Functions/Get-HgIncomingChangeset.ps1


function Get-HgIncomingChangeset
{
    <#
    .SYNOPSIS
    Gets all the incoming changesets for the current directory's repository.
     
    .DESCRIPTION
    Returns objects representing the incomingchanges.
     
    ALIASES
      ghginc, hgin
     
    .EXAMPLE
    Read-HgIncomingChangesets
     
    Returns objects representing the changesets that haven't been pulled.
 
    .EXAMPLE
    Read-HgIncomingChangesets -Path C:\Projects\psHg
 
    Returns objects for any incoming changesets for the C:\Projects\psHg repository.
    #>

    [CmdletBinding()]
    [OutputType([PsHg.ChangesetInfo])]
    param(
        [Parameter()]
        [string]
        # The revision whose changes to return. This is typically a branch name.
        $Revision,

        [string]
        # Specifies an explicit repository
        $Source,

        [string]
        [Alias('Path')]
        $RepoRoot = (Resolve-Path .),

        [Switch]
        # Get full changeset information that is slow to compute: file adds, file modifications, file deletes, etc.
        $Force
    )

    Set-StrictMode -Version 'Latest'
    
    $rRepoRoot = Resolve-HgRoot -Path $RepoRoot
    if( -not $rRepoRoot )
    {
        return
    }
    
    $revisionArg = ''
    if( $Revision )
    {
        $revisionArg = '-r{0}' -f $Revision
    }
    
    $verboseOrDebugArg = '--verbose'
    if( $Force )
    {
        $verboseOrDebugArg = '--debug'
    }

    Push-Location $rRepoRoot
    try
    {
        if( -not $Source -and -not (Test-HgDefaultPath -Incoming) )
        {
            Write-Error -Message ('Repository {0}''s default path setting not found.' -f $rRepoRoot) `
                        -RecommendedAction ('Add setting paths.default to {0}.' -f (Join-Path $rRepoRoot .hg\hgrc)) `
                        -Category InvalidOperation
            return
        }
        
        hg in --style $PsHgStylePath $revisionArg -R $rRepoRoot $Source $verboseOrDebugArg | 
            Split-HgXml
    }
    finally
    {
        Pop-Location
    }
}

Set-Alias -Name 'Read-HgIncomingChangesets' -Value 'Get-HgIncomingChangeset'
Set-Alias -Name 'hgin' -Value 'Get-HgIncomingChangeset'
Set-Alias -Name 'ghginc' -Value 'Get-HgIncomingChangeset'