Public/Remove-ForeignBranches.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<#
.SYNOPSIS Deletes private branches that are not in your own private namespace. #> function Remove-ForeignBranches() { [CmdletBinding(SupportsShouldProcess)] param( ) if (-not $script:PrivateNamespaceInitialized) { throw 'PrivateNamespace is not initialized.' } $heads = Invoke-NativeCommand git for-each-ref --format '%(refname:short)' refs/heads $foreignBranches = $heads | Where-Object { $_.StartsWith($script:PrivateNamespace) -and (-not $_.StartsWith($script:MyNamespace)) } $foreignBranches | ForEach-Object { if ($PSCmdlet.ShouldProcess($_)) { Invoke-NativeCommand git branch -D $_ } } } |