Functions/Get-HgRepositoryName.ps1

function Get-HgRepositoryName
{
    <#
    .SYNOPSIS
    Gets the name of a Mercurial repository.
     
    .DESCRIPTION
    Really, it gets the name of the repository it came from, which is usually what you want.
     
    .EXAMPLE
    Get-HgRepositoryName
     
    Gets the name of the repository in the current directory.
     
    .EXAMPLE
    Get-HgRepositoryName -RepoRoot 'C:\Projects\PsHg'
     
    Gets the name of the repository in the `C:\Projects\PsHg` directory.
    #>

    [CmdletBinding()]
    param(
        [Parameter()]
        [string]
        # The path to the repository.
        $RepoRoot = (Get-Location)
    )
    
    Set-StrictMode -Version 'Latest'
    
    $path = Resolve-HgRoot $RepoRoot
    if( -not $path )
    {
        return
    }
    
    $defaultPath = Get-HgConfig -Name 'paths.default' -RepoRoot $path
    if( -not $defaultPath )
    {
        Write-Error ('Default path for repository ''{0}'' not found.' -f $path)
        return
    }
    
    return Split-Path -Leaf -Path $defaultPath
}