revert: improve hints on abort when reverting to parent without --all stable
authorAdrian Buehlmann <adrian@cadifra.com>
Sun, 26 Jun 2011 01:13:30 +0200
branchstable
changeset 14755 6ba51c81ff75
parent 14754 189a7562d72e
child 14756 fdcf6f09b68d
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)
mercurial/commands.py
tests/test-revert.t
--- a/mercurial/commands.py	Fri Jun 24 19:44:59 2011 +0300
+++ b/mercurial/commands.py	Sun Jun 26 01:13:30 2011 +0200
@@ -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()
--- a/tests/test-revert.t	Fri Jun 24 19:44:59 2011 +0300
+++ b/tests/test-revert.t	Sun Jun 26 01:13:30 2011 +0200
@@ -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