feat: check for mainbranch
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user