Merge branch 'tg/grep-no-index-fallback'
authorJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2016 19:43:38 +0000 (11:43 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2016 19:43:39 +0000 (11:43 -0800)
"git grep" by default does not fall back to its "--no-index"
behaviour outside a directory under Git's control (otherwise the
user may by mistake end up running a huge recursive search); with a
new configuration (set in $HOME/.gitconfig--by definition this
cannot be set in the config file per project), this safety can be
disabled.

* tg/grep-no-index-fallback:
builtin/grep: add grep.fallbackToNoIndex config
t7810: correct --no-index test

1  2 
Documentation/config.txt
Documentation/git-grep.txt
builtin/grep.c
index beb18da14354a4b8b475b74113d103d404c70a7d,d41b2a61a82645755256e580cd5227b5940010b9..07f7a3b771266d488f986cd803e3fd7809533e21
@@@ -1450,10 -1399,10 +1450,14 @@@ grep.extendedRegexp:
        option is ignored when the 'grep.patternType' option is set to a value
        other than 'default'.
  
 +grep.threads::
 +      Number of grep worker threads to use.
 +      See `grep.threads` in linkgit:git-grep[1] for more information.
 +
+ grep.fallbackToNoIndex::
+       If set to true, fall back to git grep --no-index if git grep
+       is executed outside of a git repository.  Defaults to false.
  gpg.program::
        Use this custom program instead of "gpg" found on $PATH when
        making or verifying a PGP signature. The program must support the
Simple merge
diff --cc builtin/grep.c
index 06ab68223a13b35612e2cb283d778a9c904b5528,f8ed4f4182a87134513888719c30a0d32efee135..5526fd705657ff80db630ec4f29554893b6c09ad
@@@ -765,12 -766,19 +765,18 @@@ int cmd_grep(int argc, const char **arg
         */
        argc = parse_options(argc, argv, prefix, options, grep_usage,
                             PARSE_OPT_KEEP_DASHDASH |
 -                           PARSE_OPT_STOP_AT_NON_OPTION |
 -                           PARSE_OPT_NO_INTERNAL_HELP);
 +                           PARSE_OPT_STOP_AT_NON_OPTION);
        grep_commit_pattern_type(pattern_type_arg, &opt);
  
-       if (use_index && !startup_info->have_repository)
-               /* die the same way as if we did it at the beginning */
-               setup_git_directory();
+       if (use_index && !startup_info->have_repository) {
+               int fallback = 0;
+               git_config_get_bool("grep.fallbacktonoindex", &fallback);
+               if (fallback)
+                       use_index = 0;
+               else
+                       /* die the same way as if we did it at the beginning */
+                       setup_git_directory();
+       }
  
        /*
         * skip a -- separator; we know it cannot be