From dbb6a4ada6c6c1065b62313127ff032196e9d232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 23 May 2009 13:45:26 +0200 Subject: grep: fix word-regexp at the beginning of lines After bol is forwarded, it doesn't represent the beginning of the line any more. This means that the beginning-of-line marker (^) mustn't match, i.e. the regex flag REG_NOTBOL needs to be set. This bug was introduced by fb62eb7fab97cea880ea7fe4f341a4dfad14ab48 ("grep -w: forward to next possible position after rejected match"). Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index b81593780a..f275af8240 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -16,12 +16,13 @@ test_expect_success setup ' echo foo mmap bar_mmap echo foo_mmap bar mmap baz } >file && + echo ww w >w && echo x x xx x >x && echo y yy >y && echo zzz > z && mkdir t && echo test >t/t && - git add file x y z t/t && + git add file w x y z t/t && test_tick && git commit -m initial ' @@ -48,6 +49,12 @@ do diff expected actual ' + test_expect_success "grep -w $L (w)" ' + : >expected && + ! git grep -n -w -e "^w" >actual && + test_cmp expected actual + ' + test_expect_success "grep -w $L (x)" ' { echo ${HC}x:1:x x xx x -- cgit v1.2.1 From 0f7050469b7ae9a95ab01880ecd5cf22e6e41dd2 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Sat, 27 Jun 2009 20:47:44 +0200 Subject: Test grep --and/--or/--not Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index f275af8240..7868af8f18 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -125,6 +125,36 @@ do done +cat >expected <actual && + test_cmp expected actual +' + +cat >expected <actual && + test_cmp expected actual +' + +cat >expected <actual && + test_cmp expected actual +' + test_expect_success 'log grep setup' ' echo a >>file && test_tick && -- cgit v1.2.1 From 046802d015b3be2e055ae68f29f76741023bc32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 2 Jul 2009 00:03:44 +0200 Subject: grep: print context hunk marks between files Print a hunk mark before matches from a new file are shown, in addition to the current behaviour of printing them if lines have been skipped. The result is easier to read, as (presumably unrelated) matches from different files are separated by a hunk mark. GNU grep does the same. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 7868af8f18..155bfdb7d7 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -155,6 +155,28 @@ test_expect_success 'grep -e A --and --not -e B' ' test_cmp expected actual ' +cat >expected <y-$a$b; done; done && + git add y-?? && + git grep -C1 "^[yz]" >actual && + test_cmp expected actual +' + +test_expect_success 'grep -C1 --no-ext-grep, hunk mark between files' ' + git grep -C1 --no-ext-grep "^[yz]" >actual && + test_cmp expected actual +' + test_expect_success 'log grep setup' ' echo a >>file && test_tick && -- cgit v1.2.1 From 2944e4e6145bdfcb1a8730d7da671786d72c86ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 2 Jul 2009 00:06:34 +0200 Subject: grep: add option -p/--show-function The new option -p instructs git grep to print the previous function definition as a context line, similar to diff -p. Such context lines are marked with an equal sign instead of a dash. This option complements the existing context options -A, -B, -C. Function definitions are detected using the same heuristic that diff uses. User defined regular expressions are not supported, yet. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 155bfdb7d7..ef59ab9941 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -8,6 +8,15 @@ test_description='git grep various. . ./test-lib.sh +cat >hello.c < +int main(int argc, const char **argv) +{ + printf("Hello world.\n"); + return 0; +} +EOF + test_expect_success setup ' { echo foo mmap bar @@ -22,7 +31,7 @@ test_expect_success setup ' echo zzz > z && mkdir t && echo test >t/t && - git add file w x y z t/t && + git add file w x y z t/t hello.c && test_tick && git commit -m initial ' @@ -229,9 +238,32 @@ test_expect_success 'log grep (6)' ' test_expect_success 'grep with CE_VALID file' ' git update-index --assume-unchanged t/t && rm t/t && - test "$(git grep --no-ext-grep t)" = "t/t:test" && + test "$(git grep --no-ext-grep test)" = "t/t:test" && git update-index --no-assume-unchanged t/t && git checkout t/t ' +cat >expected <actual && + test_cmp expected actual +' + +cat >expected < +hello.c=int main(int argc, const char **argv) +hello.c-{ +hello.c- printf("Hello world.\n"); +hello.c: return 0; +EOF + +test_expect_success 'grep -p -B5' ' + git grep -p -B5 return >actual && + test_cmp expected actual +' + test_done -- cgit v1.2.1 From 60ecac98ed6f420c6bf823491074219087c749d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 2 Jul 2009 00:07:24 +0200 Subject: grep -p: support user defined regular expressions Respect the userdiff attributes and config settings when looking for lines with function definitions in git grep -p. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index ef59ab9941..b13aa7e89a 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -243,12 +243,25 @@ test_expect_success 'grep with CE_VALID file' ' git checkout t/t ' +cat >expected < +hello.c: return 0; +EOF + +test_expect_success 'grep -p with userdiff' ' + git config diff.custom.funcname "^#" && + echo "hello.c diff=custom" >.gitattributes && + git grep -p return >actual && + test_cmp expected actual +' + cat >expected <actual && test_cmp expected actual ' -- cgit v1.2.1 From a91f453f641ca9966a438bdd3896656b00423407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kiedrowicz?= Date: Wed, 22 Jul 2009 19:52:15 +0200 Subject: grep: Add --max-depth option. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is useful to grep directories non-recursively, e.g. when one wants to look for all files in the toplevel directory, but not in any subdirectory, or in Documentation/, but not in Documentation/technical/. This patch adds support for --max-depth option to git-grep. If it is given, git-grep descends at most levels of directories below paths specified on the command line. Note that if path specified on command line contains wildcards, this option makes no sense, e.g. $ git grep -l --max-depth 0 GNU -- 'contrib/*' (note the quotes) will search all files in contrib/, even in subdirectories, because '*' matches all files. Documentation updates, bash-completion and simple test cases are also provided. Signed-off-by: MichaƂ Kiedrowicz Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index b13aa7e89a..b4709e28b5 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -25,13 +25,17 @@ test_expect_success setup ' echo foo mmap bar_mmap echo foo_mmap bar mmap baz } >file && + echo vvv >v && echo ww w >w && echo x x xx x >x && echo y yy >y && echo zzz > z && mkdir t && echo test >t/t && - git add file w x y z t/t hello.c && + echo vvv >t/v && + mkdir t/a && + echo vvv >t/a/v && + git add . && test_tick && git commit -m initial ' @@ -132,6 +136,51 @@ do ! git grep -c test $H | grep /dev/null ' + test_expect_success "grep --max-depth -1 $L" ' + { + echo ${HC}t/a/v:1:vvv + echo ${HC}t/v:1:vvv + echo ${HC}v:1:vvv + } >expected && + git grep --max-depth -1 -n -e vvv $H >actual && + test_cmp expected actual + ' + + test_expect_success "grep --max-depth 0 $L" ' + { + echo ${HC}v:1:vvv + } >expected && + git grep --max-depth 0 -n -e vvv $H >actual && + test_cmp expected actual + ' + + test_expect_success "grep --max-depth 0 -- '*' $L" ' + { + echo ${HC}t/a/v:1:vvv + echo ${HC}t/v:1:vvv + echo ${HC}v:1:vvv + } >expected && + git grep --max-depth 0 -n -e vvv $H -- "*" >actual && + test_cmp expected actual + ' + + test_expect_success "grep --max-depth 1 $L" ' + { + echo ${HC}t/v:1:vvv + echo ${HC}v:1:vvv + } >expected && + git grep --max-depth 1 -n -e vvv $H >actual && + test_cmp expected actual + ' + + test_expect_success "grep --max-depth 0 -- t $L" ' + { + echo ${HC}t/v:1:vvv + } >expected && + git grep --max-depth 0 -n -e vvv $H -- t >actual && + test_cmp expected actual + ' + done cat >expected < Date: Sat, 5 Sep 2009 14:31:17 +0200 Subject: grep: accept relative paths outside current working directory "git grep" would barf at relative paths pointing outside the current working directory (or subdirectories thereof). Use quote_path_relative(), which can handle such cases just fine. [jc: added tests.] Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 7868af8f18..fe87834fbe 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -212,4 +212,21 @@ test_expect_success 'grep with CE_VALID file' ' git checkout t/t ' +test_expect_success 'grep from a subdirectory to search wider area (1)' ' + mkdir -p s && + ( + cd s && git grep "x x x" .. + ) +' + +test_expect_success 'grep from a subdirectory to search wider area (2)' ' + mkdir -p s && + ( + cd s || exit 1 + ( git grep xxyyzz .. >out ; echo $? >status ) + ! test -s out && + test 1 = $(cat status) + ) +' + test_done -- cgit v1.2.1 From cfe370c6476392095bc3f18013d195b1cccd6184 Mon Sep 17 00:00:00 2001 From: Matt Kraai Date: Fri, 16 Oct 2009 07:13:25 -0700 Subject: grep: do not segfault when -f is used "git grep" would segfault if its -f option was used because it would try to use an uninitialized strbuf, so initialize the strbuf. Thanks to Johannes Sixt for the help with the test cases. Signed-off-by: Matt Kraai Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 6ca11d7146..5f91d82297 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -164,6 +164,72 @@ test_expect_success 'grep -e A --and --not -e B' ' test_cmp expected actual ' +test_expect_success 'grep -f, non-existent file' ' + test_must_fail git grep -f patterns +' + +cat >expected <pattern <actual && + test_cmp expected actual +' + +cat >expected <patterns <actual && + test_cmp expected actual +' + +cat >expected <patterns <actual && + test_cmp expected actual +' + cat >expected < Date: Fri, 6 Nov 2009 01:22:35 -0800 Subject: grep: Allow case insensitive search of fixed-strings "git grep" currently an error when you combine the -F and -i flags. This isn't in line with how GNU grep handles it. This patch allows the simultaneous use of those flags. Signed-off-by: Jeff King Signed-off-by: Brian Collins Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index ae56a36eac..35a1e7a5d4 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -14,6 +14,7 @@ int main(int argc, const char **argv) { printf("Hello world.\n"); return 0; + /* char ?? */ } EOF @@ -345,4 +346,13 @@ test_expect_success 'grep from a subdirectory to search wider area (2)' ' ) ' +cat >expected <actual && + test_cmp expected actual +' + test_done -- cgit v1.2.1 From b48275998399561780af85d429da3caceeecd2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sun, 22 Nov 2009 16:58:09 +0100 Subject: grep: unset GREP_OPTIONS before spawning external grep While we're at it, also unset GREP_COLOR and GREP_COLORS in case colouring is not enabled, to be on the safe side. The presence of these variables alone is not sufficient to trigger coloured output with GNU grep, but other implementations may behave differently. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index ae5290ab43..dd0da6c0bf 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -213,6 +213,11 @@ test_expect_success 'grep -e A --and --not -e B' ' test_cmp expected actual ' +test_expect_success 'grep should ignore GREP_OPTIONS' ' + GREP_OPTIONS=-v git grep " mmap bar\$" >actual && + test_cmp expected actual +' + test_expect_success 'grep -f, non-existent file' ' test_must_fail git grep -f patterns ' -- cgit v1.2.1 From bbc09c22b9f7784b1aab71d4876227956e6e8f4f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 12 Jan 2010 19:06:41 -0800 Subject: grep: rip out support for external grep We still allow people to pass --[no-]ext-grep on the command line, but the option is ignored. Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index abd14bf819..c369cdbe9b 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -302,8 +302,8 @@ test_expect_success 'grep -C1, hunk mark between files' ' test_cmp expected actual ' -test_expect_success 'grep -C1 --no-ext-grep, hunk mark between files' ' - git grep -C1 --no-ext-grep "^[yz]" >actual && +test_expect_success 'grep -C1 hunk mark between files' ' + git grep -C1 "^[yz]" >actual && test_cmp expected actual ' @@ -359,7 +359,7 @@ test_expect_success 'log grep (6)' ' test_expect_success 'grep with CE_VALID file' ' git update-index --assume-unchanged t/t && rm t/t && - test "$(git grep --no-ext-grep test)" = "t/t:test" && + test "$(git grep test)" = "t/t:test" && git update-index --no-assume-unchanged t/t && git checkout t/t ' -- cgit v1.2.1 From 308162372d0aa202ff45743e02253e20a4fac4d7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 15 Jan 2010 12:52:40 -0800 Subject: grep --no-index: allow use of "git grep" outside a git repository Just like some people wanted diff features that are not found in other people's diff implementations outside of a git repository and added --no-index mode to the command, this adds --no-index mode to the "git grep" command. Also, inside a git repository, --no-index mode allows you to grep in untracked (but not ignored) files. Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index c369cdbe9b..7eceb086be 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -426,4 +426,56 @@ 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_done -- cgit v1.2.1 From 4ff61c21de519b4b3c9569b354fa5a3905b69c6a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 28 Jan 2010 12:33:42 -0800 Subject: grep --quiet: finishing touches Name the option "--quiet" not "--quick", document it, and add tests. Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 7eceb086be..bf4d4dcb2b 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -291,6 +291,14 @@ y:y yy z:zzz EOF +test_expect_success 'grep -q, silently report matches' ' + >empty && + git grep -q mmap >actual && + test_cmp empty actual && + test_must_fail git grep -q qfwfq >actual && + test_cmp empty actual +' + # Create 1024 file names that sort between "y" and "z" to make sure # the two files are handled by different calls to an external grep. # This depends on MAXARGS in builtin-grep.c being 1024 or less. -- cgit v1.2.1 From 3c8f6c8c4f00414e66076c2c97c834d01f828491 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 Feb 2010 09:20:01 -0800 Subject: Revert 30816237 and 7e62265 It seems that we have bad interaction with the code related to GIT_WORK_TREE and "grep --no-index", and broke running grep inside the .git directory. For now, just revert it and resurrect it after 1.7.0 ships. Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index bf4d4dcb2b..7144f815c0 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -434,56 +434,4 @@ 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_done -- cgit v1.2.1 From 1123c67ceee2f310b08ab5d67b076ef04ab59bfc Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 6 Feb 2010 23:44:15 -0500 Subject: accept "git grep -- pattern" Currently the only way to "quote" a grep pattern that might begin with a dash is to use "git grep -e pattern". This works just fine, and is also the way right way to do it on many traditional grep implemenations. Some people prefer to use "git grep -- pattern", however, as "--" is the usual "end of options" marker, and at least GNU grep and Solaris 10 grep support this. This patch makes that syntax work. There is a slight behavior change, in that "git grep -- $X" used to be interpreted as "grep for -- in $X". However, that usage is questionable. "--" is usually the end-of-options marker, so "git grep" was unlike many other greps in treating it as a literal pattern (e.g., both GNU grep and Solaris 10 grep will treat "grep --" as missing a pattern). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t7002-grep.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 7144f815c0..0b583cbfc1 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -434,4 +434,37 @@ test_expect_success 'grep -Fi' ' test_cmp expected actual ' +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 -- cgit v1.2.1 From 59332d13b2b23840452180368914921bffe9bfbc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 6 Feb 2010 10:40:08 -0800 Subject: Resurrect "git grep --no-index" This reverts commit 3c8f6c8 (Revert 30816237 and 7e62265, 2010-02-05) as the issue has been sorted out. --- t/t7002-grep.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 't/t7002-grep.sh') diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 7144f815c0..bf4d4dcb2b 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -434,4 +434,56 @@ 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_done -- cgit v1.2.1