changeset 42579:b8d54f4625cb

merge: disallow merge abort in case of an unfinished operation (issue6160) This patch disallows `hg merge --abort` in case an operation of higher precedence i.e unshelve, rebase, histedit are in unfinished states. This is done so as to avoid partial abort of these operations in case merge abort is called at an interrupted step. The patch adds a `cmdutil.getunfinishedstate` function which checks for operations under progress and returns a `statecheck` object for it. Differential Revision: https://phab.mercurial-scm.org/D6607
author Taapas Agrawal <taapas2897@gmail.com>
date Tue, 09 Jul 2019 12:58:29 +0300
parents 9f73620a65fe
children eb7bd7d64a9d
files mercurial/cmdutil.py mercurial/commands.py relnotes/next tests/test-shelve2.t
diffstat 4 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Mon Jul 08 15:01:18 2019 -0700
+++ b/mercurial/cmdutil.py	Tue Jul 09 12:58:29 2019 +0300
@@ -3297,6 +3297,14 @@
         if s._clearable and s.isunfinished(repo):
             util.unlink(repo.vfs.join(s._fname))
 
+def getunfinishedstate(repo):
+    ''' Checks for unfinished operations and returns statecheck object
+        for it'''
+    for state in statemod._unfinishedstates:
+        if state.isunfinished(repo):
+            return state
+    return None
+
 def howtocontinue(repo):
     '''Check for an unfinished operation and return the command to finish
     it.
--- a/mercurial/commands.py	Mon Jul 08 15:01:18 2019 -0700
+++ b/mercurial/commands.py	Tue Jul 09 12:58:29 2019 +0300
@@ -3952,6 +3952,10 @@
     if abort and repo.dirstate.p2() == nullid:
         cmdutil.wrongtooltocontinue(repo, _('merge'))
     if abort:
+        state = cmdutil.getunfinishedstate(repo)
+        if state and state._opname != 'merge':
+            raise error.Abort(_('cannot abort merge with %s in progress') %
+                                (state._opname), hint=state.hint())
         if node:
             raise error.Abort(_("cannot specify a node with --abort"))
         if opts.get('rev'):
--- a/relnotes/next	Mon Jul 08 15:01:18 2019 -0700
+++ b/relnotes/next	Tue Jul 09 12:58:29 2019 +0300
@@ -81,6 +81,10 @@
 
  * `cmdutil.checkunfinished()` now includes detection for merge too.
 
+ * merge abort has been disallowed in case an operation of higher
+   precedence is in progress to avoid cases of partial abort of
+   operations.
+
  * We used to automatically attempt to make extensions compatible with
    Python 3 (by translating their source code while loading it). We no
    longer do that.
--- a/tests/test-shelve2.t	Mon Jul 08 15:01:18 2019 -0700
+++ b/tests/test-shelve2.t	Tue Jul 09 12:58:29 2019 +0300
@@ -847,3 +847,38 @@
 #endif
 
   $ cd ..
+
+Block merge abort when unshelve in progress(issue6160)
+------------------------------------------------------
+
+  $ hg init a
+  $ cd a
+  $ echo foo > a ; hg commit -qAm "initial commit"
+  $ echo bar > a
+  $ hg shelve
+  shelved as default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo foobar > a
+  $ hg unshelve
+  unshelving change 'default'
+  temporarily committing pending changes (restore with 'hg unshelve --abort')
+  rebasing shelved changes
+  merging a
+  warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
+  unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
+  [1]
+
+  $ hg log --template '{desc|firstline}  {author}  {date|isodate} \n' -r .
+  pending changes temporary commit  shelve@localhost  1970-01-01 00:00 +0000 
+  $ hg merge --abort
+  abort: cannot abort merge with unshelve in progress
+  (use 'hg unshelve --continue' or 'hg unshelve --abort')
+  [255]
+
+  $ hg unshelve --abort
+  unshelve of 'default' aborted
+
+  $ hg log -G --template '{desc|firstline}  {author}  {date|isodate} \n' -r .
+  @  initial commit  test  1970-01-01 00:00 +0000
+  
+  $ cd ..