]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'pb/do-not-recurse-grep-no-index'
authorJunio C Hamano <gitster@pobox.com>
Wed, 12 Feb 2020 20:41:36 +0000 (12:41 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Feb 2020 20:41:36 +0000 (12:41 -0800)
"git grep --no-index" should not get affected by the contents of
the .gitmodules file but when "--recurse-submodules" is given or
the "submodule.recurse" variable is set, it did.  Now these
settings are ignored in the "--no-index" mode.

* pb/do-not-recurse-grep-no-index:
  grep: ignore --recurse-submodules if --no-index is given

Documentation/git-grep.txt
builtin/grep.c
t/t7814-grep-recurse-submodules.sh

index c89fb569e35855e79a43ee3cde784df5b7cb269c..ffc3a6efdc10f0bcf1a95a07f1dcf365ea41ddf7 100644 (file)
@@ -96,7 +96,8 @@ OPTIONS
        Recursively search in each submodule that has been initialized and
        checked out in the repository.  When used in combination with the
        <tree> option the prefix of all submodule output will be the name of
-       the parent project's <tree> object.
+       the parent project's <tree> object. This option has no effect
+       if `--no-index` is given.
 
 -a::
 --text::
index 50ce8d946128c9f54d43d234a2117f3dba6d2299..ae2d5bbafcae263e91cd7f9ea7a97dc7a874d4aa 100644 (file)
@@ -958,6 +958,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                        /* die the same way as if we did it at the beginning */
                        setup_git_directory();
        }
+       /* Ignore --recurse-submodules if --no-index is given or implied */
+       if (!use_index)
+               recurse_submodules = 0;
 
        /*
         * skip a -- separator; we know it cannot be
@@ -1115,8 +1118,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                }
        }
 
-       if (recurse_submodules && (!use_index || untracked))
-               die(_("option not supported with --recurse-submodules"));
+       if (recurse_submodules && untracked)
+               die(_("--untracked not supported with --recurse-submodules"));
 
        if (!show_in_pager && !opt.status_only)
                setup_pager();
index 946f91fa5782f2810b1286427359c06b64273b3a..828cb3ba5818fd47b6466fd52235e1d5a54cb333 100755 (executable)
@@ -345,7 +345,16 @@ test_incompatible_with_recurse_submodules ()
 }
 
 test_incompatible_with_recurse_submodules --untracked
-test_incompatible_with_recurse_submodules --no-index
+
+test_expect_success 'grep --recurse-submodules --no-index ignores --recurse-submodules' '
+       git grep --recurse-submodules --no-index -e "^(.|.)[\d]" >actual &&
+       cat >expect <<-\EOF &&
+       a:(1|2)d(3|4)
+       submodule/a:(1|2)d(3|4)
+       submodule/sub/a:(1|2)d(3|4)
+       EOF
+       test_cmp expect actual
+'
 
 test_expect_success 'grep --recurse-submodules should pass the pattern type along' '
        # Fixed