124 lines
3.2 KiB
PowerShell
124 lines
3.2 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Sets up the rebasing challenge environment.
|
|
|
|
.DESCRIPTION
|
|
Creates a Git repository with diverged branches to practice rebasing.
|
|
The feature branch needs to be rebased onto main.
|
|
#>
|
|
|
|
# Remove existing challenge directory if present
|
|
if (Test-Path "challenge") {
|
|
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
|
Remove-Item -Path "challenge" -Recurse -Force
|
|
}
|
|
|
|
# Create challenge directory
|
|
Write-Host "Creating challenge environment..." -ForegroundColor Cyan
|
|
New-Item -ItemType Directory -Path "challenge" | Out-Null
|
|
Set-Location "challenge"
|
|
|
|
# Initialize git repository
|
|
git init | Out-Null
|
|
git config user.name "Workshop User" | Out-Null
|
|
git config user.email "user@workshop.local" | Out-Null
|
|
|
|
# Create initial file and commit
|
|
$readme = @"
|
|
# My Project
|
|
|
|
A sample project for learning Git rebasing.
|
|
"@
|
|
|
|
Set-Content -Path "README.md" -Value $readme
|
|
git add README.md
|
|
git commit -m "Initial commit" | Out-Null
|
|
|
|
# Create and switch to feature branch
|
|
git checkout -b feature | Out-Null
|
|
|
|
# Add commits on feature branch
|
|
$feature1 = @"
|
|
# My Project
|
|
|
|
A sample project for learning Git rebasing.
|
|
|
|
## Features
|
|
|
|
- Feature A: User authentication
|
|
"@
|
|
|
|
Set-Content -Path "README.md" -Value $feature1
|
|
git add README.md
|
|
git commit -m "Add feature A" | Out-Null
|
|
|
|
$feature2 = @"
|
|
# My Project
|
|
|
|
A sample project for learning Git rebasing.
|
|
|
|
## Features
|
|
|
|
- Feature A: User authentication
|
|
- Feature B: Data validation
|
|
"@
|
|
|
|
Set-Content -Path "README.md" -Value $feature2
|
|
git add README.md
|
|
git commit -m "Add feature B" | Out-Null
|
|
|
|
# Switch back to main and add commits (simulating other work happening on main)
|
|
git checkout main | Out-Null
|
|
|
|
$main1 = @"
|
|
# My Project
|
|
|
|
A sample project for learning Git rebasing.
|
|
|
|
## Installation
|
|
|
|
Run \`npm install\` to install dependencies.
|
|
"@
|
|
|
|
Set-Content -Path "README.md" -Value $main1
|
|
git add README.md
|
|
git commit -m "Add installation instructions" | Out-Null
|
|
|
|
$main2 = @"
|
|
# My Project
|
|
|
|
A sample project for learning Git rebasing.
|
|
|
|
## Installation
|
|
|
|
Run \`npm install\` to install dependencies.
|
|
|
|
## Configuration
|
|
|
|
Copy \`config.example.json\` to \`config.json\` and update settings.
|
|
"@
|
|
|
|
Set-Content -Path "README.md" -Value $main2
|
|
git add README.md
|
|
git commit -m "Add configuration instructions" | Out-Null
|
|
|
|
# Switch back to feature branch
|
|
git checkout feature | Out-Null
|
|
|
|
# Return to module directory
|
|
Set-Location ..
|
|
|
|
Write-Host "`n========================================" -ForegroundColor Green
|
|
Write-Host "Challenge environment created!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "`nYou are now on the 'feature' branch." -ForegroundColor Cyan
|
|
Write-Host "The 'main' branch has new commits that aren't in your feature branch." -ForegroundColor Cyan
|
|
Write-Host "`nYour task:" -ForegroundColor Yellow
|
|
Write-Host "1. Navigate to the challenge directory: cd challenge" -ForegroundColor White
|
|
Write-Host "2. View the commit history: git log --oneline --graph --all" -ForegroundColor White
|
|
Write-Host "3. Rebase the 'feature' branch onto 'main'" -ForegroundColor White
|
|
Write-Host "4. View the history again to see the linear result" -ForegroundColor White
|
|
Write-Host "`nRun '../verify.ps1' from the challenge directory to check your solution.`n" -ForegroundColor Cyan
|