Functions/Test-HgBookmark.ps1

function Test-HgBookmark
{
    <#
    .SYNOPSIS
    Tests if a bookmark exists.
     
    .DESCRIPTION
    Returns `$true` if the bookmark exists, or `$false` if it doesn't.
     
    .OUTPUTS
    System.Boolean.
     
    .EXAMPLE
    Test-HgBookmark 'NewHgBookmark'
     
    Demonstrates how to test if a bookmark exists.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]
        # The name of the bookmark to check.
        $Name,
        
        [Parameter()]
        [string]
        # The path to the repository where the bookmark is created. Defaults to the current directory.
        $RepoRoot = (Get-Location)
    )
    
    Set-StrictMode -Version 'Latest'
    
    $RepoRoot = Resolve-HgRoot -Path $RepoRoot

    if( -not $RepoRoot )
    {
        return
    }
    
    $bookmark = Get-HgBookmark -Name $Name -RepoRoot $RepoRoot |
                    Where-Object { $_.Name -eq $Name }
    if( $bookmark )
    {
        return $true
    }
    else
    {
        return $false
    }
    
}