grab: gracefully handle the case when we try to grab parent of wdir
authorPulkit Goyal <7895pulkit@gmail.com>
Tue, 13 Mar 2018 20:44:51 +0530
changeset 3527 7b4d1bfb6b7d
parent 3526 df20ddc79064
child 3528 92f1e2408fd0
grab: gracefully handle the case when we try to grab parent of wdir Before this patch, we go all the way down to obsmarker creation logic and gets an error saying that changeset cannot obsolete itself. We should be more smart here and error out early saying we cannot grab that changeset.
hgext3rd/evolve/cmdrewrite.py
tests/test-grab.t
--- a/hgext3rd/evolve/cmdrewrite.py	Sat Mar 03 23:31:46 2018 +0530
+++ b/hgext3rd/evolve/cmdrewrite.py	Tue Mar 13 20:44:51 2018 +0530
@@ -1187,7 +1187,7 @@
 
             origctx = repo[revs.first()]
 
-            if origctx in pctx.ancestors():
+            if origctx in pctx.ancestors() or origctx.node() == pctx.node():
                 raise error.Abort(_("cannot grab an ancestor revision"))
 
             rewriteutil.precheck(repo, [origctx.rev()], 'grab')
--- a/tests/test-grab.t	Sat Mar 03 23:31:46 2018 +0530
+++ b/tests/test-grab.t	Tue Mar 13 20:44:51 2018 +0530
@@ -47,6 +47,12 @@
   abort: cannot grab an ancestor revision
   [255]
 
+Grabbing the working directory parent
+
+  $ hg grab -r .
+  abort: cannot grab an ancestor revision
+  [255]
+
 Specifying multiple revisions to grab
 
   $ hg grab 1f0dee641bb7 -r 7c3bad9141dc