feat: check for mainbranch

This commit is contained in:
Bjarke Sporring
2026-01-15 14:31:00 +01:00
parent 40341d21a7
commit 9fbdd941fa
8 changed files with 152 additions and 41 deletions

View File

@@ -33,6 +33,9 @@ git init | Out-Null
git config user.name "Workshop Student"
git config user.email "student@example.com"
# Detect the default branch name after first commit (created below)
# Will be detected after the initial commit
# ============================================================================
# Create initial commit (shared by all scenarios)
# ============================================================================
@@ -45,6 +48,14 @@ Set-Content -Path "README.md" -Value $readmeContent
git add .
git commit -m "Initial commit" | Out-Null
# Detect the main branch name after first commit
$mainBranch = git branch --show-current
if (-not $mainBranch) {
$mainBranch = git config --get init.defaultBranch
if (-not $mainBranch) { $mainBranch = "main" }
}
Write-Host "Default branch detected: $mainBranch" -ForegroundColor Yellow
# ============================================================================
# SCENARIO 1: Soft Reset (--soft)
# ============================================================================
@@ -155,7 +166,7 @@ Write-Host "[CREATED] soft-reset branch with commit to reset --soft" -Foreground
Write-Host "`nScenario 2: Creating mixed-reset branch..." -ForegroundColor Cyan
# Switch back to initial commit and create mixed-reset branch
git switch main | Out-Null
git switch $mainBranch | Out-Null
git switch -c mixed-reset | Out-Null
# Build up scenario 2 commits
@@ -256,7 +267,7 @@ Write-Host "[CREATED] mixed-reset branch with commits to reset --mixed" -Foregro
Write-Host "`nScenario 3: Creating hard-reset branch..." -ForegroundColor Cyan
# Switch back to main and create hard-reset branch
git switch main | Out-Null
git switch $mainBranch | Out-Null
git switch -c hard-reset | Out-Null
# Reset to basic state