[PATCH 1 of 1] revert: improve hints on abort when reverting to parent without --all

Adrian Buehlmann adrian at cadifra.com
Sat Jun 25 19:02:40 CDT 2011


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1309043610 -7200
# Branch stable
# Node ID bd25f70c66eed696ef0798e8343f3f3bbb1de99b
# Parent  baebd3473490689891d9600d632830b471742105
revert: improve hints on abort when reverting to parent without --all

BEFORE:

    $ hg revert
    abort: no files or directories specified
    (use --all to discard all changes)

AFTER:

  Uncommitted changes (using --all *will* nuke edits):

    $ hg revert
    abort: no files or directories specified
    (uncommitted changes, use --all to discard all changes)

  Clean working directory (using --all won't discard anything):

    $ hg revert
    abort: no files or directories specified
    (use --all to revert all files)

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4184,17 +4184,22 @@
 
     if not pats and not opts.get('all'):
         msg = _("no files or directories specified")
-        hint = _("use --all to discard all changes")
         if p2 != nullid:
             hint = _("uncommitted merge, use --all to discard all changes,"
                      " or 'hg update -C .' to abort the merge")
-        elif node != parent:
-            if util.any(repo.status()):
+            raise util.Abort(msg, hint=hint)
+        dirty = util.any(repo.status())
+        if node != parent:
+            if dirty:
                 hint = _("uncommitted changes, use --all to discard all"
                          " changes, or 'hg update %s' to update") % ctx.rev()
             else:
                 hint = _("use --all to revert all files,"
                          " or 'hg update %s' to update") % ctx.rev()
+        elif dirty:
+            hint = _("uncommitted changes, use --all to discard all changes")
+        else:
+            hint = _("use --all to revert all files")
         raise util.Abort(msg, hint=hint)
 
     mf = ctx.manifest()
diff --git a/tests/test-revert.t b/tests/test-revert.t
--- a/tests/test-revert.t
+++ b/tests/test-revert.t
@@ -10,7 +10,7 @@
 
   $ hg revert
   abort: no files or directories specified
-  (use --all to discard all changes)
+  (use --all to revert all files)
   [255]
 
   $ echo 123 > b


More information about the Mercurial-devel mailing list