diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -4104,6 +4104,14 @@ return hg.merge(repo, node, force=force, mergeforce=force, labels=labels, abort=abort) +statemod.addunfinished( + 'merge', fname=None, clearable=True, allowcommit=True, + cmdmsg=_('outstanding uncommitted merge'), abortfunc=hg.abortmerge, + statushint=_('To continue: hg commit\n' + 'To abort: hg merge --abort'), + cmdhint=_("use 'hg commit' or 'hg merge --abort'") +) + @command('outgoing|out', [('f', 'force', None, _('run even when the destination is unrelated')), ('r', 'rev', [], diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -960,18 +960,8 @@ stats = mergemod.update(repo, node, branchmerge=True, force=force, mergeforce=mergeforce, labels=labels) else: - ms = mergemod.mergestate.read(repo) - if ms.active(): - # there were conflicts - node = ms.localctx.hex() - else: - # there were no conficts, mergestate was not stored - node = repo['.'].hex() - - repo.ui.status(_("aborting the merge, updating back to" - " %s\n") % node[:12]) - stats = mergemod.update(repo, node, branchmerge=False, force=True, - labels=labels) + ui = repo.ui + stats = abortmerge(ui, repo, labels=labels, asflag=True) _showstats(repo, stats) if stats.unresolvedcount: @@ -981,6 +971,23 @@ repo.ui.status(_("(branch merge, don't forget to commit)\n")) return stats.unresolvedcount > 0 +def abortmerge(ui, repo, labels=None, asflag=False): + ms = mergemod.mergestate.read(repo) + if ms.active(): + # there were conflicts + node = ms.localctx.hex() + else: + # there were no conficts, mergestate was not stored + node = repo['.'].hex() + + repo.ui.status(_("aborting the merge, updating back to" + " %s\n") % node[:12]) + stats = mergemod.update(repo, node, branchmerge=False, force=True, + labels=labels) + if asflag: + return stats + _showstats(repo, stats) + def _incoming(displaychlist, subreporecurse, ui, repo, source, opts, buffered=False): """ diff --git a/mercurial/state.py b/mercurial/state.py --- a/mercurial/state.py +++ b/mercurial/state.py @@ -205,13 +205,6 @@ 'To mark the changeset bad: hg bisect --bad\n' 'To abort: hg bisect --reset\n') ) -addunfinished( - 'merge', fname=None, clearable=True, allowcommit=True, - cmdmsg=_('outstanding uncommitted merge'), - statushint=_('To continue: hg commit\n' - 'To abort: hg merge --abort'), - cmdhint=_("use 'hg commit' or 'hg merge --abort'") -) def getrepostate(repo): # experimental config: commands.status.skipstates diff --git a/tests/test-abort.t b/tests/test-abort.t --- a/tests/test-abort.t +++ b/tests/test-abort.t @@ -661,9 +661,8 @@ Unshelve abort fails with appropriate message if there's no unshelve in progress $ hg abort - abort: merge does not support 'hg abort' - (use 'hg commit' or 'hg merge --abort') - [255] + aborting the merge, updating back to 9451eaa6eee3 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd .. Abort due to pending changes @@ -978,3 +977,75 @@ $ hg abort abort: no operation in progress [255] + $ cd .. + +####TEST `hg abort` operation merge + + $ addcommit () { + > echo $1 > $1 + > hg add $1 + > hg commit -d "${2} 0" -m $1 + > } + + $ commit () { + > hg commit -d "${2} 0" -m $1 + > } + + $ hg init a + $ cd a + $ addcommit "A" 0 + $ addcommit "B" 1 + $ echo "C" >> A + $ commit "C" 2 + + $ hg update -C 0 + 1 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ echo "D" >> A + $ commit "D" 3 + created new head + +State before the merge + + $ hg status + $ hg id + e45016d2b3d3 tip + $ hg summary + parent: 3:e45016d2b3d3 tip + D + branch: default + commit: (clean) + update: 2 new changesets, 2 branch heads (merge) + phases: 4 draft + +Testing the abort functionality first in case of conflicts + + $ hg abort + abort: no operation in progress + [255] + $ hg merge + merging A + warning: conflicts while merging A! (edit, then use 'hg resolve --mark') + 1 files updated, 0 files merged, 0 files removed, 1 files unresolved + use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon + [1] + +when in dry-run mode + $ hg abort --dry-run + abort: aborting merge + [255] + +when in no-backup mode + $ hg abort --no-backup + abort: merge does not support no-backup + [255] + +when dry-run mode is used with no backup + $ hg abort --dry-run --no-backup + abort: merge does not support no-backup + [255] + +normal abort + $ hg abort + aborting the merge, updating back to e45016d2b3d3 + 1 files updated, 0 files merged, 1 files removed, 0 files unresolved +