209 lines
8.0 KiB
PowerShell
209 lines
8.0 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
<#
|
|
.SYNOPSIS
|
|
Verifies the Module 04 challenge solution.
|
|
|
|
.DESCRIPTION
|
|
This script checks that you've successfully resolved the merge conflict by:
|
|
- Merging both branches into main
|
|
- Resolving the conflict in config.json
|
|
- Keeping both timeout and debug settings
|
|
- Ensuring valid JSON syntax
|
|
#>
|
|
|
|
$script:allChecksPassed = $true
|
|
|
|
# ============================================================================
|
|
# Helper Functions
|
|
# ============================================================================
|
|
|
|
function Write-Pass {
|
|
param([string]$Message)
|
|
Write-Host "[PASS] $Message" -ForegroundColor Green
|
|
}
|
|
|
|
function Write-Fail {
|
|
param([string]$Message)
|
|
Write-Host "[FAIL] $Message" -ForegroundColor Red
|
|
$script:allChecksPassed = $false
|
|
}
|
|
|
|
function Write-Hint {
|
|
param([string]$Message)
|
|
Write-Host "[HINT] $Message" -ForegroundColor Yellow
|
|
}
|
|
|
|
function Write-Info {
|
|
param([string]$Message)
|
|
Write-Host "[INFO] $Message" -ForegroundColor Cyan
|
|
}
|
|
|
|
# ============================================================================
|
|
# Check challenge directory exists
|
|
# ============================================================================
|
|
|
|
if (-not (Test-Path "challenge")) {
|
|
Write-Host "[ERROR] Challenge directory not found." -ForegroundColor Red
|
|
Write-Host "Run .\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
|
|
Push-Location "challenge"
|
|
|
|
if (-not (Test-Path ".git")) {
|
|
Write-Host "[ERROR] Not a git repository." -ForegroundColor Red
|
|
Write-Host "Run ..\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
|
Pop-Location
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "`n=== Verifying Module 04: Merge Conflicts ===" -ForegroundColor Cyan
|
|
|
|
# ============================================================================
|
|
# Check current branch
|
|
# ============================================================================
|
|
$currentBranch = git branch --show-current 2>$null
|
|
if ($currentBranch -eq "main") {
|
|
Write-Pass "Currently on main branch"
|
|
} else {
|
|
Write-Fail "Should be on main branch (currently on: $currentBranch)"
|
|
Write-Hint "Switch to main with: git switch main"
|
|
}
|
|
|
|
# ============================================================================
|
|
# Check that merge is not in progress
|
|
# ============================================================================
|
|
if (Test-Path ".git/MERGE_HEAD") {
|
|
Write-Fail "Merge is still in progress (conflicts not resolved)"
|
|
Write-Hint "Resolve conflicts in config.json, then: git add config.json && git commit"
|
|
Pop-Location
|
|
exit 1
|
|
} else {
|
|
Write-Pass "No merge in progress (conflicts resolved)"
|
|
}
|
|
|
|
# ============================================================================
|
|
# Check if config.json exists
|
|
# ============================================================================
|
|
if (-not (Test-Path "config.json")) {
|
|
Write-Fail "File 'config.json' not found"
|
|
Write-Hint "The config.json file should exist"
|
|
Pop-Location
|
|
exit 1
|
|
}
|
|
|
|
# ============================================================================
|
|
# Verify config.json is valid JSON
|
|
# ============================================================================
|
|
try {
|
|
$configContent = Get-Content "config.json" -Raw
|
|
$config = $configContent | ConvertFrom-Json -ErrorAction Stop
|
|
Write-Pass "File 'config.json' is valid JSON"
|
|
} catch {
|
|
Write-Fail "File 'config.json' is not valid JSON"
|
|
Write-Hint "Make sure you removed all conflict markers (<<<<<<<, =======, >>>>>>>)"
|
|
Write-Hint "Check for missing commas or brackets"
|
|
Pop-Location
|
|
exit 1
|
|
}
|
|
|
|
# ============================================================================
|
|
# Check for conflict markers
|
|
# ============================================================================
|
|
if ($configContent -match '<<<<<<<|=======|>>>>>>>') {
|
|
Write-Fail "Conflict markers still present in config.json"
|
|
Write-Hint "Remove all conflict markers (<<<<<<<, =======, >>>>>>>)"
|
|
Pop-Location
|
|
exit 1
|
|
} else {
|
|
Write-Pass "No conflict markers in config.json"
|
|
}
|
|
|
|
# ============================================================================
|
|
# Verify both settings are present (timeout and debug)
|
|
# ============================================================================
|
|
if ($config.app.timeout -eq 5000) {
|
|
Write-Pass "Timeout setting preserved (5000)"
|
|
} else {
|
|
Write-Fail "Timeout setting missing or incorrect"
|
|
Write-Hint "Keep the timeout: 5000 setting from add-timeout branch"
|
|
}
|
|
|
|
if ($config.app.debug -eq $true) {
|
|
Write-Pass "Debug setting preserved (true)"
|
|
} else {
|
|
Write-Fail "Debug setting missing or incorrect"
|
|
Write-Hint "Keep the debug: true setting from add-debug branch"
|
|
}
|
|
|
|
# ============================================================================
|
|
# Verify both branches were merged
|
|
# ============================================================================
|
|
$addTimeoutMerged = git log --oneline --grep="add-timeout" 2>$null | Select-String "Merge"
|
|
$addDebugMerged = git log --oneline --grep="add-debug" 2>$null | Select-String "Merge"
|
|
|
|
if ($addTimeoutMerged) {
|
|
Write-Pass "add-timeout branch has been merged"
|
|
} else {
|
|
# Check if it was a fast-forward merge (commits exist but no merge commit)
|
|
$timeoutCommit = git log --oneline --grep="Add timeout configuration" 2>$null
|
|
if ($timeoutCommit) {
|
|
Write-Pass "add-timeout branch changes are in main"
|
|
} else {
|
|
Write-Fail "add-timeout branch not merged"
|
|
Write-Hint "Merge with: git merge add-timeout"
|
|
}
|
|
}
|
|
|
|
if ($addDebugMerged) {
|
|
Write-Pass "add-debug branch has been merged"
|
|
} else {
|
|
Write-Fail "add-debug branch not merged"
|
|
Write-Hint "Merge with: git merge add-debug"
|
|
}
|
|
|
|
# ============================================================================
|
|
# Check commit count (should have both merges)
|
|
# ============================================================================
|
|
$totalCommits = [int](git rev-list --count HEAD 2>$null)
|
|
if ($totalCommits -ge 5) {
|
|
Write-Pass "Repository has $totalCommits commits (all merges complete)"
|
|
} else {
|
|
Write-Info "Repository has $totalCommits commits"
|
|
Write-Hint "Make sure both branches are merged"
|
|
}
|
|
|
|
Pop-Location
|
|
|
|
# ============================================================================
|
|
# Final summary
|
|
# ============================================================================
|
|
Write-Host ""
|
|
if ($script:allChecksPassed) {
|
|
Write-Host "=========================================" -ForegroundColor Green
|
|
Write-Host " CONGRATULATIONS! CHALLENGE PASSED!" -ForegroundColor Green
|
|
Write-Host "=========================================" -ForegroundColor Green
|
|
Write-Host "`nYou've successfully:" -ForegroundColor Cyan
|
|
Write-Host " ✓ Discovered changes using git diff" -ForegroundColor White
|
|
Write-Host " ✓ Merged the first branch" -ForegroundColor White
|
|
Write-Host " ✓ Encountered a merge conflict" -ForegroundColor White
|
|
Write-Host " ✓ Resolved the conflict by keeping both changes" -ForegroundColor White
|
|
Write-Host " ✓ Completed the merge" -ForegroundColor White
|
|
Write-Host "`nYou're now ready to handle merge conflicts in real projects!" -ForegroundColor Green
|
|
Write-Host ""
|
|
exit 0
|
|
} else {
|
|
Write-Host "[SUMMARY] Some checks failed. Review the hints above." -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "Quick guide:" -ForegroundColor Cyan
|
|
Write-Host " 1. Make sure you're on main: git switch main" -ForegroundColor White
|
|
Write-Host " 2. Merge first branch: git merge add-timeout" -ForegroundColor White
|
|
Write-Host " 3. Merge second branch: git merge add-debug" -ForegroundColor White
|
|
Write-Host " 4. Resolve conflict: edit config.json, remove markers, keep both settings" -ForegroundColor White
|
|
Write-Host " 5. Stage resolved file: git add config.json" -ForegroundColor White
|
|
Write-Host " 6. Complete merge: git commit" -ForegroundColor White
|
|
Write-Host " 7. Run this verify script again" -ForegroundColor White
|
|
Write-Host ""
|
|
exit 1
|
|
}
|