changeset 35244:98f97eb20597

rewriteutil: use precheck() in uncommit and amend commands Differential Revision: https://phab.mercurial-scm.org/D1526
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 28 Nov 2017 05:50:45 +0530
parents 490df753894d
children 414114a7c18f
files hgext/uncommit.py mercurial/commands.py tests/test-amend.t tests/test-commit-amend.t tests/test-uncommit.t
diffstat 5 files changed, 7 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/uncommit.py	Fri Nov 24 03:44:50 2017 +0530
+++ b/hgext/uncommit.py	Tue Nov 28 05:50:45 2017 +0530
@@ -28,10 +28,10 @@
     copies,
     error,
     node,
-    obsolete,
     obsutil,
     pycompat,
     registrar,
+    rewriteutil,
     scmutil,
 )
 
@@ -155,23 +155,14 @@
     opts = pycompat.byteskwargs(opts)
 
     with repo.wlock(), repo.lock():
-        wctx = repo[None]
 
         if not pats and not repo.ui.configbool('experimental',
                                                 'uncommitondirtywdir'):
             cmdutil.bailifchanged(repo)
-        if wctx.parents()[0].node() == node.nullid:
-            raise error.Abort(_("cannot uncommit null changeset"))
-        if len(wctx.parents()) > 1:
-            raise error.Abort(_("cannot uncommit while merging"))
         old = repo['.']
-        if not old.mutable():
-            raise error.Abort(_('cannot uncommit public changesets'))
+        rewriteutil.precheck(repo, [old.rev()], 'uncommit')
         if len(old.parents()) > 1:
             raise error.Abort(_("cannot uncommit merge changeset"))
-        allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
-        if not allowunstable and old.children():
-            raise error.Abort(_('cannot uncommit changeset with children'))
 
         with repo.transaction('uncommit'):
             match = scmutil.match(old, pats, opts)
--- a/mercurial/commands.py	Fri Nov 24 03:44:50 2017 +0530
+++ b/mercurial/commands.py	Tue Nov 28 05:50:45 2017 +0530
@@ -49,6 +49,7 @@
     rcutil,
     registrar,
     revsetlang,
+    rewriteutil,
     scmutil,
     server,
     sshserver,
@@ -1541,13 +1542,7 @@
             raise error.Abort(_('cannot amend with ui.commitsubrepos enabled'))
 
         old = repo['.']
-        if not old.mutable():
-            raise error.Abort(_('cannot amend public changesets'))
-        if len(repo[None].parents()) > 1:
-            raise error.Abort(_('cannot amend while merging'))
-        allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt)
-        if not allowunstable and old.children():
-            raise error.Abort(_('cannot amend changeset with children'))
+        rewriteutil.precheck(repo, [old.rev()], 'amend')
 
         # Currently histedit gets confused if an amend happens while histedit
         # is in progress. Since we have a checkunfinished command, we are
--- a/tests/test-amend.t	Fri Nov 24 03:44:50 2017 +0530
+++ b/tests/test-amend.t	Tue Nov 28 05:50:45 2017 +0530
@@ -213,6 +213,7 @@
   $ hg update -C -q A
   $ hg amend -m AMEND
   abort: cannot amend public changesets
+  (see 'hg help phases' for details)
   [255]
 
 Amend a merge changeset
--- a/tests/test-commit-amend.t	Fri Nov 24 03:44:50 2017 +0530
+++ b/tests/test-commit-amend.t	Tue Nov 28 05:50:45 2017 +0530
@@ -16,6 +16,7 @@
   $ hg phase -r . -p
   $ hg ci --amend
   abort: cannot amend public changesets
+  (see 'hg help phases' for details)
   [255]
   $ hg phase -r . -f -d
 
--- a/tests/test-uncommit.t	Fri Nov 24 03:44:50 2017 +0530
+++ b/tests/test-uncommit.t	Tue Nov 28 05:50:45 2017 +0530
@@ -41,6 +41,7 @@
 
   $ hg uncommit
   abort: cannot uncommit null changeset
+  (no changeset checked out)
   [255]
 
 Create some commits