Files
git-workshop/util.ps1
2026-01-21 10:51:07 +01:00

51 lines
1.2 KiB
PowerShell

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
}
function Write-Error {
param([string] $Message)
Write-Host "[ERROR] $Message" -ForegroundColor Red
}
function Get-LocalBranches {
return git for-each-ref --format='%(refname:short)' refs/heads
}
function Get-MainBranch {
$mainBranch = git branch --show-current 2>$null
$allBranches = Get-LocalBranches
if ($allBranches -contains "main") {
$mainBranch = "main"
} elseif ($allBranches -contains "master") {
$mainBranch = "master"
} else {
# Get the default branch from git config
$mainBranch = git config --get init.defaultBranch
if (-not $mainBranch) {
# Ultimate fallback: use the first branch
$mainBranch = $allBranches | Select-Object -First 1
if (-not $mainBranch) { $mainBranch = "main" }
}
}
return $mainBranch
}