Functions/Get-HgVersion.ps1


function Get-HgVersion
{
    <#
    .SYNOPSIS
    Gets the version of the hg.exe binary installed on this computer.
     
    .DESCRIPTION
    The version is returned as a System.Version object
     
    ALIASES
      ghgv
       
    .EXAMPLE
    > Get-HgVersion
     
    Major Minor Build Revision
    ----- ----- ----- --------
    2 1 1 -1
 
    Mercurial 2.1.1 is installed, so a System.Version object is returned which represents that version.
    #>

    [CmdletBinding()]
    param()
    
    $version = hg version | Select-Object -First 1
    if( $version -notmatch '\(version (.*?)\)' )
    {
        Write-Error "Unable to find the version of Mercurial."
        return
    }
    [Version] $matches[1]
}

Set-Alias -Name 'hgversion' -Value 'Get-HgVersion'
Set-Alias -Name 'ghgv' -Value 'Get-HgVersion'