Functions/Redo-HgMerge.ps1


function Redo-HgMerge
{
    <#
    .SYNOPSIS
    Re-merges all unresolved files in a Mercurial repository.
     
    .DESCRIPTION
    Runs Mercurial's `resolve` command to re-run merges that have unresolved conflicts.
     
    ALIASES
      rdhgmg
     
    .EXAMPLE
    Redo-HgMerge
     
    Re-merges all files in the current directory that have unresolved conflicts.
     
    .EXAMPLE
     
    Redo-HgMerge -MergeTool 'internal:local'
     
    Uses the `internal:local` tool and re-merges all files in the current directory that have unresolved conflicts.
     
    .LINK
    Merge-HgChangeset
     
    .LINK
    Get-HgConflict
    #>

    [CmdletBinding(SupportsShouldProcess=$true)]
    param(
        [string]
        # The merge tool to use.
        $MergeTool,
        
        [string]
        # The path to the repository's root directory. Defaults to the current directory.
        $RepoRoot = ((Get-Location).Path)
    )
    
    $rRepoRoot = Resolve-HgRoot
    if( -not $rRepoRoot )
    {
        return
    }
    
    $mergeToolArgName = ''
    $mergeToolArgValue = ''
    if( $MergeTool )
    {
        $mergeToolArgName = '--tool'
        $mergeToolArgValue = $MergeTool
    }
            
    hg resolve --all $mergeToolArgName $mergeToolArgValue
    if( $LastExitCode )
    {
        Write-Error 'Failed to resolve merge conflicts.'
    }

}

Set-Alias -Name 'hgresolve' -Value 'Redo-HgMerge'
Set-Alias -Name 'rdhgmg' -Value 'Redo-HgMerge'