fix: simplify verification for module 1

This commit is contained in:
Bjarke Sporring
2026-01-04 15:25:52 +01:00
parent 2b3ea7ed36
commit 4a47d8b36e
2 changed files with 51 additions and 54 deletions

View File

@@ -7,8 +7,8 @@
.DESCRIPTION
Checks if the student has correctly:
- Initialized a git repository
- Created two commits with the correct messages
- Committed the correct files
- Created at least one commit
- Committed both required files (welcome.txt and instructions.txt)
#>
Write-Host "Verifying Module 01: Git Basics Challenge..." -ForegroundColor Cyan
@@ -33,60 +33,40 @@ if (-not (Test-Path ".git")) {
Write-Host "[PASS] Git repository initialized" -ForegroundColor Green
# Check number of commits
# Check if there are any commits
$commitCount = (git rev-list --all --count 2>$null)
if ($commitCount -ne 2) {
Write-Host "[FAIL] Expected 2 commits, found $commitCount" -ForegroundColor Red
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] Correct number of commits (2)" -ForegroundColor Green
Write-Host "[PASS] Found $commitCount commit(s)" -ForegroundColor Green
}
# Get commit messages (newest first)
$commits = git log --pretty=format:"%s" --reverse 2>$null
# 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 ($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
}
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
}
# 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
}
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 ""