summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorThomas Gummerer <t.gummerer@gmail.com>2016-01-12 11:40:26 +0100
committerJunio C Hamano <gitster@pobox.com>2016-01-12 10:54:31 -0800
commitecd9ba61778e436dde12f08781a12ad1149d5ebf (patch)
tree5d4415cd5ae4acbeabdd3bfcb1ec97494a299e77 /builtin/grep.c
parent1f5101aee2daa3459cf50f945da924afa78a8ced (diff)
downloadgit-ecd9ba61778e436dde12f08781a12ad1149d5ebf.tar.gz
builtin/grep: add grep.fallbackToNoIndex configtg/grep-no-index-fallback
Currently when git grep is used outside of a git repository without the --no-index option git simply dies. For convenience, add a grep.fallbackToNoIndex configuration variable. If set to true, git grep behaves like git grep --no-index if it is run outside of a git repository. It defaults to false, preserving the current behavior. Helped-by: Jeff King <peff@peff.net> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index d04f4400d9..f8ed4f4182 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -770,9 +770,15 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
PARSE_OPT_NO_INTERNAL_HELP);
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