Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 35704:41ef02ba329b
merge: add `--abort` flag which can abort the merge
Currently we don't have a good functionality to abort the merge and tell user to
do `hg update -C .` which can leads to different results if user missed the '.'
and moreover does not align with other abort functionalities like rebase, shelve
etc.
This patch adds `hg merge --abort` which will abort the ongoing merge and take
us back to the chagneset where we started from. Works in both cases when merge
resulted in conflicts and when there were no conflicts.
.. feature::
A `--abort` flag to merge command to abort the ongoing merge.
Differential Revision: https://phab.mercurial-scm.org/D1829
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 08 Jan 2018 19:41:47 +0530 |
parents | e925f33ac088 |
children | 7ffbd911dbc9 |
comparison
equal
deleted
inserted
replaced
35703:9a50ffd15b25 | 35704:41ef02ba329b |
---|---|
12 import hashlib | 12 import hashlib |
13 import os | 13 import os |
14 import shutil | 14 import shutil |
15 | 15 |
16 from .i18n import _ | 16 from .i18n import _ |
17 from .node import nullid | 17 from .node import ( |
18 hex, | |
19 nullid, | |
20 ) | |
18 | 21 |
19 from . import ( | 22 from . import ( |
20 bookmarks, | 23 bookmarks, |
21 bundlerepo, | 24 bundlerepo, |
22 cmdutil, | 25 cmdutil, |
842 if warndest: | 845 if warndest: |
843 destutil.statusotherdests(ui, repo) | 846 destutil.statusotherdests(ui, repo) |
844 | 847 |
845 return ret | 848 return ret |
846 | 849 |
847 def merge(repo, node, force=None, remind=True, mergeforce=False, labels=None): | 850 def merge(repo, node, force=None, remind=True, mergeforce=False, labels=None, |
851 abort=False): | |
848 """Branch merge with node, resolving changes. Return true if any | 852 """Branch merge with node, resolving changes. Return true if any |
849 unresolved conflicts.""" | 853 unresolved conflicts.""" |
850 stats = mergemod.update(repo, node, True, force, mergeforce=mergeforce, | 854 if not abort: |
851 labels=labels) | 855 stats = mergemod.update(repo, node, True, force, mergeforce=mergeforce, |
856 labels=labels) | |
857 else: | |
858 ms = mergemod.mergestate.read(repo) | |
859 if ms.active(): | |
860 # there were conflicts | |
861 node = hex(ms._local) | |
862 else: | |
863 # there were no conficts, mergestate was not stored | |
864 node = repo['.'].hex() | |
865 | |
866 repo.ui.status(_("aborting the merge, updating back to" | |
867 " %s\n") % node[:12]) | |
868 stats = mergemod.update(repo, node, branchmerge=False, force=True, | |
869 labels=labels) | |
870 | |
852 _showstats(repo, stats) | 871 _showstats(repo, stats) |
853 if stats[3]: | 872 if stats[3]: |
854 repo.ui.status(_("use 'hg resolve' to retry unresolved file merges " | 873 repo.ui.status(_("use 'hg resolve' to retry unresolved file merges " |
855 "or 'hg update -C .' to abandon\n")) | 874 "or 'hg merge --abort' to abandon\n")) |
856 elif remind: | 875 elif remind and not abort: |
857 repo.ui.status(_("(branch merge, don't forget to commit)\n")) | 876 repo.ui.status(_("(branch merge, don't forget to commit)\n")) |
858 return stats[3] > 0 | 877 return stats[3] > 0 |
859 | 878 |
860 def _incoming(displaychlist, subreporecurse, ui, repo, source, | 879 def _incoming(displaychlist, subreporecurse, ui, repo, source, |
861 opts, buffered=False): | 880 opts, buffered=False): |