154 lines
5.9 KiB
PowerShell
Executable File
154 lines
5.9 KiB
PowerShell
Executable File
#!/usr/bin/env pwsh
|
|
<#
|
|
.SYNOPSIS
|
|
Verifies the Module 03 challenge solution.
|
|
|
|
.DESCRIPTION
|
|
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
|
|
#>
|
|
|
|
$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 03: Branching and Merging ===" -ForegroundColor Cyan
|
|
|
|
# ============================================================================
|
|
# 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 {
|
|
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
|
|
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." -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
|
|
}
|