From ecd9ba61778e436dde12f08781a12ad1149d5ebf Mon Sep 17 00:00:00 2001 From: Thomas Gummerer Date: Tue, 12 Jan 2016 11:40:26 +0100 Subject: builtin/grep: add grep.fallbackToNoIndex config 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 Helped-by: Eric Sunshine Signed-off-by: Thomas Gummerer Signed-off-by: Junio C Hamano --- builtin/grep.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'builtin/grep.c') 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 -- cgit v1.2.1