Functions/Get-GitHead.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function Get-GitHead {
    <#
    .SYNOPSIS
    Gets the currently checked-out branch of the repository.
    #>

    [CmdletBinding()]
    [OutputType([LibGit2Sharp.Branch])]
    param ([string] $RepoRoot = (Get-Location).ProviderPath)

    process {
        $repo = Find-GitRepository -Path $RepoRoot -Verify
        if (-not $repo) {
            return
        }
        $repo.Head
    }
}