91 lines
3.1 KiB
PowerShell
91 lines
3.1 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Verifies the Module 01 challenge solution.
|
|
|
|
.DESCRIPTION
|
|
Checks if the student has correctly:
|
|
- Initialized a git repository
|
|
- Created at least one commit
|
|
- Committed both required files (welcome.txt and instructions.txt)
|
|
#>
|
|
|
|
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 if there are any commits
|
|
$commitCount = (git rev-list --all --count 2>$null)
|
|
if ($null -eq $commitCount -or $commitCount -eq 0) {
|
|
Write-Host "[FAIL] No commits found. Have you committed your changes?" -ForegroundColor Red
|
|
$allChecksPassed = $false
|
|
} else {
|
|
Write-Host "[PASS] Found $commitCount commit(s)" -ForegroundColor Green
|
|
}
|
|
|
|
# Check if both files are in the git history using git ls-tree
|
|
if ($commitCount -gt 0) {
|
|
$trackedFiles = git ls-tree -r HEAD --name-only 2>$null
|
|
|
|
if ($trackedFiles -match "welcome.txt") {
|
|
Write-Host "[PASS] welcome.txt is committed" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[FAIL] welcome.txt is not in the commit history" -ForegroundColor Red
|
|
$allChecksPassed = $false
|
|
}
|
|
|
|
if ($trackedFiles -match "instructions.txt") {
|
|
Write-Host "[PASS] instructions.txt is committed" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[FAIL] instructions.txt is not in the commit history" -ForegroundColor Red
|
|
$allChecksPassed = $false
|
|
}
|
|
}
|
|
|
|
# Check for uncommitted changes
|
|
$statusOutput = git status --porcelain 2>$null
|
|
if ($statusOutput) {
|
|
Write-Host "[INFO] You have uncommitted changes. This is OK, but make sure all required files are committed." -ForegroundColor Yellow
|
|
}
|
|
|
|
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
|
|
}
|