#!/usr/bin/env pwsh <# .SYNOPSIS Verifies the Module 06 challenge solution. .DESCRIPTION This script checks that: - The challenge directory exists - A Git repository exists - All three feature branches have been merged - Appropriate merge strategies were used - Student understands the difference between fast-forward and three-way merges #> Write-Host "`n=== Verifying Module 06 Solution ===" -ForegroundColor Cyan $allChecksPassed = $true # Check if challenge directory exists if (-not (Test-Path "challenge")) { Write-Host "[FAIL] Challenge directory not found. Did you run setup.ps1?" -ForegroundColor Red exit 1 } Set-Location "challenge" # Check if git repository exists if (-not (Test-Path ".git")) { Write-Host "[FAIL] Not a git repository. Did you run setup.ps1?" -ForegroundColor Red Set-Location .. exit 1 } # Check current branch is main $currentBranch = git branch --show-current 2>$null if ($currentBranch -eq "main") { Write-Host "[PASS] Currently on main branch" -ForegroundColor Green } else { Write-Host "[FAIL] Not on main branch (currently on: $currentBranch)" -ForegroundColor Red Write-Host "[HINT] Switch to main with: git switch main" -ForegroundColor Yellow $allChecksPassed = $false } # Check 1: Fast-Forward Merge - utils.py should exist if (Test-Path "utils.py") { Write-Host "[PASS] utils.py exists (feature-fast-forward merged)" -ForegroundColor Green } else { Write-Host "[FAIL] utils.py not found" -ForegroundColor Red Write-Host "[HINT] Merge feature-fast-forward: git merge feature-fast-forward" -ForegroundColor Yellow $allChecksPassed = $false } # Check 2: Three-Way Merge - auth.py should exist if (Test-Path "auth.py") { Write-Host "[PASS] auth.py exists (feature-divergent merged)" -ForegroundColor Green } else { Write-Host "[FAIL] auth.py not found" -ForegroundColor Red Write-Host "[HINT] Merge feature-divergent: git merge feature-divergent" -ForegroundColor Yellow $allChecksPassed = $false } # Check 3: --no-ff Merge - config.py should exist if (Test-Path "config.py") { Write-Host "[PASS] config.py exists (feature-optional merged)" -ForegroundColor Green } else { Write-Host "[FAIL] config.py not found" -ForegroundColor Red Write-Host "[HINT] Merge feature-optional: git merge --no-ff feature-optional" -ForegroundColor Yellow $allChecksPassed = $false } # Check for merge commits $mergeCommits = git log --merges --oneline 2>$null $mergeCount = ($mergeCommits | Measure-Object -Line).Lines if ($mergeCount -ge 2) { Write-Host "[PASS] Found $mergeCount merge commit(s)" -ForegroundColor Green Write-Host "[INFO] Expected: 1 from three-way merge + 1 from --no-ff = 2 total" -ForegroundColor Cyan } else { Write-Host "[FAIL] Only found $mergeCount merge commit(s), expected at least 2" -ForegroundColor Red Write-Host "[HINT] Make sure to:" -ForegroundColor Yellow Write-Host " 1. Merge feature-divergent (creates merge commit)" -ForegroundColor Yellow Write-Host " 2. Merge feature-optional with --no-ff flag (forces merge commit)" -ForegroundColor Yellow $allChecksPassed = $false } # Provide detailed merge analysis Write-Host "`n--- Merge Analysis ---" -ForegroundColor Cyan # Count total commits $totalCommits = git rev-list --count HEAD 2>$null Write-Host "[INFO] Total commits on main: $totalCommits" -ForegroundColor Cyan # List merge commits if ($mergeCommits) { Write-Host "[INFO] Merge commits found:" -ForegroundColor Cyan $mergeCommits | ForEach-Object { Write-Host " $_" -ForegroundColor White } } # Check if branches still exist $branches = git branch 2>$null Write-Host "[INFO] Existing branches:" -ForegroundColor Cyan $branches | ForEach-Object { Write-Host " $_" -ForegroundColor White } Set-Location .. # Final summary if ($allChecksPassed) { Write-Host "`n" -NoNewline Write-Host "=====================================" -ForegroundColor Green Write-Host " CONGRATULATIONS! CHALLENGE PASSED!" -ForegroundColor Green Write-Host "=====================================" -ForegroundColor Green Write-Host "`nYou've mastered Git merge strategies!" -ForegroundColor Cyan Write-Host "`nYou now understand:" -ForegroundColor Cyan Write-Host " - Fast-forward merges (linear history, no merge commit)" -ForegroundColor White Write-Host " - Three-way merges (divergent branches, creates merge commit)" -ForegroundColor White Write-Host " - How to force merge commits with --no-ff flag" -ForegroundColor White Write-Host " - When to use each merge strategy" -ForegroundColor White Write-Host " - Trade-offs between linear and branched history" -ForegroundColor White Write-Host "`nKey Takeaways:" -ForegroundColor Yellow Write-Host " - Git chooses the strategy automatically based on branch state" -ForegroundColor Cyan Write-Host " - Use --no-ff to preserve feature branch history" -ForegroundColor Cyan Write-Host " - Use --ff-only to enforce linear history" -ForegroundColor Cyan Write-Host " - Different workflows prefer different strategies" -ForegroundColor Cyan Write-Host "`nNow you can make informed decisions about merge strategies for your projects!" -ForegroundColor Green Write-Host "" } else { Write-Host "`n[SUMMARY] Some checks failed. Review the hints above and try again." -ForegroundColor Red Write-Host "[INFO] You can run this verification script as many times as needed." -ForegroundColor Yellow Write-Host "" Write-Host "Quick Reference:" -ForegroundColor Cyan Write-Host " git merge feature-fast-forward # Fast-forward merge" -ForegroundColor White Write-Host " git merge feature-divergent # Three-way merge" -ForegroundColor White Write-Host " git merge --no-ff feature-optional # Force merge commit" -ForegroundColor White Write-Host "" exit 1 }