Possible bug in revert commands -n option

Peter Williams pwil3058 at bigpond.net.au
Thu Mar 22 22:14:35 CDT 2007


Alexis S. L. Carvalho wrote:
> Thus spake Peter Williams:
>> With mercurial 0.9.3, this option only seems to work when used in 
>> conjunction with the --all option:
> 
> Actually it does work:
> 
> $ hg init a
> $ cd a
> $ echo foo > foo
> $ hg add foo
> $ hg ci -m 'add foo'
> $ echo bar >> foo
> $ hg diff
> diff -r 2f7910f0cd32 foo
> --- a/foo	Thu Mar 22 22:39:58 2007 -0300
> +++ b/foo	Thu Mar 22 22:40:03 2007 -0300
> @@ -1,1 +1,2 @@ foo
>  foo
> +bar
> $ hg revert -n foo  #does nothing. i.e. works fine
> $ hg diff
> diff -r 2f7910f0cd32 foo
> --- a/foo	Thu Mar 22 22:39:58 2007 -0300
> +++ b/foo	Thu Mar 22 22:40:03 2007 -0300
> @@ -1,1 +1,2 @@ foo
>  foo
> +bar
> $ hg revert foo     #reverts the change to foo
> $ hg diff
> $
> 
> What's probably confusing you is that "hg revert <filename>" doesn't
> print anything by default.

Yes.  This is the case.

> 
>> Personally, I would like -n to work without the --all option.  The 
>> reason for my preference is that I'm writing a GUI wrapper around hg 
>> (and other SCMs) specifically aimed at managing the working directory 
>> rather than the repository itself (which is what existing GUI tools 
>> provide).  Part of the functionality of the GUI is allowing the user to 
>> select files (in a file tree) and then invoke file related hg commands 
>> (add, copy, remove, rename, diff, revert) on them.  Where the command is 
>> one with likely irreversible consequences I like to pop up a 
>> "confirmation" dialog to give the user to change their mind.  The best 
>> way for me to tell the user what's about to happen with a "revert" is to 
>> get the output from a "-n" run to show them what the result will be.
> 
> Try --verbose to get the message.

The help message for revert make no mention of --verbose which is why I 
never tried it.  After your suggestion I eventually found the 
documentation for the universal options after a few tries. (The helpful 
message at the start of "hg help"'s output is usually not visible as it 
has scrolled off the terminal.  Repeating it at the end might be worth 
considering.)

> 
> Maybe we should print the messages by default with --dry-run...  But
> that would be inconsistent with the behaviour without --dry-run...

Consistency is important and now that I know about --verbose my needs 
are met so I'd say leave it like it is.  Maybe mention the issue in the FAQ?

> 
> Also note that revert saves the original files with a .orig suffix.
> 

I noticed that in the documentation and the --no-backup option.  By 
default, I won't be using the --no-backup option as it's safer not to 
but I'll still offer the confirmation dialog as undoing a revert using 
the .orig files can be painful.

Thanks for the quick and helpful response
Peter
-- 
Peter Williams                                   pwil3058 at bigpond.net.au

"Learning, n. The kind of ignorance distinguishing the studious."
  -- Ambrose Bierce


More information about the Mercurial-devel mailing list