#!/usr/bin/env pwsh <# .SYNOPSIS Verifies the Module 04 challenge solution. .DESCRIPTION This script checks that: - The challenge directory exists - A Git repository exists - Currently on main branch - feature-login has been merged into main - A merge commit exists (three-way merge) - Login functionality is present on main #> Write-Host "`n=== Verifying Module 04 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 if feature-login branch exists $featureLoginBranch = git branch --list "feature-login" 2>$null if ($featureLoginBranch) { Write-Host "[PASS] Branch 'feature-login' exists" -ForegroundColor Green } else { Write-Host "[INFO] Branch 'feature-login' not found (may have been deleted after merge)" -ForegroundColor Cyan } # Check if login.py exists (should be on main after merge) if (Test-Path "login.py") { Write-Host "[PASS] File 'login.py' exists on main (from feature-login merge)" -ForegroundColor Green } else { Write-Host "[FAIL] File 'login.py' not found on main" -ForegroundColor Red Write-Host "[HINT] This file should appear after merging feature-login into main" -ForegroundColor Yellow $allChecksPassed = $false } # Check if app.py contains login integration if (Test-Path "app.py") { $appContent = Get-Content "app.py" -Raw if ($appContent -match "login") { Write-Host "[PASS] app.py contains login integration" -ForegroundColor Green } else { Write-Host "[FAIL] app.py doesn't contain login integration" -ForegroundColor Red Write-Host "[HINT] After merging, app.py should import and use the login module" -ForegroundColor Yellow $allChecksPassed = $false } } else { Write-Host "[FAIL] app.py not found" -ForegroundColor Red $allChecksPassed = $false } # Check for merge commit (indicates three-way merge happened) $mergeCommits = git log --merges --oneline 2>$null if ($mergeCommits) { Write-Host "[PASS] Merge commit found (three-way merge completed)" -ForegroundColor Green # Get the merge commit message $mergeMessage = git log --merges --format=%s -1 2>$null Write-Host "[INFO] Merge commit message: '$mergeMessage'" -ForegroundColor Cyan } else { Write-Host "[FAIL] No merge commit found" -ForegroundColor Red Write-Host "[HINT] Merge feature-login into main with: git merge feature-login" -ForegroundColor Yellow $allChecksPassed = $false } # Check if both branches contributed commits (true three-way merge) $totalCommits = git rev-list --count HEAD 2>$null if ($totalCommits -ge 4) { Write-Host "[PASS] Repository has $totalCommits commits (branches diverged properly)" -ForegroundColor Green } else { Write-Host "[WARN] Repository has only $totalCommits commits (expected at least 4)" -ForegroundColor Yellow Write-Host "[INFO] This might still be correct if you deleted commits" -ForegroundColor Cyan } 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 successfully completed your first branch merge!" -ForegroundColor Cyan Write-Host "You now understand:" -ForegroundColor Cyan Write-Host " - How to merge branches with git merge" -ForegroundColor White Write-Host " - What a merge commit is and why it's created" -ForegroundColor White Write-Host " - How divergent branches are combined" -ForegroundColor White Write-Host " - How to visualize merges with git log --graph" -ForegroundColor White Write-Host "`nNext up: Module 05 - Merge Conflicts!" -ForegroundColor Yellow Write-Host "You'll learn what happens when Git can't automatically merge." -ForegroundColor Cyan 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 "" exit 1 }