3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='git grep various.
13 int main(int argc, const char **argv)
15 printf("Hello world.\n");
21 test_expect_success setup
'
25 echo foo_mmap bar mmap
26 echo foo mmap bar_mmap
27 echo foo_mmap bar mmap baz
44 test_expect_success
'grep should not segfault with a bad input' '
45 test_must_fail git grep "("
51 HEAD
) HC
='HEAD:' L
='HEAD' ;;
52 '') HC
= L
='in working tree' ;;
55 test_expect_success
"grep -w $L" '
57 echo ${HC}file:1:foo mmap bar
58 echo ${HC}file:3:foo_mmap bar mmap
59 echo ${HC}file:4:foo mmap bar_mmap
60 echo ${HC}file:5:foo_mmap bar mmap baz
62 git grep -n -w -e mmap $H >actual &&
66 test_expect_success
"grep -w $L (w)" '
68 ! git grep -n -w -e "^w" >actual &&
69 test_cmp expected actual
72 test_expect_success
"grep -w $L (x)" '
74 echo ${HC}x:1:x x xx x
76 git grep -n -w -e "x xx* x" $H >actual &&
80 test_expect_success
"grep -w $L (y-1)" '
84 git grep -n -w -e "^y" $H >actual &&
88 test_expect_success
"grep -w $L (y-2)" '
90 if git grep -n -w -e "^y y" $H >actual
92 echo should not have matched
100 test_expect_success
"grep -w $L (z)" '
102 if git grep -n -w -e "^z" $H >actual
104 echo should not have matched
112 test_expect_success
"grep $L (t-1)" '
113 echo "${HC}t/t:1:test" >expected &&
114 git grep -n -e test $H >actual &&
118 test_expect_success
"grep $L (t-2)" '
119 echo "${HC}t:1:test" >expected &&
122 git grep -n -e test $H
127 test_expect_success
"grep $L (t-3)" '
128 echo "${HC}t/t:1:test" >expected &&
131 git grep --full-name -n -e test $H
136 test_expect_success
"grep -c $L (no /dev/null)" '
137 ! git grep -c test $H | grep /dev/null
140 test_expect_success
"grep --max-depth -1 $L" '
142 echo ${HC}t/a/v:1:vvv
146 git grep --max-depth -1 -n -e vvv $H >actual &&
147 test_cmp expected actual
150 test_expect_success
"grep --max-depth 0 $L" '
154 git grep --max-depth 0 -n -e vvv $H >actual &&
155 test_cmp expected actual
158 test_expect_success
"grep --max-depth 0 -- '*' $L" '
160 echo ${HC}t/a/v:1:vvv
164 git grep --max-depth 0 -n -e vvv $H -- "*" >actual &&
165 test_cmp expected actual
168 test_expect_success
"grep --max-depth 1 $L" '
173 git grep --max-depth 1 -n -e vvv $H >actual &&
174 test_cmp expected actual
177 test_expect_success
"grep --max-depth 0 -- t $L" '
181 git grep --max-depth 0 -n -e vvv $H -- t >actual &&
182 test_cmp expected actual
188 file:foo mmap bar_mmap
191 test_expect_success
'grep -e A --and -e B' '
192 git grep -e "foo mmap" --and -e bar_mmap >actual &&
193 test_cmp expected actual
197 file:foo_mmap bar mmap
198 file:foo_mmap bar mmap baz
202 test_expect_success
'grep ( -e A --or -e B ) --and -e B' '
203 git grep \( -e foo_ --or -e baz \) \
204 --and -e " mmap" >actual &&
205 test_cmp expected actual
212 test_expect_success
'grep -e A --and --not -e B' '
213 git grep -e "foo mmap" --and --not -e bar_mmap >actual &&
214 test_cmp expected actual
223 # Create 1024 file names that sort between "y" and "z" to make sure
224 # the two files are handled by different calls to an external grep.
225 # This depends on MAXARGS in builtin-grep.c being 1024 or less.
226 c32
="0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v"
227 test_expect_success
'grep -C1, hunk mark between files' '
228 for a in $c32; do for b in $c32; do : >y-$a$b; done; done &&
230 git grep -C1 "^[yz]" >actual &&
231 test_cmp expected actual
234 test_expect_success
'grep -C1 --no-ext-grep, hunk mark between files' '
235 git grep -C1 --no-ext-grep "^[yz]" >actual &&
236 test_cmp expected actual
239 test_expect_success
'log grep setup' '
242 GIT_AUTHOR_NAME="With * Asterisk" \
243 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
244 git commit -a -m "second" &&
248 git commit -a -m "third"
252 test_expect_success
'log grep (1)' '
253 git log --author=author --pretty=tformat:%s >actual &&
254 ( echo third ; echo initial ) >expect &&
255 test_cmp expect actual
258 test_expect_success
'log grep (2)' '
259 git log --author=" * " -F --pretty=tformat:%s >actual &&
260 ( echo second ) >expect &&
261 test_cmp expect actual
264 test_expect_success
'log grep (3)' '
265 git log --author="^A U" --pretty=tformat:%s >actual &&
266 ( echo third ; echo initial ) >expect &&
267 test_cmp expect actual
270 test_expect_success
'log grep (4)' '
271 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
272 ( echo second ) >expect &&
273 test_cmp expect actual
276 test_expect_success
'log grep (5)' '
277 git log --author=Thor -F --grep=Thu --pretty=tformat:%s >actual &&
278 ( echo third ; echo initial ) >expect &&
279 test_cmp expect actual
282 test_expect_success
'log grep (6)' '
283 git log --author=-0700 --pretty=tformat:%s >actual &&
285 test_cmp expect actual
288 test_expect_success
'grep with CE_VALID file' '
289 git update-index --assume-unchanged t/t &&
291 test "$(git grep --no-ext-grep test)" = "t/t:test" &&
292 git update-index --no-assume-unchanged t/t &&
297 hello.c=#include <stdio.h>
301 test_expect_success
'grep -p with userdiff' '
302 git config diff.custom.funcname "^#" &&
303 echo "hello.c diff=custom" >.gitattributes &&
304 git grep -p return >actual &&
305 test_cmp expected actual
309 hello.c=int main(int argc, const char **argv)
313 test_expect_success
'grep -p' '
314 rm -f .gitattributes &&
315 git grep -p return >actual &&
316 test_cmp expected actual
320 hello.c-#include <stdio.h>
321 hello.c=int main(int argc, const char **argv)
323 hello.c- printf("Hello world.\n");
327 test_expect_success
'grep -p -B5' '
328 git grep -p -B5 return >actual &&
329 test_cmp expected actual
332 test_expect_success
'grep from a subdirectory to search wider area (1)' '
335 cd s && git grep "x x x" ..
339 test_expect_success
'grep from a subdirectory to search wider area (2)' '
343 ( git grep xxyyzz .. >out ; echo $? >status )
345 test 1 = $(cat status)
350 hello.c:int main(int argc, const char **argv)
353 test_expect_success
'grep -Fi' '
354 git grep -Fi "CHAR *" >actual &&
355 test_cmp expected actual