#!/usr/bin/env pwsh <# .SYNOPSIS Verifies the Module 01 challenge solution. .DESCRIPTION Checks if the student has correctly: - Initialized a git repository - Created two commits with the correct messages - Committed the correct files #> Write-Host "Verifying Module 01: Git Basics Challenge..." -ForegroundColor Cyan Write-Host "" $allChecksPassed = $true # Check if challenge directory exists if (-not (Test-Path "challenge")) { Write-Host "[FAIL] Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red exit 1 } Set-Location "challenge" # Check if git repository exists if (-not (Test-Path ".git")) { Write-Host "[FAIL] No git repository found. Did you run 'git init'?" -ForegroundColor Red Set-Location ".." exit 1 } Write-Host "[PASS] Git repository initialized" -ForegroundColor Green # Check number of commits $commitCount = (git rev-list --all --count 2>$null) if ($commitCount -ne 2) { Write-Host "[FAIL] Expected 2 commits, found $commitCount" -ForegroundColor Red $allChecksPassed = $false } else { Write-Host "[PASS] Correct number of commits (2)" -ForegroundColor Green } # Get commit messages (newest first) $commits = git log --pretty=format:"%s" --reverse 2>$null if ($commits) { $commitArray = $commits -split "`n" # Check first commit if ($commitArray.Count -ge 1) { if ($commitArray[0] -eq "Add welcome file") { Write-Host "[PASS] First commit message correct" -ForegroundColor Green } else { Write-Host "[FAIL] First commit message incorrect. Expected 'Add welcome file', got '$($commitArray[0])'" -ForegroundColor Red $allChecksPassed = $false } # Check files in first commit $filesInFirstCommit = git diff-tree --no-commit-id --name-only -r HEAD~1 2>$null if ($filesInFirstCommit -match "welcome.txt") { Write-Host "[PASS] First commit contains welcome.txt" -ForegroundColor Green } else { Write-Host "[FAIL] First commit should contain welcome.txt" -ForegroundColor Red $allChecksPassed = $false } } # Check second commit if ($commitArray.Count -ge 2) { if ($commitArray[1] -eq "Add instructions") { Write-Host "[PASS] Second commit message correct" -ForegroundColor Green } else { Write-Host "[FAIL] Second commit message incorrect. Expected 'Add instructions', got '$($commitArray[1])'" -ForegroundColor Red $allChecksPassed = $false } # Check files in second commit $filesInSecondCommit = git diff-tree --no-commit-id --name-only -r HEAD 2>$null if ($filesInSecondCommit -match "instructions.txt") { Write-Host "[PASS] Second commit contains instructions.txt" -ForegroundColor Green } else { Write-Host "[FAIL] Second commit should contain instructions.txt" -ForegroundColor Red $allChecksPassed = $false } } } Set-Location ".." Write-Host "" if ($allChecksPassed) { Write-Host "========================================" -ForegroundColor Green Write-Host " CONGRATULATIONS! Challenge Complete! " -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "" Write-Host "You've mastered the basics of git!" -ForegroundColor Cyan Write-Host "You can now move on to Module 02." -ForegroundColor Cyan Write-Host "" } else { Write-Host "========================================" -ForegroundColor Red Write-Host " Challenge Not Complete - Try Again! " -ForegroundColor Red Write-Host "========================================" -ForegroundColor Red Write-Host "" Write-Host "Review the errors above and try again." -ForegroundColor Yellow Write-Host "Hint: Check 'git log' and 'git status' to see what you've done." -ForegroundColor Yellow Write-Host "" exit 1 }