Bug 5789 - interactive revert passes on nonexistant file patterns
Summary: interactive revert passes on nonexistant file patterns
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: PC Linux
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-12 02:29 UTC by Denis Laxalde
Modified: 2018-02-23 00:00 UTC (History)
2 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Denis Laxalde 2018-02-12 02:29 UTC
When passed a file pattern that does not match any file in the repository, "hg revert -i" just warns about it but then continues and asks about other modified files. This is different from the non-interactive case. I believe the command should just abort if none of specified file patterns exist (in which case, the user quite just likely made a typo). 

Step to reproduce:

  $ hg files
  a
  $ hg status
  A a
  $ hg rev b
  b: no such file in rev 000000000000
  $ hg rev -i b
  b: no such file in rev 000000000000
  diff --git a/a b/a
  new file mode 100644
  examine changes to 'a'? [Ynesfdaq?]
Comment 1 HG Bot 2018-02-15 18:35 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/a228b2f55ad6
Denis Laxalde <denis@laxalde.org>
tests: add a test demonstrate that 'revert -i' ignores nonexistent patterns

As described in issue5789, when revert is called through:

  hg revert -i <some file that does not exist>

we'd expect the command to abort early. Currently, it just warns about
missing file but prompt about files unrelated to user arguments.

(please test the fix)
Comment 2 HG Bot 2018-02-15 18:36 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/39b3aab6231e
Denis Laxalde <denis.laxalde@logilab.fr>
revert: use an exact matcher in interactive diff selection (issue5789)

When going through _performrevert() in the interactive case, we build a
matcher with files to revert and pass it patch.diff() for later
selection of diff hunks to revert. The files set used to build the
matcher comes from dirstate and accounts for patterns explicitly passed
to revert ('hg revert -i <file>') and, in case of nonexistent pattern,
this set is empty (which is expected). Unfortunately, the matcher built
from scmutil.match(ctx, []) is wrong as it leads patch.diff() to rebuild
a 'changes' tuple with dirstate information, ignoring user-specified
pattern. This leads to the situation described in issue5789, where
one gets prompted about reverting files unrelated to specified patterns
because they made a typo or so.

We fix this by building an exact matcher with the correct set of file
paths (built earlier). Thanks to Yuya Nishihara for suggesting the
correct fix.

(please test the fix)
Comment 3 Bugzilla 2018-02-23 00:00 UTC
Bug was set to TESTING for 7 days, resolving