D3916: grep: reject --diff --all-files

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Wed Jul 11 14:16:34 UTC 2018


yuja created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This combination doesn't make any sense since --diff is the flag to search
  change history, whereas --all-files is to include unmodified contents.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3916

AFFECTED FILES
  mercurial/commands.py
  tests/test-grep.t

CHANGE DETAILS

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,12 @@
   $ hg grep -r "." "unmod" --all-files
   um:1:unmod
 
+--diff --all-files makes no sense since --diff is the option to grep history
+
+  $ hg grep --diff --all-files um
+  abort: --diff and --all-files are mutually exclusive
+  [255]
+
   $ cd ..
 
 Fix_Wdir(): test that passing wdir() t -r flag does greps on the
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2533,6 +2533,9 @@
     """
     opts = pycompat.byteskwargs(opts)
     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'))
+
     reflags = re.M
     if opts.get('ignore_case'):
         reflags |= re.I



To: yuja, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list