refactor: rewrite the merge-revert section

It is an advanced and difficult revert to accomplish and should probably
be done through a reset instead, which means that we're modifying
history which is dangerous and so should be handled by someone who
understands these dangers.
This commit is contained in:
Bjarke Sporring
2026-01-15 16:11:24 +01:00
parent aa24c50b45
commit 575e083f33
4 changed files with 186 additions and 282 deletions

View File

@@ -1,16 +1,16 @@
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Verifies the Module 05 challenge solutions.
Verifies the Module 06 challenge solutions.
.DESCRIPTION
Checks that all three revert scenarios have been completed correctly:
- regular-revert: Single commit reverted
- merge-revert: Merge commit reverted with -m flag
- middle-revert: Commit in middle of history reverted
- multi-revert: Multiple commits reverted
#>
Write-Host "`n=== Verifying Module 05: Git Revert Solutions ===" -ForegroundColor Cyan
Write-Host "`n=== Verifying Module 06: Git Revert Solutions ===" -ForegroundColor Cyan
$allChecksPassed = $true
$originalDir = Get-Location
@@ -87,53 +87,50 @@ if ($LASTEXITCODE -ne 0) {
}
# ============================================================================
# SCENARIO 2: Merge Revert Verification
# SCENARIO 2: Middle Revert Verification
# ============================================================================
Write-Host "`n=== Scenario 2: Merge Revert ===" -ForegroundColor Cyan
Write-Host "`n=== Scenario 2: Middle Revert ===" -ForegroundColor Cyan
git switch merge-revert 2>&1 | Out-Null
git switch middle-revert 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "[FAIL] merge-revert branch not found" -ForegroundColor Red
Write-Host "[FAIL] middle-revert branch not found" -ForegroundColor Red
$allChecksPassed = $false
} else {
# Check that a revert commit for the merge exists
$revertMerge = git log --oneline --grep="Revert.*Merge" 2>$null
if ($revertMerge) {
Write-Host "[PASS] Merge revert commit found" -ForegroundColor Green
# Check that a revert commit exists
$revertCommit = git log --oneline --grep="Revert" 2>$null
if ($revertCommit) {
Write-Host "[PASS] Revert commit found" -ForegroundColor Green
} else {
Write-Host "[FAIL] No merge revert commit found" -ForegroundColor Red
Write-Host "[HINT] Use: git revert -m 1 <merge-commit-hash>" -ForegroundColor Yellow
Write-Host "[FAIL] No revert commit found" -ForegroundColor Red
Write-Host "[HINT] Use: git revert <commit-hash>" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check that the original merge commit still exists (revert doesn't erase it)
$mergeCommit = git log --merges --oneline --grep="Merge feature-auth" 2>$null
if ($mergeCommit) {
Write-Host "[PASS] Original merge commit still in history (not erased)" -ForegroundColor Green
# Check that formatter.py is removed (reverted)
if (-not (Test-Path "formatter.py")) {
Write-Host "[PASS] Broken formatter.py successfully reverted (file removed)" -ForegroundColor Green
} else {
Write-Host "[INFO] Original merge commit not found (this is OK if you used a different approach)" -ForegroundColor Yellow
Write-Host "[FAIL] formatter.py still exists (should be reverted)" -ForegroundColor Red
Write-Host "[HINT] The bad commit should be reverted, removing formatter.py" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check that auth.py no longer exists or its effects are reverted
if (-not (Test-Path "auth.py")) {
Write-Host "[PASS] auth.py removed (merge reverted successfully)" -ForegroundColor Green
# Check that validation.py still exists (good commit before bad one)
if (Test-Path "validation.py") {
Write-Host "[PASS] validation.py preserved (good commit before bad one)" -ForegroundColor Green
} else {
Write-Host "[INFO] auth.py still exists (check if merge was fully reverted)" -ForegroundColor Yellow
Write-Host "[FAIL] validation.py missing (should still exist)" -ForegroundColor Red
$allChecksPassed = $false
}
# Check that calculator.py exists
if (Test-Path "calculator.py") {
$calcContent = Get-Content "calculator.py" -Raw
# After reverting the merge, calculator shouldn't import auth
if ($calcContent -notmatch "from auth import") {
Write-Host "[PASS] Auth integration reverted from calculator.py" -ForegroundColor Green
} else {
Write-Host "[FAIL] calculator.py still imports auth (merge not fully reverted)" -ForegroundColor Red
Write-Host "[HINT] Reverting the merge should remove the auth integration" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check that config.py still exists (good commit after bad one)
if (Test-Path "config.py") {
Write-Host "[PASS] config.py preserved (good commit after bad one)" -ForegroundColor Green
} else {
Write-Host "[FAIL] config.py missing (should still exist)" -ForegroundColor Red
Write-Host "[HINT] Only revert the bad commit, not the good ones after it" -ForegroundColor Yellow
$allChecksPassed = $false
}
}
@@ -211,11 +208,11 @@ if ($allChecksPassed) {
Write-Host "=========================================" -ForegroundColor Green
Write-Host "`nYou've mastered git revert!" -ForegroundColor Cyan
Write-Host "You now understand:" -ForegroundColor Cyan
Write-Host " ✓ Reverting regular commits safely" -ForegroundColor White
Write-Host " ✓ Reverting merge commits with -m flag" -ForegroundColor White
Write-Host " ✓ Reverting commits safely without erasing history" -ForegroundColor White
Write-Host " ✓ Reverting old commits in the middle of history" -ForegroundColor White
Write-Host " ✓ Reverting multiple commits at once" -ForegroundColor White
Write-Host " ✓ Preserving history while undoing changes" -ForegroundColor White
Write-Host "`nReady for Module 06: Git Reset!" -ForegroundColor Green
Write-Host " ✓ Preserving commits before and after the reverted one" -ForegroundColor White
Write-Host "`nReady for Module 07: Git Reset!" -ForegroundColor Green
Write-Host ""
exit 0
} else {