ps/Modules/Cole.PowerShell.Developer/TODO/Find-MergedGitBranches.ps1

40 lines
1.1 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
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
}