refactor: split out merge strategies from essentials

This commit is contained in:
Bjarke Sporring
2026-01-07 21:50:59 +01:00
parent 7fb84560f5
commit df9a2bf7c1
7 changed files with 1164 additions and 177 deletions

View File

@@ -5,8 +5,7 @@
.DESCRIPTION
This script creates a challenge directory with a Git repository that
contains a main branch and a feature branch ready to merge. Students
will practice both fast-forward and three-way merges.
contains two divergent branches ready to merge (three-way merge scenario).
#>
Write-Host "`n=== Setting up Module 04 Challenge ===" -ForegroundColor Cyan
@@ -30,99 +29,121 @@ git init | Out-Null
git config user.name "Workshop Student"
git config user.email "student@example.com"
# Commit 1: Initial API file on main
Write-Host "Creating initial API structure on main..." -ForegroundColor Green
$apiContent = @"
# api.py - API module
# Commit 1: Initial project structure on main
Write-Host "Creating initial project structure..." -ForegroundColor Green
$readmeContent = @"
# My Project
def api_handler():
print("API Handler initialized")
return True
A simple web application project.
## Setup
Coming soon...
"@
Set-Content -Path "api.py" -Value $apiContent
Set-Content -Path "README.md" -Value $readmeContent
$appContent = @"
# app.py - Main application file
def main():
print("Welcome to My App!")
pass
if __name__ == "__main__":
main()
"@
Set-Content -Path "app.py" -Value $appContent
git add .
git commit -m "Initial API setup" | Out-Null
git commit -m "Initial project structure" | Out-Null
# Commit 2: Add more API functionality on main
$apiContent = @"
# api.py - API module
# Create feature-login branch
Write-Host "Creating feature-login branch..." -ForegroundColor Green
git switch -c feature-login | Out-Null
def api_handler():
print("API Handler initialized")
# Commit on feature-login: Add login module
Write-Host "Adding login functionality on feature-login..." -ForegroundColor Green
$loginContent = @"
# login.py - User login module
def login(username, password):
"""Authenticate a user."""
print(f"Authenticating user: {username}")
# TODO: Add actual authentication logic
return True
def get_data():
print("Fetching data from API...")
return {"status": "ok"}
def logout(username):
"""Log out a user."""
print(f"Logging out user: {username}")
return True
"@
Set-Content -Path "api.py" -Value $apiContent
Set-Content -Path "login.py" -Value $loginContent
git add .
git commit -m "Add get_data function" | Out-Null
git commit -m "Add login module" | Out-Null
# Create feature-api branch and add commits
Write-Host "Creating feature-api branch..." -ForegroundColor Green
git checkout -b feature-api 2>$null | Out-Null
# Second commit on feature-login: Integrate login with app
$appContent = @"
# app.py - Main application file
from login import login, logout
# Commit on feature-api: Add API routes
$routesContent = @"
# api-routes.py - API Routes module
def main():
print("Welcome to My App!")
# Add login integration
if login("testuser", "password"):
print("Login successful!")
pass
def setup_routes():
print("Setting up API routes...")
routes = {
"/api/data": "get_data",
"/api/status": "get_status"
}
return routes
if __name__ == "__main__":
main()
"@
Set-Content -Path "api-routes.py" -Value $routesContent
Set-Content -Path "app.py" -Value $appContent
git add .
git commit -m "Add API routes" | Out-Null
# Second commit on feature-api: Enhance routes
$routesContent = @"
# api-routes.py - API Routes module
def setup_routes():
print("Setting up API routes...")
routes = {
"/api/data": "get_data",
"/api/status": "get_status",
"/api/health": "health_check"
}
return routes
def health_check():
return {"healthy": True}
"@
Set-Content -Path "api-routes.py" -Value $routesContent
git add .
git commit -m "Add health check route" | Out-Null
git commit -m "Integrate login with main app" | Out-Null
# Switch back to main branch
Write-Host "Switching back to main branch..." -ForegroundColor Green
git checkout main 2>$null | Out-Null
git switch main | Out-Null
# Make a commit on main (creates divergence)
Write-Host "Adding documentation on main (creates divergence)..." -ForegroundColor Green
$readmeContent = @"
# My Project
A simple web application project.
## Setup
1. Install Python 3.8 or higher
2. Run: python app.py
## Features
- User authentication (coming soon)
- Data management (coming soon)
## Contributing
Please follow our coding standards when contributing.
"@
Set-Content -Path "README.md" -Value $readmeContent
git add .
git commit -m "Update README with setup instructions" | 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 "`nYou have:" -ForegroundColor Cyan
Write-Host " - A main branch with API code" -ForegroundColor White
Write-Host " - A feature-api branch with API routes ready to merge" -ForegroundColor White
Write-Host "`nScenario: You have two divergent branches!" -ForegroundColor Yellow
Write-Host " - main: Has updated documentation" -ForegroundColor White
Write-Host " - feature-login: Has new login functionality" -ForegroundColor White
Write-Host "`nNext steps:" -ForegroundColor Cyan
Write-Host " 1. cd challenge" -ForegroundColor White
Write-Host " 2. View branches: git branch -a" -ForegroundColor White
Write-Host " 3. Merge feature-api: git merge feature-api (fast-forward merge)" -ForegroundColor White
Write-Host " 4. Create feature-ui branch: git checkout -b feature-ui" -ForegroundColor White
Write-Host " 5. Make commits on feature-ui" -ForegroundColor White
Write-Host " 6. Switch back to main and make a commit there" -ForegroundColor White
Write-Host " 7. Merge feature-ui: git merge feature-ui (three-way merge)" -ForegroundColor White
Write-Host " 8. View merge history: git log --oneline --graph --all" -ForegroundColor White
Write-Host " 9. Run '..\verify.ps1' to check your solution" -ForegroundColor White
Write-Host " 2. View the branch structure: git log --oneline --graph --all" -ForegroundColor White
Write-Host " 3. Merge feature-login into main: git merge feature-login" -ForegroundColor White
Write-Host " 4. View the merge result: git log --oneline --graph --all" -ForegroundColor White
Write-Host " 5. Run '..\verify.ps1' to check your solution" -ForegroundColor White
Write-Host ""