grab: move the initialization of pctx variable outside of if-else
authorPulkit Goyal <7895pulkit@gmail.com>
Sat, 03 Mar 2018 23:31:46 +0530
changeset 3526 df20ddc79064
parent 3525 300d7d019b98
child 3527 7b4d1bfb6b7d
grab: move the initialization of pctx variable outside of if-else The pctx variable is used outside of the if-else but it was initialized under the conditional statements. Added test for the case when the initialization inside the if-else broke `hg grab --continue`.
hgext3rd/evolve/cmdrewrite.py
tests/test-grab.t
--- a/hgext3rd/evolve/cmdrewrite.py	Wed Mar 14 02:32:08 2018 +0100
+++ b/hgext3rd/evolve/cmdrewrite.py	Sat Mar 03 23:31:46 2018 +0530
@@ -1175,6 +1175,7 @@
 
     with repo.wlock(), repo.lock(), repo.transaction('grab'):
         grabstate = state.cmdstate(repo, path='grabstate')
+        pctx = repo['.']
 
         if not cont and not abort:
             cmdutil.bailifchanged(repo)
@@ -1185,7 +1186,6 @@
                 raise error.Abort(_("empty revision set"))
 
             origctx = repo[revs.first()]
-            pctx = repo['.']
 
             if origctx in pctx.ancestors():
                 raise error.Abort(_("cannot grab an ancestor revision"))
--- a/tests/test-grab.t	Wed Mar 14 02:32:08 2018 +0100
+++ b/tests/test-grab.t	Sat Mar 03 23:31:46 2018 +0530
@@ -181,12 +181,39 @@
   |
   o  0:1f0dee641bb7 add a
   
+
+When interrupted grab results in no changes to commit
+
+  $ hg up d46dc301d92f
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo bar > c
+  $ hg add c
+  $ hg ci -m "foo to c"
+  created new head
+
+  $ hg up 44e155eb95c7
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg grab 4e04628911f6
+  grabbing 9:4e04628911f6 "foo to c"
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  unresolved merge conflicts (see hg help resolve)
+  [1]
+  $ echo foobar > c
+  $ hg resolve -m
+  (no more unresolved files)
+  continue: hg grab --continue
+
+  $ hg grab --continue
+  note: grab of 9:4e04628911f6 created no changes to commit
+
 Testing the abort functionality of hg grab
 
   $ echo foo > b
   $ hg ci -Aqm "foo to b"
   $ hg glog -r .^::
-  @  9:902d4f4602bb foo to b
+  @  10:c437988de89f foo to b
   |
   o  8:44e155eb95c7 add c
   |
@@ -200,10 +227,10 @@
   [1]
 
   $ hg grab --abort
-  aborting grab, updating to 902d4f4602bb
+  aborting grab, updating to c437988de89f
 
   $ hg glog
-  @  9:902d4f4602bb foo to b
+  @  10:c437988de89f foo to b
   |
   o  8:44e155eb95c7 add c
   |
@@ -228,7 +255,7 @@
   [255]
 
   $ hg glog
-  @  9:902d4f4602bb foo to b
+  @  10:c437988de89f foo to b
   |
   o  8:44e155eb95c7 add c
   |
@@ -262,7 +289,7 @@
 
   $ hg grab --continue
   $ hg phase -r .
-  10: secret
+  11: secret
 
 No merge conflicts
 
@@ -273,14 +300,14 @@
   $ hg ci -qm "added l" --secret
 
   $ hg phase -r .
-  11: secret
+  12: secret
 
   $ hg glog
-  @  11:508d572e7053 added l
+  @  12:508d572e7053 added l
   |
-  | o  10:cd90ed194449 add b
+  | o  11:10427de9e26e add b
   | |
-  | o  9:902d4f4602bb foo to b
+  | o  10:c437988de89f foo to b
   | |
   | o  8:44e155eb95c7 add c
   | |
@@ -292,11 +319,11 @@
   |
   o  0:1f0dee641bb7 add a
   
-  $ hg up cd90ed194449
+  $ hg up 10427de9e26e
   3 files updated, 0 files merged, 1 files removed, 0 files unresolved
 
   $ hg grab -r 508d572e7053
-  grabbing 11:508d572e7053 "added l"
+  grabbing 12:508d572e7053 "added l"
 
   $ hg phase -r .
-  12: secret
+  13: secret