[PATCH STABLE] revert: improve hints on abort with no files specified
Kevin Bullock
kbullock+mercurial at ringworld.org
Fri Jun 24 13:03:30 CDT 2011
On 24 Jun 2011, at 1:01 PM, Kevin Bullock wrote:
> # HG changeset patch
> # User Kevin Bullock <kbullock at ringworld.org>
> # Date 1308626766 18000
> # Branch stable
> # Node ID 50e33684a46172574479e31808c8131cb7b80209
> # Parent b9faf94ee1969f41b89edfc4df809adad582ab4c
> revert: suggest update on revert to non-parent
Whoops, nevermind, just saw that Adrian already sent another version of this.
pacem in terris / mir / shanti / salaam / heiwa
Kevin R. Bullock
>
> uncommitted changes, revert to non-parent:
>
> BEFORE:
> $ hg revert -d 2011-05-05
> Found revision 14208 from Thu May 05 18:05:24 2011 +0200
> abort: no files or directories specified
> (use --all to discard all changes)
>
> AFTER (clean):
> $ hg revert -d 2011-05-05
> Found revision 14208 from Thu May 05 18:05:24 2011 +0200
> abort: no files or directories specified
> (use --all to revert all files, or 'hg update 14208' to check out that revision)
>
> AFTER (uncommitted changes):
> $ hg revert -d 2011-05-05
> Found revision 14208 from Thu May 05 18:05:24 2011 +0200
> abort: no files or directories specified
> (use --all to discard all changes, or 'hg update 14208' to check out that revision)
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -4180,16 +4180,28 @@
>
> 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")
> 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")
> + raise util.Abort(msg, hint=hint)
> + dirty = util.any(repo.status())
> + if node != parent:
> + if dirty:
> + hint = _('use --all to discard all changes, or '
> + "'hg update %s' to check out that revision"
> + ) % ctx.rev()
> + else:
> + hint = _('use --all to revert all files, or '
> + "'hg update %s' to check out that revision"
> + ) % 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 check out that revision)
> [255]
>
> should succeed
More information about the Mercurial-devel
mailing list