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

@@ -32,6 +32,21 @@ if (-not (Test-Path ".git")) {
exit 1
}
# Detect the main branch name
$allBranches = git branch --list 2>$null | ForEach-Object { $_.Trim('* ') }
if ($allBranches -contains "main") {
$mainBranch = "main"
} elseif ($allBranches -contains "master") {
$mainBranch = "master"
} else {
$mainBranch = git config --get init.defaultBranch
if (-not $mainBranch) {
$mainBranch = $allBranches | Select-Object -First 1
if (-not $mainBranch) { $mainBranch = "main" }
}
}
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
# Check current branch
$currentBranch = git branch --show-current 2>$null
if ($currentBranch -ne "feature-login") {
@@ -53,14 +68,14 @@ if ($status) {
}
# Verify main branch has the security fix
Write-Host "`nChecking main branch for bug fix..." -ForegroundColor Cyan
git checkout main 2>$null | Out-Null
Write-Host "`nChecking $mainBranch branch for bug fix..." -ForegroundColor Cyan
git checkout $mainBranch 2>$null | Out-Null
# Check for bug fix commit
$mainCommits = git log --pretty=format:"%s" main 2>$null
$mainCommits = git log --pretty=format:"%s" $mainBranch 2>$null
if ($mainCommits -notmatch "security bug|Fix.*bug|security fix") {
Write-Host "[FAIL] No security bug fix commit found on main branch." -ForegroundColor Red
Write-Host "Hint: After stashing, switch to main and commit a bug fix" -ForegroundColor Yellow
Write-Host "[FAIL] No security bug fix commit found on $mainBranch branch." -ForegroundColor Red
Write-Host "Hint: After stashing, switch to $mainBranch and commit a bug fix" -ForegroundColor Yellow
git checkout feature-login 2>$null | Out-Null
Set-Location ..
exit 1
@@ -68,7 +83,7 @@ if ($mainCommits -notmatch "security bug|Fix.*bug|security fix") {
# Check that app.py has been fixed
if (-not (Test-Path "app.py")) {
Write-Host "[FAIL] app.py not found on main branch." -ForegroundColor Red
Write-Host "[FAIL] app.py not found on $mainBranch branch." -ForegroundColor Red
git checkout feature-login 2>$null | Out-Null
Set-Location ..
exit 1