[PATCH 1 of 1 V3] revert: improve abort messages if --all is not specified

Adrian Buehlmann adrian at cadifra.com
Tue Jun 14 13:12:23 CDT 2011


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1308074809 -7200
# Node ID 2ca10d93b81f4d87bceae22ed0904030960a45c4
# Parent  4aef71839337c5548eba07f6e76d9b002d31ad70
revert: improve abort messages if --all is not specified

We now provide tailored abort messages, depending on the situation.

uncommitted merge:

  $ hg revert
  abort: uncommitted merge
  (use 'hg update -C .' to cancel the merge and lose all your changes)

uncommitted changes:

  $ hg revert
  abort: uncommitted changes
  (use --all to lose all your changes)

uncommitted changes, revert to non-parent:

  $ hg revert -r 2
  abort: revert to 946c41063461 modifies all files to match that revision
  (use update, or --all to lose all your changes)

clean, revert to non-parent:

  $ hg revert -r 2
  abort: revert to 946c41063461 modifies all files to match that revision
  (use update, or --all to force)

nothing changed:

  $ hg revert
  nothing changed

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4125,10 +4125,6 @@
 
     parent, p2 = repo.dirstate.parents()
 
-    if not pats and not opts.get('all'):
-        raise util.Abort(_('no files or directories specified'),
-                         hint=_('use --all to revert all files'))
-
     ctx = scmutil.revsingle(repo, opts.get('rev'))
     node = ctx.node()
     mf = ctx.manifest()
@@ -4137,6 +4133,27 @@
     else:
         pmf = None
 
+    if not pats and not opts.get('all'):
+        if p2 != nullid:
+            msg = _("uncommitted merge")
+            hint = _("use 'hg update -C .' to cancel the merge and lose"
+                     " all your changes")
+            raise util.Abort(msg, hint=hint)
+        dirty = util.any(repo.status())
+        if node != parent:
+            msg = (_("revert to %s modifies all files to match"
+                     " that revision") % short(node))
+            if dirty:
+                hint = _("use update, or --all to lose all your changes")
+            else:
+                hint = _("use update, or --all to force")
+            raise util.Abort(msg, hint=hint)
+        if dirty:
+            msg = _("uncommitted changes")
+            hint = _("use --all to lose all your changes")
+            raise util.Abort(msg, hint=hint)
+        ui.status(_("nothing changed\n"))
+
     # need all matching names in dirstate and manifest of target rev,
     # so have to walk both. do not print errors if files exist in one
     # but not other.
diff --git a/tests/test-confused-revert.t b/tests/test-confused-revert.t
--- a/tests/test-confused-revert.t
+++ b/tests/test-confused-revert.t
@@ -59,8 +59,8 @@
 Revert should fail:
 
   $ hg revert
-  abort: no files or directories specified
-  (use --all to revert all files)
+  abort: uncommitted merge
+  (use 'hg update -C .' to cancel the merge and lose all your changes)
   [255]
 
 Revert should be ok now:
diff --git a/tests/test-revert.t b/tests/test-revert.t
--- a/tests/test-revert.t
+++ b/tests/test-revert.t
@@ -185,8 +185,8 @@
 should fail - no arguments
 
   $ hg revert -rtip
-  abort: no files or directories specified
-  (use --all to revert all files)
+  abort: revert to e9b9a7718906 modifies all files to match that revision
+  (use update, or --all to force)
   [255]
 
 should succeed


More information about the Mercurial-devel mailing list