125 lines
4.2 KiB
PowerShell
125 lines
4.2 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
<#
|
|
.SYNOPSIS
|
|
Sets up the Module 05 challenge environment for learning about merge conflicts.
|
|
|
|
.DESCRIPTION
|
|
This script creates a challenge directory with a Git repository that
|
|
contains conflicting changes on two branches. Students will practice
|
|
resolving merge conflicts.
|
|
#>
|
|
|
|
Write-Host "`n=== Setting up Module 05 Challenge ===" -ForegroundColor Cyan
|
|
|
|
# Remove existing challenge directory if it exists
|
|
if (Test-Path "challenge") {
|
|
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
|
Remove-Item -Recurse -Force "challenge"
|
|
}
|
|
|
|
# Create fresh challenge directory
|
|
Write-Host "Creating challenge directory..." -ForegroundColor Green
|
|
New-Item -ItemType Directory -Path "challenge" | Out-Null
|
|
Set-Location "challenge"
|
|
|
|
# Initialize Git repository
|
|
Write-Host "Initializing Git repository..." -ForegroundColor Green
|
|
git init | Out-Null
|
|
|
|
# Configure git for this repository
|
|
git config user.name "Workshop Student"
|
|
git config user.email "student@example.com"
|
|
|
|
# Create initial app.py with clear line numbers
|
|
Write-Host "Creating initial application..." -ForegroundColor Green
|
|
$initialContent = @"
|
|
# app.py - Main application
|
|
|
|
def main():
|
|
print("Application starting...")
|
|
# Lines 5-7 will be modified differently on each branch
|
|
print("Version: 1.0")
|
|
print("Status: Development")
|
|
print("Mode: Standard")
|
|
# End of conflicting section
|
|
print("Application ready!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
"@
|
|
Set-Content -Path "app.py" -Value $initialContent
|
|
|
|
git add .
|
|
git commit -m "Initial application setup" | Out-Null
|
|
|
|
# Create feature-updates branch
|
|
Write-Host "Creating feature-updates branch..." -ForegroundColor Green
|
|
git checkout -b feature-updates 2>$null | Out-Null
|
|
|
|
# On feature branch: Modify lines 5-7 (Version 2.0, Beta, Advanced)
|
|
$featureContent = @"
|
|
# app.py - Main application
|
|
|
|
def main():
|
|
print("Application starting...")
|
|
# Lines 5-7 will be modified differently on each branch
|
|
print("Version: 2.0")
|
|
print("Status: Beta")
|
|
print("Mode: Advanced")
|
|
# End of conflicting section
|
|
print("Application ready!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
"@
|
|
Set-Content -Path "app.py" -Value $featureContent
|
|
|
|
git add .
|
|
git commit -m "Update to version 2.0 with advanced features" | Out-Null
|
|
|
|
# Switch back to main
|
|
Write-Host "Switching back to main branch..." -ForegroundColor Green
|
|
git checkout main 2>$null | Out-Null
|
|
|
|
# On main: Modify THE SAME lines 5-7 differently (Version 1.5, Production, Basic)
|
|
$mainContent = @"
|
|
# app.py - Main application
|
|
|
|
def main():
|
|
print("Application starting...")
|
|
# Lines 5-7 will be modified differently on each branch
|
|
print("Version: 1.5")
|
|
print("Status: Production")
|
|
print("Mode: Basic")
|
|
# End of conflicting section
|
|
print("Application ready!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
"@
|
|
Set-Content -Path "app.py" -Value $mainContent
|
|
|
|
git add .
|
|
git commit -m "Update to version 1.5 for production" | Out-Null
|
|
|
|
# Return to module directory
|
|
Set-Location ..
|
|
|
|
Write-Host "`n=== Setup Complete! ===" -ForegroundColor Green
|
|
Write-Host "`nYour challenge environment is ready in the 'challenge/' directory." -ForegroundColor Cyan
|
|
Write-Host "`nThe conflict scenario:" -ForegroundColor Cyan
|
|
Write-Host " - Main branch: Version 1.5, Production, Basic mode" -ForegroundColor White
|
|
Write-Host " - Feature branch: Version 2.0, Beta, Advanced mode" -ForegroundColor White
|
|
Write-Host " - SAME LINES modified differently = CONFLICT!" -ForegroundColor Yellow
|
|
Write-Host "`nNext steps:" -ForegroundColor Cyan
|
|
Write-Host " 1. cd challenge" -ForegroundColor White
|
|
Write-Host " 2. Try to merge: git merge feature-updates" -ForegroundColor White
|
|
Write-Host " 3. See the conflict! git status will show 'both modified: app.py'" -ForegroundColor White
|
|
Write-Host " 4. Open app.py and look for conflict markers (<<<<<<< ======= >>>>>>>)" -ForegroundColor White
|
|
Write-Host " 5. Manually resolve by editing app.py" -ForegroundColor White
|
|
Write-Host " 6. Remove conflict markers and keep desired version" -ForegroundColor White
|
|
Write-Host " 7. Stage: git add app.py" -ForegroundColor White
|
|
Write-Host " 8. Complete: git commit" -ForegroundColor White
|
|
Write-Host " 9. Run '..\verify.ps1' to check your solution" -ForegroundColor White
|
|
Write-Host ""
|