#!/usr/bin/env pwsh <# .SYNOPSIS Verifies the Module 02 challenge solution. .DESCRIPTION This script checks that: - The challenge directory exists - A Git repository exists - answers.txt exists with correct information about commit history #> Write-Host "`n=== Verifying Module 02 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 if answers.md exists if (-not (Test-Path "answers.md")) { Write-Host "[FAIL] answers.md not found. Did you run setup.ps1?" -ForegroundColor Red Write-Host "[HINT] The setup script should have created answers.md for you" -ForegroundColor Yellow $allChecksPassed = $false } else { Write-Host "[PASS] answers.md exists" -ForegroundColor Green # Read the answers file $answers = Get-Content "answers.md" -Raw $answersLower = $answers.ToLower() # Check 1: Contains "5" or "five" for commit count if ($answersLower -match "5|five") { Write-Host "[PASS] Correct commit count found" -ForegroundColor Green } else { Write-Host "[FAIL] Commit count not found or incorrect" -ForegroundColor Red Write-Host "[HINT] Use 'git log --oneline' to count commits easily" -ForegroundColor Yellow $allChecksPassed = $false } # Check 2: Contains "database" keyword for third commit if ($answersLower -match "database") { Write-Host "[PASS] Third commit message identified" -ForegroundColor Green } else { Write-Host "[FAIL] Third commit message not found" -ForegroundColor Red Write-Host "[HINT] Use 'git log' to see commit messages in order" -ForegroundColor Yellow $allChecksPassed = $false } # Check 3: Contains both "auth" and "database" keywords for files modified in bug fix $hasAuth = $answersLower -match "auth" $hasDatabase = $answersLower -match "database" if ($hasAuth -and $hasDatabase) { Write-Host "[PASS] Both files identified for bug fix commit" -ForegroundColor Green } elseif ($hasAuth -or $hasDatabase) { Write-Host "[PARTIAL] Only one file found - there are TWO files modified in this commit" -ForegroundColor Yellow Write-Host "[HINT] Use 'git log --stat' or 'git show --name-only' to see ALL files changed" -ForegroundColor Yellow $allChecksPassed = $false } else { Write-Host "[FAIL] Files modified in bug fix commit not found" -ForegroundColor Red Write-Host "[HINT] Use 'git log --stat' to see which files were changed in each commit" -ForegroundColor Yellow $allChecksPassed = $false } # Check 4: Contains "config" keyword for staged file if ($answersLower -match "config") { Write-Host "[PASS] Staged file identified" -ForegroundColor Green } else { Write-Host "[FAIL] Staged file not identified" -ForegroundColor Red Write-Host "[HINT] Use 'git status' or 'git diff --staged' to see staged changes" -ForegroundColor Yellow $allChecksPassed = $false } # Check 5: Contains "unicorn" for the secret code if ($answersLower -match "unicorn") { Write-Host "[PASS] Secret code found!" -ForegroundColor Green } else { Write-Host "[FAIL] Secret code not found" -ForegroundColor Red Write-Host "[HINT] Use 'git diff database.py' to find the secret code" -ForegroundColor Yellow $allChecksPassed = $false } } 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 explored Git commit history!" -ForegroundColor Cyan Write-Host "You now know how to:" -ForegroundColor Cyan Write-Host " - View commit history with git log" -ForegroundColor White Write-Host " - Find specific commits and their messages" -ForegroundColor White Write-Host " - See which files changed in commits" -ForegroundColor White Write-Host " - Check staged changes with git diff --staged" -ForegroundColor White Write-Host " - Compare changes between specific commits with git diff" -ForegroundColor White Write-Host "`nReady for the next module!" -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 "" exit 1 }