summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 885d211)
raw | patch | inline | side by side (parent: 885d211)
author | Junio C Hamano <gitster@pobox.com> | |
Fri, 15 Jan 2010 20:50:54 +0000 (12:50 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 15 Jan 2010 20:54:00 +0000 (12:54 -0800) |
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>
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>
builtin-grep.c | patch | blob | history | |
git.c | patch | blob | history |
diff --git a/builtin-grep.c b/builtin-grep.c
index 3d6ebb586dd0ff4db513dcc77f9d37c75b79e19b..229555d52d93c5a8eba5e7cd923fd05f0fe3e5f7 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
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"),
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.
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,
index 11544cdb4037715b1e9edc14689896d99d6e3284..ad074735fcf4d37041da65653967a482b6070bfe 100644 (file)
--- a/git.c
+++ b/git.c
{ "fsck-objects", cmd_fsck, RUN_SETUP },
{ "gc", cmd_gc, RUN_SETUP },
{ "get-tar-commit-id", cmd_get_tar_commit_id },
- { "grep", cmd_grep, RUN_SETUP | USE_PAGER },
+ { "grep", cmd_grep, USE_PAGER },
{ "help", cmd_help },
{ "init", cmd_init_db },
{ "init-db", cmd_init_db },