222 lines
6.8 KiB
PowerShell
222 lines
6.8 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
<#
|
|
.SYNOPSIS
|
|
Sets up the Module 06 challenge environment for learning merge strategies.
|
|
|
|
.DESCRIPTION
|
|
This script creates a challenge directory with a Git repository that
|
|
contains scenarios for both fast-forward and three-way merges, allowing
|
|
students to compare different merge strategies.
|
|
#>
|
|
|
|
Write-Host "`n=== Setting up Module 06 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"
|
|
|
|
# ========================================
|
|
# Scenario 1: Fast-Forward Merge Setup
|
|
# ========================================
|
|
|
|
Write-Host "Setting up fast-forward merge scenario..." -ForegroundColor Green
|
|
|
|
# Commit 1: Initial structure on main
|
|
$appContent = @"
|
|
# app.py - Main application
|
|
|
|
def main():
|
|
print("Application started")
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
"@
|
|
Set-Content -Path "app.py" -Value $appContent
|
|
|
|
git add .
|
|
git commit -m "Initial application structure" | Out-Null
|
|
|
|
# Create feature-fast-forward branch (main won't change after this)
|
|
git switch -c feature-fast-forward | Out-Null
|
|
|
|
# Commit on feature-fast-forward
|
|
$utilsContent = @"
|
|
# utils.py - Utility functions
|
|
|
|
def format_string(text):
|
|
"""Format a string to title case."""
|
|
return text.title()
|
|
|
|
def validate_input(text):
|
|
"""Validate user input."""
|
|
return text and len(text) > 0
|
|
"@
|
|
Set-Content -Path "utils.py" -Value $utilsContent
|
|
|
|
git add .
|
|
git commit -m "Add utility functions" | Out-Null
|
|
|
|
# Second commit on feature-fast-forward
|
|
$utilsContent = @"
|
|
# utils.py - Utility functions
|
|
|
|
def format_string(text):
|
|
"""Format a string to title case."""
|
|
return text.title()
|
|
|
|
def validate_input(text):
|
|
"""Validate user input."""
|
|
return text and len(text) > 0
|
|
|
|
def sanitize_input(text):
|
|
"""Remove dangerous characters from input."""
|
|
return text.replace("<", "").replace(">", "")
|
|
"@
|
|
Set-Content -Path "utils.py" -Value $utilsContent
|
|
|
|
git add .
|
|
git commit -m "Add input sanitization" | Out-Null
|
|
|
|
# ========================================
|
|
# Scenario 2: Three-Way Merge Setup
|
|
# ========================================
|
|
|
|
Write-Host "Setting up three-way merge scenario..." -ForegroundColor Green
|
|
|
|
# Switch back to main
|
|
git switch main | Out-Null
|
|
|
|
# Create feature-divergent branch
|
|
git switch -c feature-divergent | Out-Null
|
|
|
|
# Commit on feature-divergent
|
|
$authContent = @"
|
|
# auth.py - Authentication module
|
|
|
|
def authenticate(username, password):
|
|
"""Authenticate a user."""
|
|
print(f"Authenticating: {username}")
|
|
# TODO: Implement actual authentication
|
|
return True
|
|
"@
|
|
Set-Content -Path "auth.py" -Value $authContent
|
|
|
|
git add .
|
|
git commit -m "Add authentication module" | Out-Null
|
|
|
|
# Second commit on feature-divergent
|
|
$authContent = @"
|
|
# auth.py - Authentication module
|
|
|
|
def authenticate(username, password):
|
|
"""Authenticate a user."""
|
|
print(f"Authenticating: {username}")
|
|
# TODO: Implement actual authentication
|
|
return True
|
|
|
|
def check_permissions(user, resource):
|
|
"""Check if user has permission for resource."""
|
|
print(f"Checking permissions for {user}")
|
|
return True
|
|
"@
|
|
Set-Content -Path "auth.py" -Value $authContent
|
|
|
|
git add .
|
|
git commit -m "Add permission checking" | Out-Null
|
|
|
|
# Switch back to main and make a commit (creates divergence)
|
|
git switch main | Out-Null
|
|
|
|
$readmeContent = @"
|
|
# My Application
|
|
|
|
A Python application with utilities and authentication.
|
|
|
|
## Features
|
|
|
|
- String formatting and validation
|
|
- User authentication
|
|
- Permission management
|
|
|
|
## Setup
|
|
|
|
1. Install Python 3.8+
|
|
2. Run: python app.py
|
|
"@
|
|
Set-Content -Path "README.md" -Value $readmeContent
|
|
|
|
git add .
|
|
git commit -m "Add README documentation" | Out-Null
|
|
|
|
# ========================================
|
|
# Scenario 3: Optional Fast-Forward for --no-ff
|
|
# ========================================
|
|
|
|
Write-Host "Setting up --no-ff demonstration scenario..." -ForegroundColor Green
|
|
|
|
# Create feature-optional branch (main won't change after this)
|
|
git switch -c feature-optional | Out-Null
|
|
|
|
# Commit on feature-optional
|
|
$configContent = @"
|
|
# config.py - Configuration settings
|
|
|
|
DEBUG_MODE = False
|
|
LOG_LEVEL = "INFO"
|
|
DATABASE_URL = "sqlite:///app.db"
|
|
"@
|
|
Set-Content -Path "config.py" -Value $configContent
|
|
|
|
git add .
|
|
git commit -m "Add configuration module" | Out-Null
|
|
|
|
# Switch back to main
|
|
git switch main | 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 THREE scenarios set up:" -ForegroundColor Yellow
|
|
Write-Host "`n Scenario 1: Fast-Forward Merge" -ForegroundColor White
|
|
Write-Host " Branch: feature-fast-forward" -ForegroundColor Cyan
|
|
Write-Host " Status: main has NOT changed since branch was created" -ForegroundColor Cyan
|
|
Write-Host " Result: Will fast-forward (no merge commit)" -ForegroundColor Green
|
|
Write-Host "`n Scenario 2: Three-Way Merge" -ForegroundColor White
|
|
Write-Host " Branch: feature-divergent" -ForegroundColor Cyan
|
|
Write-Host " Status: BOTH main and branch have new commits" -ForegroundColor Cyan
|
|
Write-Host " Result: Will create merge commit" -ForegroundColor Green
|
|
Write-Host "`n Scenario 3: Force Merge Commit" -ForegroundColor White
|
|
Write-Host " Branch: feature-optional" -ForegroundColor Cyan
|
|
Write-Host " Status: Could fast-forward, but we'll use --no-ff" -ForegroundColor Cyan
|
|
Write-Host " Result: Will create merge commit even though fast-forward is possible" -ForegroundColor Green
|
|
Write-Host "`nNext steps:" -ForegroundColor Cyan
|
|
Write-Host " 1. cd challenge" -ForegroundColor White
|
|
Write-Host " 2. View initial state: git log --oneline --graph --all" -ForegroundColor White
|
|
Write-Host " 3. Merge fast-forward: git merge feature-fast-forward" -ForegroundColor White
|
|
Write-Host " 4. View result: git log --oneline --graph" -ForegroundColor White
|
|
Write-Host " 5. Merge divergent: git merge feature-divergent" -ForegroundColor White
|
|
Write-Host " 6. View result: git log --oneline --graph --all" -ForegroundColor White
|
|
Write-Host " 7. Merge with --no-ff: git merge --no-ff feature-optional" -ForegroundColor White
|
|
Write-Host " 8. View final result: git log --oneline --graph --all" -ForegroundColor White
|
|
Write-Host " 9. Compare all three merges!" -ForegroundColor White
|
|
Write-Host " 10. Run '..\verify.ps1' to check your solution" -ForegroundColor White
|
|
Write-Host ""
|