diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-01-15 12:50:54 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-01-15 12:54:00 -0800 |
commit | 7e622650d756955a94f546866eddd51506aa93a3 (patch) | |
tree | 7eb51da4665f07adb7e0ee26ab3d6877eabadb37 /builtin-grep.c | |
parent | 885d211e714b3787cd059e347694f9b24e1db1f3 (diff) | |
download | git-7e622650d756955a94f546866eddd51506aa93a3.tar.gz |
grep: prepare to run outside of a work tree
This moves the call to setup_git_directory() for running "grep" from
the "git" wrapper to the implementation of the "grep" subcommand. A
new variable "use_index" is always true at this stage in the series,
and when it is on, we require that we are in a directory that is under
git control. To make sure we die the same way, we make a second call
into setup_git_directory() when we detect this situation.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-grep.c')
-rw-r--r-- | builtin-grep.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/builtin-grep.c b/builtin-grep.c index 3d6ebb586d..229555d52d 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -414,6 +414,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) const char **paths = NULL; int i; int dummy; + int nongit = 0, use_index = 1; struct option options[] = { OPT_BOOLEAN(0, "cached", &cached, "search in index instead of in the work tree"), @@ -497,6 +498,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_END() }; + prefix = setup_git_directory_gently(&nongit); + /* * 'git grep -h', unlike 'git grep -h <pattern>', is a request * to show usage information and exit. @@ -534,6 +537,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix) PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_NO_INTERNAL_HELP); + if (use_index && nongit) + /* die the same way as if we did it at the beginning */ + setup_git_directory(); + /* First unrecognized non-option token */ if (argc > 0 && !opt.pattern_list) { append_grep_pattern(&opt, argv[0], "command line", 0, |