40 lines
1.1 KiB
PowerShell
40 lines
1.1 KiB
PowerShell
function Find-MergedGitBranches {
|
|
[CmdletBinding()]
|
|
param ()
|
|
|
|
$alwaysKeep = @('main','master','develop','release')
|
|
|
|
$mergedLines = Invoke-GitCommand -Verb branch -Arguments @("--merged")
|
|
|
|
$branches = @()
|
|
|
|
foreach ($line in $mergedLines) {
|
|
$trimLine = $line.Trim()
|
|
if ($trimLine.StartsWith("*") -or $alwaysKeep -contains $trimLine) {
|
|
continue
|
|
} else {
|
|
$branches += $trimLine
|
|
}
|
|
}
|
|
|
|
# Look for branches removed on origin
|
|
$goneLines = Invoke-GitCommand -Verb branch -Arguments @("-vv")
|
|
|
|
foreach ($line in $goneLines) {
|
|
if ($line -match 'gone') {
|
|
# magic string split
|
|
$line = ($line -split '\[')[0]
|
|
|
|
# Remove the committish at the end of the line
|
|
$line = $line.Substring(0, $_.Length - 9)
|
|
$trimLine = $line.Trim()
|
|
if ($trimLine.StartsWith("*") -or $alwaysKeep -contains $trimLine) {
|
|
continue
|
|
} else {
|
|
$branches += $trimLine
|
|
}
|
|
}
|
|
}
|
|
|
|
return $branches
|
|
} |