Files
2026-01-07 23:03:18 +01:00

152 lines
5.2 KiB
PowerShell

#!/usr/bin/env pwsh
<#
.SYNOPSIS
Verifies the merge conflicts challenge solution.
.DESCRIPTION
Checks that the user successfully resolved the merge conflict,
kept both configuration settings, and completed the merge.
#>
Set-Location "challenge" -ErrorAction SilentlyContinue
# Check if challenge directory exists
if (-not (Test-Path "../verify.ps1")) {
Write-Host "Error: Please run this script from the module directory" -ForegroundColor Red
exit 1
}
if (-not (Test-Path ".")) {
Write-Host "Error: Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
Set-Location ..
exit 1
}
Write-Host "Verifying your solution..." -ForegroundColor Cyan
# Check if git repository exists
if (-not (Test-Path ".git")) {
Write-Host "[FAIL] No git repository found." -ForegroundColor Red
Set-Location ..
exit 1
}
# Check current branch
$currentBranch = git branch --show-current 2>$null
if ($currentBranch -ne "main") {
Write-Host "[FAIL] You should be on the 'main' branch." -ForegroundColor Red
Write-Host "Current branch: $currentBranch" -ForegroundColor Yellow
Write-Host "Hint: Use 'git checkout main' to switch to main branch" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check if there's an ongoing merge
if (Test-Path ".git/MERGE_HEAD") {
Write-Host "[FAIL] Merge is not complete. There are still unresolved conflicts." -ForegroundColor Red
Write-Host "Hint: After resolving conflicts in config.json, use:" -ForegroundColor Yellow
Write-Host " git add config.json" -ForegroundColor White
Write-Host " git commit" -ForegroundColor White
Set-Location ..
exit 1
}
# Check if config.json exists
if (-not (Test-Path "config.json")) {
Write-Host "[FAIL] config.json file not found." -ForegroundColor Red
Set-Location ..
exit 1
}
# Read and parse config.json
try {
$configContent = Get-Content "config.json" -Raw
$config = $configContent | ConvertFrom-Json
} catch {
Write-Host "[FAIL] config.json is not valid JSON." -ForegroundColor Red
Write-Host "Make sure you removed all conflict markers (<<<<<<, ======, >>>>>>)" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check for conflict markers (in case user forgot to remove them)
if ($configContent -match "<<<<<<|======|>>>>>>") {
Write-Host "[FAIL] Conflict markers still present in config.json" -ForegroundColor Red
Write-Host "Remove all lines containing: <<<<<<, ======, >>>>>>" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check if both timeout and debug settings exist
$hasTimeout = $null -ne $config.app.timeout
$hasDebug = $null -ne $config.app.debug
if (-not $hasTimeout) {
Write-Host "[FAIL] The 'timeout' setting is missing from config.json" -ForegroundColor Red
Write-Host "Hint: The resolved file should include both timeout AND debug settings" -ForegroundColor Yellow
Set-Location ..
exit 1
}
if (-not $hasDebug) {
Write-Host "[FAIL] The 'debug' setting is missing from config.json" -ForegroundColor Red
Write-Host "Hint: The resolved file should include both timeout AND debug settings" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Validate the values
if ($config.app.timeout -ne 5000) {
Write-Host "[FAIL] The 'timeout' value should be 5000" -ForegroundColor Red
Set-Location ..
exit 1
}
if ($config.app.debug -ne $true) {
Write-Host "[FAIL] The 'debug' value should be true" -ForegroundColor Red
Set-Location ..
exit 1
}
# Check that merge commit exists
$commitCount = (git rev-list --count HEAD 2>$null)
if ($commitCount -lt 4) {
Write-Host "[FAIL] Not enough commits. Expected at least 4 commits (including merge commit)." -ForegroundColor Red
Write-Host "Current commits: $commitCount" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check that the latest commit is a merge commit (has 2 parents)
$parentCount = (git rev-list --parents -n 1 HEAD 2>$null).Split(' ').Count - 1
if ($parentCount -ne 2) {
Write-Host "[FAIL] The latest commit should be a merge commit." -ForegroundColor Red
Write-Host "Hint: Complete the merge with 'git commit' after resolving conflicts" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check that both branches are merged
$branches = git branch --merged update-config 2>$null
Write-Host "$branches $($branches -notmatch 'update-config')"
if ($branches -notmatch "update-config") {
Write-Host "[FAIL] The 'update-config' branch was not merged." -ForegroundColor Red
Set-Location ..
exit 1
}
# Success!
Write-Host "`n========================================" -ForegroundColor Green
Write-Host "SUCCESS! Challenge completed!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host "`nYou have successfully:" -ForegroundColor Cyan
Write-Host "- Identified the merge conflict" -ForegroundColor White
Write-Host "- Resolved the conflict by keeping both settings" -ForegroundColor White
Write-Host "- Completed the merge with a proper merge commit" -ForegroundColor White
Write-Host "`nYou now understand how to handle merge conflicts!" -ForegroundColor Green
Write-Host "This is a critical skill for collaborative development.`n" -ForegroundColor Green
Set-Location ..
exit 0