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)
--- a/mercurial/commands.py Fri Jun 24 10:51:05 2011 +0200
+++ b/mercurial/commands.py Fri Jun 24 12:37:29 2011 +0200
@@ -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
--- a/tests/test-revert.t Fri Jun 24 10:51:05 2011 +0200
+++ b/tests/test-revert.t Fri Jun 24 12:37:29 2011 +0200
@@ -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