Code

Merge branch 'rs/git-dir-cleanup'
authorJunio C Hamano <gitster@pobox.com>
Sat, 13 Feb 2010 23:09:33 +0000 (15:09 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 13 Feb 2010 23:09:33 +0000 (15:09 -0800)
* rs/git-dir-cleanup:
  Resurrect "git grep --no-index"
  setenv(GIT_DIR) clean-up

Conflicts:
builtin-grep.c
t/t7002-grep.sh

1  2 
builtin-grep.c
t/t7002-grep.sh

diff --cc builtin-grep.c
index 63d4b95b0d8d1d0f3a3cc8acc50bab9cdf67deaa,0ef849cb84650705ffc840aed8a3fcedbeb48f9a..46ffc1d1d917dd9388ae76899630b717811205a6
@@@ -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 0b583cbfc15ae09c030c0d4e82635f244ffc5293,bf4d4dcb2bc577715a02ae01f95a5be348e40384..ebae1522c82a6a38e9f5bfeb051f39486b33ccb3
@@@ -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 <<EOF &&
 +--
 +->
 +other
 +EOF
 +git add double-dash
 +'
 +
 +cat >expected <<EOF
 +double-dash:->
 +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 <<EOF
 +double-dash:--
 +EOF
 +test_expect_success 'grep -e -- -- path' '
 +      git grep -e -- -- double-dash >actual &&
 +      test_cmp expected actual
 +'
 +
  test_done