feat: add remotes and stash

This commit is contained in:
Bjarke Sporring
2026-01-04 17:53:41 +01:00
parent 515a76dd5a
commit cde1a6ba70
32 changed files with 1178 additions and 379 deletions

View File

@@ -0,0 +1,206 @@
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Verifies the cherry-pick challenge solution.
.DESCRIPTION
Checks that the user successfully cherry-picked only the bug fix commits
to the main branch without merging the experimental features.
#>
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 cherry-pick
if (Test-Path ".git/CHERRY_PICK_HEAD") {
Write-Host "[FAIL] Cherry-pick is not complete. There may be unresolved conflicts." -ForegroundColor Red
Write-Host "Hint: Resolve any conflicts, then use:" -ForegroundColor Yellow
Write-Host " git add <file>" -ForegroundColor White
Write-Host " git cherry-pick --continue" -ForegroundColor White
Write-Host "Or abort with: git cherry-pick --abort" -ForegroundColor White
Set-Location ..
exit 1
}
# Check commit count on main (should be 4: 2 initial + 2 cherry-picked)
$mainCommitCount = (git rev-list --count main 2>$null)
if ($mainCommitCount -ne 4) {
Write-Host "[FAIL] Expected 4 commits on main branch, found $mainCommitCount" -ForegroundColor Red
if ($mainCommitCount -lt 4) {
Write-Host "Hint: You should cherry-pick 2 bug fix commits to main" -ForegroundColor Yellow
} else {
Write-Host "Hint: You should cherry-pick ONLY the 2 bug fix commits, not all commits" -ForegroundColor Yellow
}
Write-Host "`nExpected commits on main:" -ForegroundColor Yellow
Write-Host " 1. Initial app implementation" -ForegroundColor White
Write-Host " 2. Add README" -ForegroundColor White
Write-Host " 3. Fix security vulnerability in input validation (cherry-picked)" -ForegroundColor White
Write-Host " 4. Fix performance issue with data caching (cherry-picked)" -ForegroundColor White
Set-Location ..
exit 1
}
# Check for merge commits (should be none - cherry-pick doesn't create merge commits)
$mergeCommits = git log --merges --oneline main 2>$null
if ($mergeCommits) {
Write-Host "[FAIL] Found merge commits on main. You should use cherry-pick, not merge." -ForegroundColor Red
Write-Host "Hint: Use 'git cherry-pick <commit-hash>' instead of 'git merge'" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check that security.js exists (from the security fix commit)
if (-not (Test-Path "security.js")) {
Write-Host "[FAIL] security.js not found on main branch." -ForegroundColor Red
Write-Host "Hint: You need to cherry-pick the 'Fix security vulnerability' commit" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check that security.js has the security fix
$securityContent = Get-Content "security.js" -Raw
if ($securityContent -notmatch "sanitizeInput") {
Write-Host "[FAIL] security.js is missing the sanitizeInput function." -ForegroundColor Red
Set-Location ..
exit 1
}
if ($securityContent -notmatch "validateToken") {
Write-Host "[FAIL] security.js is missing the validateToken function." -ForegroundColor Red
Set-Location ..
exit 1
}
# Check that app.js exists
if (-not (Test-Path "app.js")) {
Write-Host "[FAIL] app.js not found." -ForegroundColor Red
Set-Location ..
exit 1
}
# Check that app.js has the performance fix (cache) but NOT experimental features
$appContent = Get-Content "app.js" -Raw
# Should have cache (from performance fix)
if ($appContent -notmatch "cache") {
Write-Host "[FAIL] app.js is missing the performance fix (cache)." -ForegroundColor Red
Write-Host "Hint: You need to cherry-pick the 'Fix performance issue' commit" -ForegroundColor Yellow
Set-Location ..
exit 1
}
if ($appContent -notmatch "getData") {
Write-Host "[FAIL] app.js is missing the getData method from performance fix." -ForegroundColor Red
Set-Location ..
exit 1
}
# Should NOT have experimental features
if ($appContent -match "experimentalMode") {
Write-Host "[FAIL] app.js contains experimental features (experimentalMode)." -ForegroundColor Red
Write-Host "Hint: You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
Write-Host " The experimental feature commits should stay on development branch only" -ForegroundColor Yellow
Set-Location ..
exit 1
}
if ($appContent -match "betaFeatures") {
Write-Host "[FAIL] app.js contains experimental features (betaFeatures)." -ForegroundColor Red
Write-Host "Hint: You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
Set-Location ..
exit 1
}
if ($appContent -match "enableExperimentalFeatures") {
Write-Host "[FAIL] app.js contains experimental features (enableExperimentalFeatures)." -ForegroundColor Red
Write-Host "Hint: You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check commit messages to verify cherry-picks
$commits = git log --pretty=format:"%s" main 2>$null
$commitArray = $commits -split "`n"
$hasSecurityFix = $false
$hasPerformanceFix = $false
foreach ($commit in $commitArray) {
if ($commit -match "security vulnerability") {
$hasSecurityFix = $true
}
if ($commit -match "performance issue") {
$hasPerformanceFix = $true
}
}
if (-not $hasSecurityFix) {
Write-Host "[FAIL] Security fix commit not found on main branch." -ForegroundColor Red
Write-Host "Hint: Cherry-pick the 'Fix security vulnerability' commit from development" -ForegroundColor Yellow
Set-Location ..
exit 1
}
if (-not $hasPerformanceFix) {
Write-Host "[FAIL] Performance fix commit not found on main branch." -ForegroundColor Red
Write-Host "Hint: Cherry-pick the 'Fix performance issue' commit from development" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Verify development branch still has all commits
$devCommitCount = (git rev-list --count development 2>$null)
if ($devCommitCount -ne 6) {
Write-Host "[FAIL] Development branch should still have 6 commits." -ForegroundColor Red
Write-Host "Found: $devCommitCount commits" -ForegroundColor Yellow
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 "- Cherry-picked the security vulnerability fix to main" -ForegroundColor White
Write-Host "- Cherry-picked the performance issue fix to main" -ForegroundColor White
Write-Host "- Left experimental features on development branch only" -ForegroundColor White
Write-Host "- Kept development branch intact with all commits" -ForegroundColor White
Write-Host "`nPerfect use of cherry-pick!" -ForegroundColor Green
Write-Host "You selectively applied critical fixes without merging unfinished features.`n" -ForegroundColor Green
Write-Host "Try 'git log --oneline --graph --all' to see both branches." -ForegroundColor Cyan
Set-Location ..
exit 0