--- a/mercurial/hg.py Thu Jan 04 21:37:03 2018 -0800
+++ b/mercurial/hg.py Mon Jan 08 19:41:47 2018 +0530
@@ -14,7 +14,10 @@
import shutil
from .i18n import _
-from .node import nullid
+from .node import (
+ hex,
+ nullid,
+)
from . import (
bookmarks,
@@ -844,16 +847,32 @@
return ret
-def merge(repo, node, force=None, remind=True, mergeforce=False, labels=None):
+def merge(repo, node, force=None, remind=True, mergeforce=False, labels=None,
+ abort=False):
"""Branch merge with node, resolving changes. Return true if any
unresolved conflicts."""
- stats = mergemod.update(repo, node, True, force, mergeforce=mergeforce,
- labels=labels)
+ if not abort:
+ stats = mergemod.update(repo, node, True, force, mergeforce=mergeforce,
+ labels=labels)
+ else:
+ ms = mergemod.mergestate.read(repo)
+ if ms.active():
+ # there were conflicts
+ node = hex(ms._local)
+ 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)
+
_showstats(repo, stats)
if stats[3]:
repo.ui.status(_("use 'hg resolve' to retry unresolved file merges "
- "or 'hg update -C .' to abandon\n"))
- elif remind:
+ "or 'hg merge --abort' to abandon\n"))
+ elif remind and not abort:
repo.ui.status(_("(branch merge, don't forget to commit)\n"))
return stats[3] > 0