feat: add initial module 04
This commit is contained in:
128
module-04-merging/setup.ps1
Normal file
128
module-04-merging/setup.ps1
Normal file
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env pwsh
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets up the Module 04 challenge environment for learning about merging.
|
||||
|
||||
.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.
|
||||
#>
|
||||
|
||||
Write-Host "`n=== Setting up Module 04 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"
|
||||
|
||||
# Commit 1: Initial API file on main
|
||||
Write-Host "Creating initial API structure on main..." -ForegroundColor Green
|
||||
$apiContent = @"
|
||||
# api.py - API module
|
||||
|
||||
def api_handler():
|
||||
print("API Handler initialized")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "api.py" -Value $apiContent
|
||||
|
||||
git add .
|
||||
git commit -m "Initial API setup" | Out-Null
|
||||
|
||||
# Commit 2: Add more API functionality on main
|
||||
$apiContent = @"
|
||||
# api.py - API module
|
||||
|
||||
def api_handler():
|
||||
print("API Handler initialized")
|
||||
return True
|
||||
|
||||
def get_data():
|
||||
print("Fetching data from API...")
|
||||
return {"status": "ok"}
|
||||
"@
|
||||
Set-Content -Path "api.py" -Value $apiContent
|
||||
|
||||
git add .
|
||||
git commit -m "Add get_data function" | 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
|
||||
|
||||
# Commit on feature-api: Add API 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"
|
||||
}
|
||||
return routes
|
||||
"@
|
||||
Set-Content -Path "api-routes.py" -Value $routesContent
|
||||
|
||||
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
|
||||
|
||||
# Switch back to main branch
|
||||
Write-Host "Switching back to main branch..." -ForegroundColor Green
|
||||
git checkout main 2>$null | 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 "`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 ""
|
||||
Reference in New Issue
Block a user