280 lines
8.7 KiB
PowerShell
Executable File
280 lines
8.7 KiB
PowerShell
Executable File
#!/usr/bin/env pwsh
|
|
<#
|
|
.SYNOPSIS
|
|
Sets up the Module 03 checkpoint-based challenge environment.
|
|
|
|
.DESCRIPTION
|
|
This script creates a challenge directory with a complete Git repository
|
|
containing all commits and checkpoints for learning branching, merging,
|
|
and merge conflict resolution in one continuous workflow.
|
|
|
|
The script creates three checkpoints:
|
|
- checkpoint-start: Beginning of branching basics
|
|
- checkpoint-merge: Beginning of merging section
|
|
- checkpoint-merge-conflict: Beginning of conflict resolution
|
|
#>
|
|
|
|
Write-Host "`n=== Setting up Module 03: Branching and Merging ===" -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"
|
|
|
|
# ============================================================================
|
|
# PHASE 1: Branching Basics - Initial commits on main
|
|
# ============================================================================
|
|
Write-Host "`nPhase 1: Creating initial project structure..." -ForegroundColor Cyan
|
|
|
|
# Commit 1: Initial commit
|
|
$mainContent = @"
|
|
# main.py - Main application file
|
|
|
|
def main():
|
|
print("Welcome to the Application!")
|
|
print("This is the main branch")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
"@
|
|
Set-Content -Path "main.py" -Value $mainContent
|
|
git add .
|
|
git commit -m "Initial commit" | Out-Null
|
|
|
|
# Commit 2: Add main functionality
|
|
$mainContent = @"
|
|
# main.py - Main application file
|
|
|
|
def main():
|
|
print("Welcome to the Application!")
|
|
print("This is the main branch")
|
|
run_application()
|
|
|
|
def run_application():
|
|
print("Application is running...")
|
|
print("Ready for new features!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
"@
|
|
Set-Content -Path "main.py" -Value $mainContent
|
|
git add .
|
|
git commit -m "Add main functionality" | Out-Null
|
|
|
|
# Tag checkpoint-start (students begin here - will create feature-login)
|
|
Write-Host "Creating checkpoint: start" -ForegroundColor Green
|
|
git tag checkpoint-start
|
|
|
|
# ============================================================================
|
|
# PHASE 2: Create feature-login branch (what students will do in checkpoint 1)
|
|
# ============================================================================
|
|
Write-Host "Phase 2: Creating feature-login branch..." -ForegroundColor Cyan
|
|
|
|
# Create and switch to feature-login branch
|
|
git switch -c feature-login | Out-Null
|
|
|
|
# Commit 3: Add login module
|
|
$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 logout(username):
|
|
"""Log out a user."""
|
|
print(f"Logging out user: {username}")
|
|
return True
|
|
"@
|
|
Set-Content -Path "login.py" -Value $loginContent
|
|
git add .
|
|
git commit -m "Add login module" | Out-Null
|
|
|
|
# Commit 4: Add password validation
|
|
$loginContent = @"
|
|
# login.py - User login module
|
|
|
|
def validate_password(password):
|
|
"""Validate password strength."""
|
|
if len(password) < 8:
|
|
return False
|
|
return True
|
|
|
|
def login(username, password):
|
|
"""Authenticate a user."""
|
|
if not validate_password(password):
|
|
print("Password too weak!")
|
|
return False
|
|
print(f"Authenticating user: {username}")
|
|
# TODO: Add actual authentication logic
|
|
return True
|
|
|
|
def logout(username):
|
|
"""Log out a user."""
|
|
print(f"Logging out user: {username}")
|
|
return True
|
|
"@
|
|
Set-Content -Path "login.py" -Value $loginContent
|
|
git add .
|
|
git commit -m "Add password validation" | Out-Null
|
|
|
|
# Switch back to main
|
|
git switch main | Out-Null
|
|
|
|
# Now create divergence - add commits to main while feature-login exists
|
|
Write-Host "Creating divergent history on main..." -ForegroundColor Cyan
|
|
|
|
# Commit 5: Add app.py with basic functionality
|
|
$appContent = @"
|
|
# app.py - Main application entry point
|
|
|
|
from main import main
|
|
|
|
def run():
|
|
"""Run the application."""
|
|
print("Starting application...")
|
|
main()
|
|
print("Application finished.")
|
|
|
|
if __name__ == "__main__":
|
|
run()
|
|
"@
|
|
Set-Content -Path "app.py" -Value $appContent
|
|
git add .
|
|
git commit -m "Add app.py entry point" | Out-Null
|
|
|
|
# Commit 6: Add README
|
|
$readmeContent = @"
|
|
# My Application
|
|
|
|
Welcome to my application!
|
|
|
|
## Features
|
|
|
|
- Main functionality
|
|
- More features coming soon
|
|
|
|
## Setup
|
|
|
|
Run: python app.py
|
|
"@
|
|
Set-Content -Path "README.md" -Value $readmeContent
|
|
git add .
|
|
git commit -m "Add README documentation" | Out-Null
|
|
|
|
# Tag checkpoint-merge (students begin merging here - divergent branches ready)
|
|
Write-Host "Creating checkpoint: merge" -ForegroundColor Green
|
|
git tag checkpoint-merge
|
|
|
|
# ============================================================================
|
|
# PHASE 3: Merge feature-login into main (what students will do in checkpoint 2)
|
|
# ============================================================================
|
|
Write-Host "Phase 3: Merging feature-login into main..." -ForegroundColor Cyan
|
|
|
|
# Merge feature-login into main (will create three-way merge commit)
|
|
git merge feature-login --no-edit | Out-Null
|
|
|
|
# ============================================================================
|
|
# PHASE 4: Create conflict scenario (what students will do in checkpoint 3)
|
|
# ============================================================================
|
|
Write-Host "Phase 4: Creating merge conflict scenario..." -ForegroundColor Cyan
|
|
|
|
# Create config.json file on main
|
|
$initialConfig = @"
|
|
{
|
|
"app": {
|
|
"name": "MyApp",
|
|
"version": "1.0.0",
|
|
"port": 3000
|
|
}
|
|
}
|
|
"@
|
|
Set-Content -Path "config.json" -Value $initialConfig
|
|
git add config.json
|
|
git commit -m "Add initial configuration" | Out-Null
|
|
|
|
# On main branch: Add timeout setting
|
|
$mainConfig = @"
|
|
{
|
|
"app": {
|
|
"name": "MyApp",
|
|
"version": "1.0.0",
|
|
"port": 3000,
|
|
"timeout": 5000
|
|
}
|
|
}
|
|
"@
|
|
Set-Content -Path "config.json" -Value $mainConfig
|
|
git add config.json
|
|
git commit -m "Add timeout configuration" | Out-Null
|
|
|
|
# Create update-config branch from the commit before timeout was added
|
|
git switch -c update-config HEAD~1 | Out-Null
|
|
|
|
# On update-config branch: Add debug setting (conflicting change)
|
|
$featureConfig = @"
|
|
{
|
|
"app": {
|
|
"name": "MyApp",
|
|
"version": "1.0.0",
|
|
"port": 3000,
|
|
"debug": true
|
|
}
|
|
}
|
|
"@
|
|
Set-Content -Path "config.json" -Value $featureConfig
|
|
git add config.json
|
|
git commit -m "Add debug mode configuration" | Out-Null
|
|
|
|
# Switch back to main
|
|
git switch main | Out-Null
|
|
|
|
# Tag checkpoint-merge-conflict (students begin conflict resolution here - on main with timeout, update-config has debug)
|
|
Write-Host "Creating checkpoint: merge-conflict" -ForegroundColor Green
|
|
git tag checkpoint-merge-conflict
|
|
|
|
# ============================================================================
|
|
# Reset to checkpoint-start so students begin at the beginning
|
|
# ============================================================================
|
|
Write-Host "`nResetting to checkpoint-start..." -ForegroundColor Yellow
|
|
git reset --hard checkpoint-start | Out-Null
|
|
git clean -fd | 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 "`nThis module uses a CHECKPOINT SYSTEM:" -ForegroundColor Yellow
|
|
Write-Host " You'll work through 3 sections in one continuous repository:" -ForegroundColor White
|
|
Write-Host " 1. Branching Basics (checkpoint: start)" -ForegroundColor White
|
|
Write-Host " 2. Merging Branches (checkpoint: merge)" -ForegroundColor White
|
|
Write-Host " 3. Resolving Merge Conflicts (checkpoint: merge-conflict)" -ForegroundColor White
|
|
Write-Host "`nCommands:" -ForegroundColor Cyan
|
|
Write-Host " .\reset.ps1 - Show available checkpoints" -ForegroundColor White
|
|
Write-Host " .\reset.ps1 start - Jump to branching section" -ForegroundColor White
|
|
Write-Host " .\reset.ps1 merge - Jump to merging section" -ForegroundColor White
|
|
Write-Host " .\verify.ps1 - Verify all sections complete" -ForegroundColor White
|
|
Write-Host " .\verify.ps1 start - Verify only branching section" -ForegroundColor White
|
|
Write-Host "`nNext steps:" -ForegroundColor Cyan
|
|
Write-Host " 1. Read the README.md for detailed instructions" -ForegroundColor White
|
|
Write-Host " 2. cd challenge" -ForegroundColor White
|
|
Write-Host " 3. Start with Checkpoint 1: Branching Basics" -ForegroundColor White
|
|
Write-Host ""
|