From: Junio C Hamano Date: Sat, 13 Feb 2010 23:09:33 +0000 (-0800) Subject: Merge branch 'rs/git-dir-cleanup' X-Git-Tag: v1.7.1-rc0~157 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=263830c47b0ddd3440fbc87a841499fe699a50b1;p=git.git Merge branch 'rs/git-dir-cleanup' * rs/git-dir-cleanup: Resurrect "git grep --no-index" setenv(GIT_DIR) clean-up Conflicts: builtin-grep.c t/t7002-grep.sh --- 263830c47b0ddd3440fbc87a841499fe699a50b1 diff --cc builtin-grep.c index 63d4b95b0,0ef849cb8..46ffc1d1d --- a/builtin-grep.c +++ b/builtin-grep.c @@@ -861,16 -885,10 +885,20 @@@ int cmd_grep(int argc, const char **arg 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(); + + /* + * skip a -- separator; we know it cannot be + * separating revisions from pathnames if + * we haven't even had any patterns yet + */ + if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) { + argv++; + argc--; + } + /* First unrecognized non-option token */ if (argc > 0 && !opt.pattern_list) { append_grep_pattern(&opt, argv[0], "command line", 0, diff --cc t/t7002-grep.sh index 0b583cbfc,bf4d4dcb2..ebae1522c --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@@ -434,37 -434,56 +434,89 @@@ test_expect_success 'grep -Fi' test_cmp expected actual ' + test_expect_success 'outside of git repository' ' + rm -fr non && + mkdir -p non/git/sub && + echo hello >non/git/file1 && + echo world >non/git/sub/file2 && + echo ".*o*" >non/git/.gitignore && + { + echo file1:hello && + echo sub/file2:world + } >non/expect.full && + echo file2:world >non/expect.sub + ( + GIT_CEILING_DIRECTORIES="$(pwd)/non/git" && + export GIT_CEILING_DIRECTORIES && + cd non/git && + test_must_fail git grep o && + git grep --no-index o >../actual.full && + test_cmp ../expect.full ../actual.full + cd sub && + test_must_fail git grep o && + git grep --no-index o >../../actual.sub && + test_cmp ../../expect.sub ../../actual.sub + ) + ' + + test_expect_success 'inside git repository but with --no-index' ' + rm -fr is && + mkdir -p is/git/sub && + echo hello >is/git/file1 && + echo world >is/git/sub/file2 && + echo ".*o*" >is/git/.gitignore && + { + echo file1:hello && + echo sub/file2:world + } >is/expect.full && + : >is/expect.empty && + echo file2:world >is/expect.sub + ( + cd is/git && + git init && + test_must_fail git grep o >../actual.full && + test_cmp ../expect.empty ../actual.full && + git grep --no-index o >../actual.full && + test_cmp ../expect.full ../actual.full && + cd sub && + test_must_fail git grep o >../../actual.sub && + test_cmp ../../expect.empty ../../actual.sub && + git grep --no-index o >../../actual.sub && + test_cmp ../../expect.sub ../../actual.sub + ) + ' + +test_expect_success 'setup double-dash tests' ' +cat >double-dash < +other +EOF +git add double-dash +' + +cat >expected < +EOF +test_expect_success 'grep -- pattern' ' + git grep -- "->" >actual && + test_cmp expected actual +' +test_expect_success 'grep -- pattern -- pathspec' ' + git grep -- "->" -- double-dash >actual && + test_cmp expected actual +' +test_expect_success 'grep -e pattern -- path' ' + git grep -e "->" -- double-dash >actual && + test_cmp expected actual +' + +cat >expected <actual && + test_cmp expected actual +' + test_done