Functions/Test-HgHead.ps1


function Test-HgHead
{
    <#
    .SYNOPSIS
    Tests if there are multiple heads in a repository or in a branch.
 
    .DESCRIPTION
    Returns `True` if a repository (or branch) contains multiple heads. `False` otherwise.
     
    ALIASES
      thgh
 
    .EXAMPLE
    Test-HgHeads
 
    Returns `True` if the repository in the current directory has multiple heads. `False` otherwise.
 
    .EXAMPLE
    Test-HgHeads -RepoRoot C:\Projects\PsHg -Revision stable
 
    Returns `True` if the `stable` branch in `C:\Projects\PsHg` has multiple heads. `False` otherwise.
    #>

    [CmdletBinding()]
    param(
        [string]
        # The revision whose branch should be tested for multiple heads.
        $Revision,
        
        [string]
        # The path to a repository.
        $RepoRoot = (Get-Location)
    )
    
    $rRepoRoot = Resolve-HgRoot -Path $RepoRoot
    if( -not $rRepoRoot )
    {
        return
    }
    
    $headsArgs = @()
    if( $Revision )
    {
        $headsArgs += $Revision
    }
    
    $heads = @( hg heads $headsArgs --template '{node}\n' -R $rRepoRoot )
    return ($heads.Length -gt 1)
}

Set-Alias -Name 'Test-HgHeads' -Value 'Test-HgHead'
Set-Alias -Name 'thgh' -Value 'Test-HgHead'