# HG changeset patch # User Yuya Nishihara # Date 2018-07-11 12:35:31 # Node ID eba69ddd4e52f9ab12f1ea01177891d3169aa298 # Parent 0d0f8bd692c46aa4d1939500f9ec6d6ff886ec1a grep: search working directory files by default if --all-files is specified The default was -rtip:0 before, but "--all-files -rtip:0" would be the most useless combination, and it isn't supported yet. Let's change the default to something useful. This isn't flagged as BC since --all-files isn't released. Differential Revision: https://phab.mercurial-scm.org/D3917 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2535,6 +2535,8 @@ def grep(ui, repo, pattern, *pats, **opt diff = opts.get('all') or opts.get('diff') if diff and opts.get('all_files'): raise error.Abort(_('--diff and --all-files are mutually exclusive')) + if opts.get('all_files') and not opts.get('rev'): + opts['rev'] = ['wdir()'] reflags = re.M if opts.get('ignore_case'): diff --git a/tests/test-grep.t b/tests/test-grep.t --- a/tests/test-grep.t +++ b/tests/test-grep.t @@ -412,6 +412,18 @@ Test for showing working of allfiles fla $ hg grep -r "." "unmod" --all-files um:1:unmod +With --all-files, the working directory is searched by default + + $ echo modified >> new + $ hg grep --all-files mod + new:2147483647:modified + um:2147483647:unmod + + which can be overridden by -rREV + + $ hg grep --all-files -r. mod + um:1:unmod + --diff --all-files makes no sense since --diff is the option to grep history $ hg grep --diff --all-files um