refactor: we're breaking out merge-conflicts

This commit is contained in:
Bjarke Sporring
2026-01-15 12:51:43 +01:00
parent ea5cbccc75
commit 7b638d27de
29 changed files with 1385 additions and 1310 deletions

View File

@@ -1,34 +1,15 @@
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Verifies the Module 03 challenge solution (checkpoint-aware).
Verifies the Module 03 challenge solution.
.DESCRIPTION
This script can verify completion of individual checkpoints or
the entire module. Without arguments, it verifies all checkpoints.
.PARAMETER Checkpoint
The checkpoint to verify: start, merge, or merge-conflict.
If not specified, verifies all checkpoints.
.EXAMPLE
.\verify.ps1
Verifies all three checkpoints are complete.
.EXAMPLE
.\verify.ps1 start
Verifies only the branching basics checkpoint.
.EXAMPLE
.\verify.ps1 merge
Verifies only the merging checkpoint.
This script checks that you've practiced branching and merging by:
- Creating at least one new branch (beyond the example branches)
- Making commits on your branch
- Merging your branch into main
#>
param(
[ValidateSet('start', 'merge', 'merge-conflict', '')]
[string]$Checkpoint = ''
)
$script:allChecksPassed = $true
# ============================================================================
@@ -51,198 +32,15 @@ function Write-Hint {
Write-Host "[HINT] $Message" -ForegroundColor Yellow
}
# ============================================================================
# Checkpoint 1: Branching Basics Verification
# ============================================================================
function Verify-Branching {
Write-Host "`n=== Checkpoint 1: Branching Basics ===" -ForegroundColor Cyan
# Save current branch
$originalBranch = git branch --show-current 2>$null
# Check if feature-login branch exists
$branchExists = git branch --list "feature-login" 2>$null
if ($branchExists) {
Write-Pass "Branch 'feature-login' exists"
} else {
Write-Fail "Branch 'feature-login' not found"
Write-Hint "Create the branch with: git switch -c feature-login"
return
}
# Check if feature-login has commits beyond main (or if they've been merged)
$commitCount = git rev-list main..feature-login --count 2>$null
$mergeCommitExists = (git log --merges --oneline 2>$null | Select-String "Merge.*feature-login")
if ($mergeCommitExists -and $commitCount -eq 0) {
# Commits were merged into main - this is correct!
Write-Pass "Branch 'feature-login' commits have been merged into main"
} elseif ($commitCount -ge 2) {
Write-Pass "Branch 'feature-login' has $commitCount new commits"
} else {
Write-Fail "Branch 'feature-login' needs at least 2 new commits (found: $commitCount)"
Write-Hint "Make sure you've committed login.py and made at least one more commit"
}
# Switch to feature-login and check for login.py
git switch feature-login 2>$null | Out-Null
if (Test-Path "login.py") {
Write-Pass "File 'login.py' exists in feature-login branch"
} else {
Write-Fail "File 'login.py' not found in feature-login branch"
Write-Hint "Create login.py and commit it to the feature-login branch"
}
# Switch to main and verify login.py doesn't exist there yet (unless merged)
git switch main 2>$null | Out-Null
# Check if merge happened - if so, login.py can exist on main
$mergeCommitExists = (git log --merges --oneline 2>$null | Select-String "Merge.*feature-login")
if (-not $mergeCommitExists) {
# No merge yet - login.py should NOT be on main
if (-not (Test-Path "login.py")) {
Write-Pass "File 'login.py' does NOT exist in main branch (branches are independent!)"
} else {
Write-Fail "File 'login.py' should not exist in main branch yet (before merge)"
Write-Hint "Make sure you created login.py only on the feature-login branch"
}
}
# Switch back to original branch
if ($originalBranch) {
git switch $originalBranch 2>$null | Out-Null
}
function Write-Info {
param([string]$Message)
Write-Host "[INFO] $Message" -ForegroundColor Cyan
}
# ============================================================================
# Checkpoint 2: Merging Verification
# Check challenge directory exists
# ============================================================================
function Verify-Merging {
Write-Host "`n=== Checkpoint 2: Merging Branches ===" -ForegroundColor Cyan
# Check current branch is main
$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 if login.py exists on main (indicates merge happened)
if (Test-Path "login.py") {
Write-Pass "File 'login.py' exists on main branch (merged successfully)"
} else {
Write-Fail "File 'login.py' not found on main branch"
Write-Hint "Merge feature-login into main with: git merge feature-login"
}
# Check for merge commit
$mergeCommitExists = (git log --merges --oneline 2>$null | Select-String "Merge.*feature-login")
if ($mergeCommitExists) {
Write-Pass "Merge commit exists"
} else {
Write-Fail "No merge commit found"
Write-Hint "Create a merge commit with: git merge feature-login"
}
# Check commit count (should have both branches' commits)
$commitCount = [int](git rev-list --count HEAD 2>$null)
if ($commitCount -ge 6) {
Write-Pass "Repository has $commitCount commits (merge complete)"
} else {
Write-Fail "Repository should have at least 6 commits after merge (found: $commitCount)"
}
}
# ============================================================================
# Checkpoint 3: Merge Conflicts Verification
# ============================================================================
function Verify-MergeConflicts {
Write-Host "`n=== Checkpoint 3: Resolving Merge Conflicts ===" -ForegroundColor Cyan
# Check current branch is main
$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"
return
} else {
Write-Pass "No merge in progress (conflicts resolved)"
}
# Check if config.json exists
if (Test-Path "config.json") {
Write-Pass "File 'config.json' exists"
} else {
Write-Fail "File 'config.json' not found"
Write-Hint "Merge update-config branch with: git merge update-config"
return
}
# 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 (<<<<<<<, =======, >>>>>>>)"
return
}
# Check for conflict markers
if ($configContent -match '<<<<<<<|=======|>>>>>>>') {
Write-Fail "Conflict markers still present in config.json"
Write-Hint "Remove all conflict markers (<<<<<<<, =======, >>>>>>>)"
return
} 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 main 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 update-config branch"
}
# Verify merge commit exists for update-config
$updateConfigMerge = (git log --merges --oneline 2>$null | Select-String "Merge.*update-config")
if ($updateConfigMerge) {
Write-Pass "Merge commit exists for update-config branch"
} else {
Write-Fail "No merge commit found for update-config"
Write-Hint "Complete the merge with: git commit (after resolving conflicts)"
}
}
# ============================================================================
# Main Script Logic
# ============================================================================
# Check if 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
@@ -251,7 +49,6 @@ if (-not (Test-Path "challenge")) {
Push-Location "challenge"
# Check if git repository exists
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
@@ -259,62 +56,98 @@ if (-not (Test-Path ".git")) {
exit 1
}
# Run appropriate verification
if ($Checkpoint -eq '') {
# Verify all checkpoints
Write-Host "`n=== Verifying All Checkpoints ===" -ForegroundColor Cyan
Write-Host "`n=== Verifying Module 03: Branching and Merging ===" -ForegroundColor Cyan
Verify-Branching
Verify-Merging
Verify-MergeConflicts
# ============================================================================
# Count initial setup commits (should be 13 commits from setup)
# ============================================================================
$initialCommitCount = 13
# ============================================================================
# Check for new commits beyond setup
# ============================================================================
Write-Host "`nChecking your work..." -ForegroundColor Cyan
$totalCommits = [int](git rev-list --count HEAD 2>$null)
if ($totalCommits -gt $initialCommitCount) {
$newCommits = $totalCommits - $initialCommitCount
Write-Pass "Found $newCommits new commit(s) beyond the initial setup"
} else {
# Verify specific checkpoint
switch ($Checkpoint) {
'start' { Verify-Branching }
'merge' { Verify-Merging }
'merge-conflict' { Verify-MergeConflicts }
}
Write-Fail "No new commits found"
Write-Hint "Create a branch, make some commits, and merge it into main"
Write-Hint "Example: git switch -c my-feature"
}
# ============================================================================
# Check for branches (excluding the example branches)
# ============================================================================
$allBranches = git branch --list 2>$null | ForEach-Object { $_.Trim('* ') }
$exampleBranches = @('main', 'feature-login', 'feature-api', 'feature-database')
$studentBranches = $allBranches | Where-Object { $_ -notin $exampleBranches }
if ($studentBranches.Count -gt 0) {
Write-Pass "Created $($studentBranches.Count) new branch(es): $($studentBranches -join ', ')"
} else {
Write-Info "No new branches found (it's OK if you deleted them after merging)"
Write-Hint "To practice: git switch -c your-branch-name"
}
# ============================================================================
# Check for merge commits by the student
# ============================================================================
$setupUser = "Workshop Student"
$mergeCommits = git log --merges --format="%s" 2>$null
# Count how many merge commits exist beyond the initial 3
$totalMerges = ($mergeCommits | Measure-Object).Count
$setupMerges = 3 # feature-login, feature-api, feature-database
if ($totalMerges -gt $setupMerges) {
$studentMerges = $totalMerges - $setupMerges
Write-Pass "Performed $studentMerges merge(s) of your own work"
} else {
Write-Fail "No merge commits found beyond the example merges"
Write-Hint "Create a branch, add commits, then merge it: git merge your-branch-name"
}
# ============================================================================
# Check current branch
# ============================================================================
$currentBranch = git branch --show-current 2>$null
if ($currentBranch -eq "main") {
Write-Pass "Currently on main branch"
} else {
Write-Info "Currently on '$currentBranch' branch"
Write-Hint "Typically you merge feature branches INTO main"
}
Pop-Location
# ============================================================================
# Final summary
# ============================================================================
Write-Host ""
if ($script:allChecksPassed) {
Write-Host "=========================================" -ForegroundColor Green
Write-Host " CONGRATULATIONS! CHALLENGE PASSED!" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Green
if ($Checkpoint -eq '') {
Write-Host "`nYou've completed the entire module!" -ForegroundColor Cyan
Write-Host "You've mastered:" -ForegroundColor Cyan
Write-Host " ✓ Creating and working with branches" -ForegroundColor White
Write-Host " ✓ Merging branches together" -ForegroundColor White
Write-Host " ✓ Resolving merge conflicts" -ForegroundColor White
Write-Host "`nReady for the next module!" -ForegroundColor Green
} else {
Write-Host "`nCheckpoint '$Checkpoint' complete!" -ForegroundColor Cyan
switch ($Checkpoint) {
'start' {
Write-Host "Next: Move to the merging checkpoint" -ForegroundColor White
Write-Host " ..\reset.ps1 merge OR continue to merge feature-login" -ForegroundColor Yellow
}
'merge' {
Write-Host "Next: Move to the conflict resolution checkpoint" -ForegroundColor White
Write-Host " ..\reset.ps1 merge-conflict" -ForegroundColor Yellow
}
'merge-conflict' {
Write-Host "Module complete! Ready for the next module!" -ForegroundColor Green
}
}
}
Write-Host "`nYou've successfully practiced:" -ForegroundColor Cyan
Write-Host " ✓ Creating branches" -ForegroundColor White
Write-Host " ✓ Making commits on branches" -ForegroundColor White
Write-Host " ✓ Merging branches together" -ForegroundColor White
Write-Host "`nReady for the next module!" -ForegroundColor Green
Write-Host ""
exit 0
} else {
Write-Host "[SUMMARY] Some checks failed. Review the hints above and try again." -ForegroundColor Red
Write-Host "[INFO] You can run this verification script as many times as needed." -ForegroundColor Yellow
Write-Host "[SUMMARY] Some checks failed. Review the hints above." -ForegroundColor Red
Write-Host ""
Write-Host "Quick guide:" -ForegroundColor Cyan
Write-Host " 1. Create a branch: git switch -c my-feature" -ForegroundColor White
Write-Host " 2. Make changes and commit them" -ForegroundColor White
Write-Host " 3. Switch to main: git switch main" -ForegroundColor White
Write-Host " 4. Merge your branch: git merge my-feature" -ForegroundColor White
Write-Host " 5. Run this verify script again" -ForegroundColor White
Write-Host ""
exit 1
}