Public/Get-BranchComment.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
28
29
<#
    .SYNOPSIS
        Gets the comment stored via Set-BranchComment for the current branch.
 
    .PARAMETER Branch
        Name of the branch for which to get the comment
#>

function Get-BranchComment() {
    param(
        [Parameter(Position=0)]
        [ValidateSet([AllBranchesValuesGenerator])]
        [string]$Branch = 'HEAD'
    )
    $branchName = Invoke-NativeCommand git rev-parse --abbrev-ref $Branch
    $configValue = "branch.$branchName.description"
    $comment = git config $configValue
    if ($LastExitCode -ne 0) {
        Write-Error 'No comment set.'
    } else {
        $comment
    }    
}

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