changeset 4798:2e14a9386316

abort: added support for evolve to hg abort This patch adds support of `hg evolve --abort` to `hg abort` plan. This involves creating a `hgabortevolve()` function under `evolvecmd` which ensures abortion of evolve via `hg abort`. This function is then registered using `addunfinished()` in `__init__.py`. Results are shown as tests.
author Taapas Agrawal <taapas2897@gmail.com>
date Thu, 11 Jul 2019 22:56:46 +0530
parents 8c780c3eb116
children 6f9e66433ff8
files hgext3rd/evolve/__init__.py hgext3rd/evolve/evolvecmd.py tests/test-evolve-abort-orphan.t tests/test-evolve-abort-phasediv.t
diffstat 4 files changed, 54 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py	Fri Jul 12 23:43:25 2019 +0530
+++ b/hgext3rd/evolve/__init__.py	Thu Jul 11 22:56:46 2019 +0530
@@ -1362,7 +1362,8 @@
                  '(also see `hg help evolve.interrupted`)')
         statemod.addunfinished('evolve', fname='evolvestate',
                                continueflag=True, stopflag=True,
-                               statushint=_msg)
+                               statushint=_msg,
+                               abortfunc=evolvecmd.hgabortevolve)
         statemod.addunfinished('pick', fname='pickstate', continueflag=True)
     else:
         # compat <= hg-5.0 (5f2f6912c9e6)
--- a/hgext3rd/evolve/evolvecmd.py	Fri Jul 12 23:43:25 2019 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Thu Jul 11 22:56:46 2019 +0530
@@ -1912,6 +1912,21 @@
         raise error.Abort(_("unable to abort interrupted evolve, use 'hg "
                             "evolve --stop' to stop evolve"))
 
+def hgabortevolve(ui, repo):
+    """logic for aborting evolve using 'hg abort'"""
+    with repo.wlock(), repo.lock():
+        evolvestate = state.cmdstate(repo)
+        evolvestate.load()
+        if evolvestate['command'] != 'evolve':
+            pctx = repo['.']
+            hg.updaterepo(repo, pctx.node(), True)
+            ui.status(_('evolve aborted\n'))
+            ui.status(_('working directory is now at %s\n')
+                      % pctx.hex()[:12])
+            evolvestate.delete()
+            return 0
+        return abortevolve(ui, repo, evolvestate)
+
 def continueevolve(ui, repo, evolvestate):
     """logic for handling of `hg evolve --continue`"""
 
--- a/tests/test-evolve-abort-orphan.t	Fri Jul 12 23:43:25 2019 +0530
+++ b/tests/test-evolve-abort-orphan.t	Thu Jul 11 22:56:46 2019 +0530
@@ -10,6 +10,7 @@
 Setup
 =====
 
+#testcases abortcommand abortflag
   $ cat >> $HGRCPATH <<EOF
   > [phases]
   > publish = False
@@ -19,6 +20,13 @@
   > EOF
   $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
 
+#if abortflag
+  $ cat >> $HGRCPATH <<EOF
+  > [alias]
+  > abort = evolve --abort
+  > EOF
+#endif
+
   $ hg init abortrepo
   $ cd abortrepo
   $ echo ".*\.orig" > .hgignore
@@ -41,9 +49,15 @@
 Testing --abort when no evolve is interrupted
 =============================================
 
+#if abortflag
   $ hg evolve --abort
   abort: no interrupted evolve to abort
   [255]
+#else
+  $ hg abort
+  abort: no operation in progress
+  [255]
+#endif
 
 Testing with wrong combination of flags
 =======================================
@@ -103,8 +117,13 @@
   instability: orphan
   summary:     added d
   
+#if abortcommand
+when in dry-run mode
+  $ hg abort --dry-run
+  evolve in progress, will be aborted
+#endif
 
-  $ hg evolve --abort
+  $ hg abort
   evolve aborted
   working directory is now at e93a9161a274
 
@@ -199,7 +218,7 @@
   o  0:8fa14d15e168 added hgignore
       () draft
 
-  $ hg evolve --abort
+  $ hg abort
   1 new orphan changesets
   evolve aborted
   working directory is now at 125af0ed8cae
@@ -299,7 +318,7 @@
   o  0:8fa14d15e168 added hgignore
       () draft
 
-  $ hg evolve --abort
+  $ hg abort
   2 new orphan changesets
   evolve aborted
   working directory is now at 807e8e2ca559
@@ -395,7 +414,7 @@
   adding file changes
   added 1 changesets with 1 changes to 1 files
   $ cd ../repotwo
-  $ hg evolve --abort
+  $ hg abort
   warning: new changesets detected on destination branch
   abort: unable to abort interrupted evolve, use 'hg evolve --stop' to stop evolve
   [255]
@@ -442,7 +461,7 @@
 
   $ hg phase -r 1c476940790a --public
 
-  $ hg evolve --abort
+  $ hg abort
   cannot clean up public changesets: 1c476940790a
   abort: unable to abort interrupted evolve, use 'hg evolve --stop' to stop evolve
   [255]
@@ -510,7 +529,7 @@
   o  0:8fa14d15e168 added hgignore
       () draft
 
-  $ hg evolve --abort
+  $ hg abort
   1 new orphan changesets
   evolve aborted
   working directory is now at a0086c17bfc7
@@ -543,7 +562,7 @@
   (see 'hg help evolve.interrupted')
   [1]
 
-  $ hg evolve --abort
+  $ hg abort
   evolve aborted
   working directory is now at c1f4718020e3
 
--- a/tests/test-evolve-abort-phasediv.t	Fri Jul 12 23:43:25 2019 +0530
+++ b/tests/test-evolve-abort-phasediv.t	Thu Jul 11 22:56:46 2019 +0530
@@ -10,6 +10,7 @@
 Setup
 =====
 
+#testcases abortcommand abortflag
   $ cat >> $HGRCPATH <<EOF
   > [phases]
   > publish = False
@@ -19,6 +20,13 @@
   > EOF
   $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
 
+#if abortflag
+  $ cat >> $HGRCPATH <<EOF
+  > [alias]
+  > abort = evolve --abort
+  > EOF
+#endif
+
   $ hg init abortrepo
   $ cd abortrepo
   $ echo ".*\.orig" > .hgignore
@@ -124,7 +132,7 @@
   summary:     added d
   
 
-  $ hg evolve --abort
+  $ hg abort
   evolve aborted
   working directory is now at ddba58020bc0
 
@@ -218,7 +226,7 @@
   (see 'hg help evolve.interrupted')
   [1]
 
-  $ hg evolve --abort
+  $ hg abort
   1 new phase-divergent changesets
   evolve aborted
   working directory is now at 28cd06b3f801
@@ -304,7 +312,7 @@
   (see 'hg help evolve.interrupted')
   [1]
 
-  $ hg evolve --abort
+  $ hg abort
   1 new phase-divergent changesets
   evolve aborted
   working directory is now at ef9b72b9b42c