Functions/Find-HgUnmergedChangeset.ps1


function Find-HgUnmergedChangeset
{
    <#
    .SYNOPSIS
    Finds all the changesets that haven't been merged between a given branch and the current working directory.
     
    .DESCRIPTION
    The changesets are returned as objects.
     
    .EXAMPLE
     
    Find-HgUnmergedChangesets -Revision StableBranch
     
    Finds all the changesets that haven't been merged between `StableBranch` and the current working directory.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]
        [Alias('From')]
        # The name of the branch whose revisions are checked.
        $BranchName,
        
        [string]
        # The path to the repository. Defaults to the current directory.
        $RepoRoot = ((Get-Location).Path)
    )
    
    $rRepoRoot = Resolve-HgRoot $RepoRoot
    if( -not $rRepoRoot )
    {
        return
    }
    
    Push-Location $rRepoRoot
    try
    {
        if( -not (Test-HgBranch -Name $BranchName) )
        {
            Write-Error "Branch '$BranchName' not found."
            return
        }
        
        $currentBranch = Get-HgBranch -Current
        if( -not $currentBranch )
        {
            return
        }
        
        hg log -r ("ancestors(branch({0})) - ancestors(branch({1}))" -f $BranchName,$currentBranch.Name) --style $PsHgStylePath | Split-HgXml
    }
    finally
    {
        Pop-Location
    }
}

Set-Alias -Name 'Find-HgUnmergedChangesets' -Value 'Find-HgUnmergedChangeset'