[PATCH] revert: mention update in hint of abort when reverting to non-parent

Adrian Buehlmann adrian at cadifra.com
Fri Jun 24 06:33:13 CDT 2011


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1308911849 -7200
# Branch stable
# Node ID dd301744d87ec041c40343944af5da137aa856ea
# Parent  b9faf94ee1969f41b89edfc4df809adad582ab4c
revert: mention update in hint of abort when reverting to non-parent

and explicitly warn about uncommitted changes

Examples:

BEFORE:

    $ hg par -q
    7:e81a2efd53d4
    $ hg revert -r 2
    abort: no files or directories specified
    (use --all to discard all changes)

AFTER:

  Clean working directory (revert can be easily undone, no edits to be lost):

    $ hg revert -r 2
    abort: no files or directories specified
    (use --all to revert all files, or 'hg update 2' to update)

  Uncommitted changes (revert --all *does* discard edits and is pretty hard to
  undo or even impossible if --no-backup is specified):

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

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4179,6 +4179,8 @@
         opts["rev"] = cmdutil.finddate(ui, repo, opts["date"])
 
     parent, p2 = repo.dirstate.parents()
+    ctx = scmutil.revsingle(repo, opts.get('rev'))
+    node = ctx.node()
 
     if not pats and not opts.get('all'):
         msg = _("no files or directories specified")
@@ -4186,10 +4188,15 @@
         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()):
+                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()
         raise util.Abort(msg, hint=hint)
 
-    ctx = scmutil.revsingle(repo, opts.get('rev'))
-    node = ctx.node()
     mf = ctx.manifest()
     if node == parent:
         pmf = mf
diff --git a/tests/test-revert.t b/tests/test-revert.t
--- a/tests/test-revert.t
+++ b/tests/test-revert.t
@@ -186,7 +186,7 @@
 
   $ hg revert -rtip
   abort: no files or directories specified
-  (use --all to discard all changes)
+  (use --all to revert all files, or 'hg update 1' to update)
   [255]
 
 should succeed


More information about the Mercurial-devel mailing list