From 3a6eb0646b62df68c47030a6116bd06b8379e906 Mon Sep 17 00:00:00 2001 From: Bjarke Sporring Date: Wed, 21 Jan 2026 10:51:07 +0100 Subject: [PATCH] feat: add util.ps1 script for common operations --- util.ps1 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 util.ps1 diff --git a/util.ps1 b/util.ps1 new file mode 100644 index 0000000..6eadaf8 --- /dev/null +++ b/util.ps1 @@ -0,0 +1,50 @@ +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 +}