[PATCH 2 of 2] revert: print "nothing changed" warning and return 1 instead of aborting

Adrian Buehlmann adrian at cadifra.com
Fri Jun 24 16:46:19 CDT 2011


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1308951253 -7200
# Branch stable
# Node ID c0d82d5f78df21b8f6af714353e3e5cc3687e276
# Parent  82a960b76b4d8ebcfc997cf6e8caf77dde3a860f
revert: print "nothing changed" warning and return 1 instead of aborting

if
  - we do not have a pending merge
  - and we are reverting to the parent revision
  - and the working directory is clean

We're returning 1 as on commit if nothing is changed.

BEFORE:

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

AFTER:

  $ hg revert
  nothing changed

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4170,7 +4170,7 @@
 
     See :hg:`help dates` for a list of formats valid for -d/--date.
 
-    Returns 0 on success.
+    Returns 0 on success, 1 if nothing changed.
     """
 
     if opts.get("date"):
@@ -4184,18 +4184,24 @@
 
     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()
-        raise util.Abort(msg, hint=hint)
+            raise util.Abort(msg, hint=hint)
+        if dirty:
+            hint = _("use --all to discard all changes")
+            raise util.Abort(msg, hint=hint)
+        ui.warn(_("nothing changed\n"))
+        return 1
 
     mf = ctx.manifest()
     if node == parent:
diff --git a/tests/test-revert.t b/tests/test-revert.t
--- a/tests/test-revert.t
+++ b/tests/test-revert.t
@@ -9,9 +9,8 @@
 nothing changed
 
   $ hg revert
-  abort: no files or directories specified
-  (use --all to discard all changes)
-  [255]
+  nothing changed
+  [1]
 
   $ echo 123 > b
 


More information about the Mercurial-devel mailing list