refactor: check for main branch

This commit is contained in:
Bjarke Sporring
2026-01-15 13:14:38 +01:00
parent 7b638d27de
commit bf07cb1868
2 changed files with 65 additions and 14 deletions

View File

@@ -31,6 +31,19 @@ git init | Out-Null
git config user.name "Workshop Student"
git config user.email "student@example.com"
# Detect the default branch name (could be main, master, etc.)
# First commit creates the branch, so we detect it after that
$mainBranch = git branch --show-current
if (-not $mainBranch) {
# Fallback: Get default branch name from git config
$mainBranch = git config --get init.defaultBranch
if (-not $mainBranch) {
# Ultimate fallback: use "main"
$mainBranch = "main"
}
}
Write-Host "Default branch detected: $mainBranch" -ForegroundColor Yellow
# ============================================================================
# Create a realistic project history with multiple merged branches
# ============================================================================
@@ -96,8 +109,8 @@ Set-Content -Path "login.py" -Value $loginContent
git add .
git commit -m "Add password validation" | Out-Null
# Switch back to main and make more commits
git switch main | Out-Null
# Switch back to main branch
git switch $mainBranch | Out-Null
$appContent = @"
# app.py - Application entry point
@@ -163,8 +176,8 @@ Set-Content -Path "api.py" -Value $apiContent
git add .
git commit -m "Add delete endpoint to API" | Out-Null
# Switch back to main and add documentation
git switch main | Out-Null
# Switch back to main branch and add documentation
git switch $mainBranch | Out-Null
$readmeContent = @"
# My Application
@@ -241,8 +254,22 @@ Set-Content -Path "database.py" -Value $dbContent
git add .
git commit -m "Add disconnect method" | Out-Null
# Switch to main and merge
git switch main | Out-Null
# Switch to main branch and add another commit (to create divergent history)
git switch $mainBranch | Out-Null
$configContent = @"
{
"app": {
"port": 3000,
"debug": false
}
}
"@
Set-Content -Path "config.json" -Value $configContent
git add .
git commit -m "Add configuration file" | Out-Null
# Merge feature-database (will be three-way merge since main diverged)
Write-Host "Merging feature-database into main..." -ForegroundColor Green
git merge feature-database --no-edit | Out-Null
@@ -278,7 +305,7 @@ Write-Host "`n=== Setup Complete! ===" -ForegroundColor Green
Write-Host "`nYour challenge environment is ready in the 'challenge/' directory." -ForegroundColor Cyan
Write-Host "`nThe repository contains a realistic project history:" -ForegroundColor Yellow
Write-Host " - Multiple feature branches (login, api, database)" -ForegroundColor White
Write-Host " - All branches have been merged into main" -ForegroundColor White
Write-Host " - All branches have been merged into $mainBranch" -ForegroundColor White
Write-Host " - View the history: git log --oneline --graph --all" -ForegroundColor White
Write-Host "`nNext steps:" -ForegroundColor Cyan
Write-Host " 1. Read the README.md for detailed instructions" -ForegroundColor White