Public/Remove-Branch.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<#
    .SYNOPSIS
        Removes a branch, not only deleting it locally but also from the remote.
 
    .PARAMETER Branch
            Name of the branch that should be deleted.
#>

function Remove-Branch() {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position=0)]
        [ValidateSet([AllBranchesValuesGenerator])]
        [string]$Branch
    )
    process {
        Write-Verbose "Removing branch $Branch."
        Invoke-NativeCommand git push -d origin $Branch
        Invoke-NativeCommand git branch -D $Branch
    }
}

class AllBranchesValuesGenerator : System.Management.Automation.IValidateSetValuesGenerator {
    [string[]] GetValidValues() {
        return Get-AllBranches
    }
}