[PATCH 1 of 1 V5] revert: improve hint on abort if no files were specified
Adrian Buehlmann
adrian at cadifra.com
Fri Jun 17 11:56:42 UTC 2011
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1308220115 -7200
# Node ID 123f9a41a8a6d8a4b736af89cb7e437cc0cf4500
# Parent e21fd445c297dfff9c709380e09be58f23108a36
revert: improve hint on abort if no files were specified
and provide some additional status info in two notable cases as a friendly
reminder for the user (please see the examples below)
uncommitted merge:
BEFORE:
$ hg revert
abort: no files or directories specified
(use --all to revert all files)
NEW:
$ hg revert
uncommitted merge
abort: no files or directories specified
(use --all to discard all changes you might have made)
uncommitted changes, revert to non-parent (most complex use case):
BEFORE:
$ hg revert -d 2011-05-05
Found revision 7423 from Thu May 05 19:56:05 2011 +0200
abort: no files or directories specified
(use --all to revert all files)
NEW:
$ hg revert -d 2011-05-05
Found revision 7423 from Thu May 05 19:56:05 2011 +0200
uncommitted changes
abort: no files or directories specified
(use --all to discard all changes, or 'hg update -r 7423' to update)
clean, revert to non-parent:
BEFORE:
$ hg revert -d 2011-05-05
Found revision 7423 from Thu May 05 19:56:05 2011 +0200
abort: no files or directories specified
(use --all to revert all files)
NEW:
$ hg revert -d 2011-05-05
Found revision 7423 from Thu May 05 19:56:05 2011 +0200
abort: no files or directories specified
(use --all to revert all files, or 'hg update -r 7423' to update)
uncommitted changes:
BEFORE:
$ hg revert
abort: no files or directories specified
(use --all to revert all files)
NEW:
$ hg revert
abort: no files or directories specified
(use --all to discard all changes)
nothing changed:
BEFORE:
$ hg revert
abort: no files or directories specified
(use --all to revert all files)
NEW:
$ hg revert
nothing changed
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4181,10 +4181,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()
@@ -4193,6 +4189,27 @@
else:
pmf = None
+ if not pats and not opts.get('all'):
+ msg = _("no files or directories specified")
+ if p2 != nullid:
+ ui.status(_("uncommitted merge\n"))
+ hint = _("use --all to discard all changes you might have made")
+ raise util.Abort(msg, hint=hint)
+ dirty = util.any(repo.status())
+ if node != parent:
+ if dirty:
+ ui.status(_("uncommitted changes\n"))
+ hint = _("use --all to discard all changes,"
+ " or 'hg update -r %s' to update") % ctx.rev()
+ else:
+ hint = _("use --all to revert all files,"
+ " or 'hg update -r %s' to update") % ctx.rev()
+ raise util.Abort(msg, hint=hint)
+ elif dirty:
+ hint = _("use --all to discard all 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,9 @@
Revert should fail:
$ hg revert
+ uncommitted merge
abort: no files or directories specified
- (use --all to revert all files)
+ (use --all to discard all changes you might have made)
[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
@@ -186,7 +186,7 @@
$ hg revert -rtip
abort: no files or directories specified
- (use --all to revert all files)
+ (use --all to revert all files, or 'hg update -r 1' to update)
[255]
should succeed
More information about the Mercurial-devel
mailing list