]>
Commit | Line | Data |
---|---|---|
f25b7939 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Junio C Hamano | |
4 | # | |
5 | ||
0d042fec | 6 | test_description='git grep various. |
f25b7939 JH |
7 | ' |
8 | ||
9 | . ./test-lib.sh | |
10 | ||
2944e4e6 | 11 | cat >hello.c <<EOF |
799e09e5 | 12 | #include <assert.h> |
2944e4e6 | 13 | #include <stdio.h> |
799e09e5 | 14 | |
2944e4e6 RS |
15 | int main(int argc, const char **argv) |
16 | { | |
17 | printf("Hello world.\n"); | |
18 | return 0; | |
5183bf67 | 19 | /* char ?? */ |
2944e4e6 RS |
20 | } |
21 | EOF | |
22 | ||
f25b7939 JH |
23 | test_expect_success setup ' |
24 | { | |
25 | echo foo mmap bar | |
26 | echo foo_mmap bar | |
27 | echo foo_mmap bar mmap | |
28 | echo foo mmap bar_mmap | |
29 | echo foo_mmap bar mmap baz | |
30 | } >file && | |
8f852ce6 MK |
31 | { |
32 | echo Hello world | |
33 | echo HeLLo world | |
34 | echo Hello_world | |
35 | echo HeLLo_world | |
36 | } >hello_world && | |
f556e4af | 37 | { |
d0042abe MK |
38 | echo "a+b*c" |
39 | echo "a+bc" | |
40 | echo "abc" | |
f556e4af | 41 | } >ab && |
7675c7bd JK |
42 | { |
43 | echo d && | |
44 | echo 0 | |
45 | } >d0 && | |
a91f453f | 46 | echo vvv >v && |
dbb6a4ad | 47 | echo ww w >w && |
f25b7939 JH |
48 | echo x x xx x >x && |
49 | echo y yy >y && | |
50 | echo zzz > z && | |
0d042fec JH |
51 | mkdir t && |
52 | echo test >t/t && | |
a91f453f MK |
53 | echo vvv >t/v && |
54 | mkdir t/a && | |
55 | echo vvv >t/a/v && | |
d29d787c MK |
56 | { |
57 | echo "line without leading space1" | |
58 | echo " line with leading space1" | |
59 | echo " line with leading space2" | |
60 | echo " line with leading space3" | |
61 | echo "line without leading space2" | |
62 | } >space && | |
a91f453f | 63 | git add . && |
a4d7d2c6 | 64 | test_tick && |
f25b7939 JH |
65 | git commit -m initial |
66 | ' | |
67 | ||
c922b01f LT |
68 | test_expect_success 'grep should not segfault with a bad input' ' |
69 | test_must_fail git grep "(" | |
70 | ' | |
71 | ||
f25b7939 JH |
72 | for H in HEAD '' |
73 | do | |
74 | case "$H" in | |
75 | HEAD) HC='HEAD:' L='HEAD' ;; | |
76 | '') HC= L='in working tree' ;; | |
77 | esac | |
78 | ||
79 | test_expect_success "grep -w $L" ' | |
80 | { | |
81 | echo ${HC}file:1:foo mmap bar | |
82 | echo ${HC}file:3:foo_mmap bar mmap | |
83 | echo ${HC}file:4:foo mmap bar_mmap | |
84 | echo ${HC}file:5:foo_mmap bar mmap baz | |
85 | } >expected && | |
b22520a3 JR |
86 | git -c grep.linenumber=false grep -n -w -e mmap $H >actual && |
87 | test_cmp expected actual | |
88 | ' | |
89 | ||
90 | test_expect_success "grep -w $L" ' | |
91 | { | |
92 | echo ${HC}file:1:foo mmap bar | |
93 | echo ${HC}file:3:foo_mmap bar mmap | |
94 | echo ${HC}file:4:foo mmap bar_mmap | |
95 | echo ${HC}file:5:foo_mmap bar mmap baz | |
96 | } >expected && | |
97 | git -c grep.linenumber=true grep -w -e mmap $H >actual && | |
98 | test_cmp expected actual | |
99 | ' | |
100 | ||
101 | test_expect_success "grep -w $L" ' | |
102 | { | |
103 | echo ${HC}file:foo mmap bar | |
104 | echo ${HC}file:foo_mmap bar mmap | |
105 | echo ${HC}file:foo mmap bar_mmap | |
106 | echo ${HC}file:foo_mmap bar mmap baz | |
107 | } >expected && | |
108 | git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual && | |
4fdf71be | 109 | test_cmp expected actual |
f25b7939 JH |
110 | ' |
111 | ||
dbb6a4ad RS |
112 | test_expect_success "grep -w $L (w)" ' |
113 | : >expected && | |
9afad7a1 | 114 | test_must_fail git grep -n -w -e "^w" $H >actual && |
dbb6a4ad RS |
115 | test_cmp expected actual |
116 | ' | |
117 | ||
f25b7939 JH |
118 | test_expect_success "grep -w $L (x)" ' |
119 | { | |
120 | echo ${HC}x:1:x x xx x | |
121 | } >expected && | |
122 | git grep -n -w -e "x xx* x" $H >actual && | |
4fdf71be | 123 | test_cmp expected actual |
f25b7939 JH |
124 | ' |
125 | ||
126 | test_expect_success "grep -w $L (y-1)" ' | |
127 | { | |
128 | echo ${HC}y:1:y yy | |
129 | } >expected && | |
130 | git grep -n -w -e "^y" $H >actual && | |
4fdf71be | 131 | test_cmp expected actual |
f25b7939 JH |
132 | ' |
133 | ||
134 | test_expect_success "grep -w $L (y-2)" ' | |
135 | : >expected && | |
136 | if git grep -n -w -e "^y y" $H >actual | |
137 | then | |
138 | echo should not have matched | |
139 | cat actual | |
140 | false | |
141 | else | |
4fdf71be | 142 | test_cmp expected actual |
f25b7939 JH |
143 | fi |
144 | ' | |
145 | ||
146 | test_expect_success "grep -w $L (z)" ' | |
147 | : >expected && | |
148 | if git grep -n -w -e "^z" $H >actual | |
149 | then | |
150 | echo should not have matched | |
151 | cat actual | |
152 | false | |
153 | else | |
4fdf71be | 154 | test_cmp expected actual |
f25b7939 JH |
155 | fi |
156 | ' | |
0d042fec JH |
157 | |
158 | test_expect_success "grep $L (t-1)" ' | |
159 | echo "${HC}t/t:1:test" >expected && | |
160 | git grep -n -e test $H >actual && | |
4fdf71be | 161 | test_cmp expected actual |
0d042fec JH |
162 | ' |
163 | ||
164 | test_expect_success "grep $L (t-2)" ' | |
165 | echo "${HC}t:1:test" >expected && | |
166 | ( | |
167 | cd t && | |
168 | git grep -n -e test $H | |
169 | ) >actual && | |
4fdf71be | 170 | test_cmp expected actual |
0d042fec JH |
171 | ' |
172 | ||
173 | test_expect_success "grep $L (t-3)" ' | |
174 | echo "${HC}t/t:1:test" >expected && | |
175 | ( | |
176 | cd t && | |
177 | git grep --full-name -n -e test $H | |
178 | ) >actual && | |
4fdf71be | 179 | test_cmp expected actual |
0d042fec JH |
180 | ' |
181 | ||
41ac414e | 182 | test_expect_success "grep -c $L (no /dev/null)" ' |
87539416 | 183 | ! git grep -c test $H | grep /dev/null |
89e64100 | 184 | ' |
d99ebf08 | 185 | |
a91f453f MK |
186 | test_expect_success "grep --max-depth -1 $L" ' |
187 | { | |
188 | echo ${HC}t/a/v:1:vvv | |
189 | echo ${HC}t/v:1:vvv | |
190 | echo ${HC}v:1:vvv | |
191 | } >expected && | |
192 | git grep --max-depth -1 -n -e vvv $H >actual && | |
193 | test_cmp expected actual | |
194 | ' | |
195 | ||
196 | test_expect_success "grep --max-depth 0 $L" ' | |
197 | { | |
198 | echo ${HC}v:1:vvv | |
199 | } >expected && | |
200 | git grep --max-depth 0 -n -e vvv $H >actual && | |
201 | test_cmp expected actual | |
202 | ' | |
203 | ||
204 | test_expect_success "grep --max-depth 0 -- '*' $L" ' | |
205 | { | |
206 | echo ${HC}t/a/v:1:vvv | |
207 | echo ${HC}t/v:1:vvv | |
208 | echo ${HC}v:1:vvv | |
209 | } >expected && | |
210 | git grep --max-depth 0 -n -e vvv $H -- "*" >actual && | |
211 | test_cmp expected actual | |
212 | ' | |
213 | ||
214 | test_expect_success "grep --max-depth 1 $L" ' | |
215 | { | |
216 | echo ${HC}t/v:1:vvv | |
217 | echo ${HC}v:1:vvv | |
218 | } >expected && | |
219 | git grep --max-depth 1 -n -e vvv $H >actual && | |
220 | test_cmp expected actual | |
221 | ' | |
222 | ||
223 | test_expect_success "grep --max-depth 0 -- t $L" ' | |
224 | { | |
225 | echo ${HC}t/v:1:vvv | |
226 | } >expected && | |
227 | git grep --max-depth 0 -n -e vvv $H -- t >actual && | |
228 | test_cmp expected actual | |
229 | ' | |
230 | ||
b31f6880 NTND |
231 | test_expect_success "grep --max-depth 0 -- . t $L" ' |
232 | { | |
233 | echo ${HC}t/v:1:vvv | |
234 | echo ${HC}v:1:vvv | |
235 | } >expected && | |
236 | git grep --max-depth 0 -n -e vvv $H -- . t >actual && | |
237 | test_cmp expected actual | |
238 | ' | |
239 | ||
240 | test_expect_success "grep --max-depth 0 -- t . $L" ' | |
241 | { | |
242 | echo ${HC}t/v:1:vvv | |
243 | echo ${HC}v:1:vvv | |
244 | } >expected && | |
245 | git grep --max-depth 0 -n -e vvv $H -- t . >actual && | |
246 | test_cmp expected actual | |
247 | ' | |
f556e4af | 248 | test_expect_success "grep $L with grep.extendedRegexp=false" ' |
9afad7a1 RS |
249 | echo "${HC}ab:a+bc" >expected && |
250 | git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual && | |
f556e4af MK |
251 | test_cmp expected actual |
252 | ' | |
b31f6880 | 253 | |
f556e4af | 254 | test_expect_success "grep $L with grep.extendedRegexp=true" ' |
9afad7a1 RS |
255 | echo "${HC}ab:abc" >expected && |
256 | git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual && | |
f556e4af MK |
257 | test_cmp expected actual |
258 | ' | |
84befcd0 S |
259 | |
260 | test_expect_success "grep $L with grep.patterntype=basic" ' | |
9afad7a1 RS |
261 | echo "${HC}ab:a+bc" >expected && |
262 | git -c grep.patterntype=basic grep "a+b*c" $H ab >actual && | |
84befcd0 S |
263 | test_cmp expected actual |
264 | ' | |
265 | ||
266 | test_expect_success "grep $L with grep.patterntype=extended" ' | |
9afad7a1 RS |
267 | echo "${HC}ab:abc" >expected && |
268 | git -c grep.patterntype=extended grep "a+b*c" $H ab >actual && | |
84befcd0 S |
269 | test_cmp expected actual |
270 | ' | |
271 | ||
272 | test_expect_success "grep $L with grep.patterntype=fixed" ' | |
9afad7a1 RS |
273 | echo "${HC}ab:a+b*c" >expected && |
274 | git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual && | |
84befcd0 S |
275 | test_cmp expected actual |
276 | ' | |
277 | ||
278 | test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" ' | |
9afad7a1 RS |
279 | echo "${HC}ab:a+b*c" >expected && |
280 | git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" $H ab >actual && | |
84befcd0 S |
281 | test_cmp expected actual |
282 | ' | |
283 | ||
284 | test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" ' | |
9afad7a1 | 285 | echo "${HC}ab:abc" >expected && |
84befcd0 S |
286 | git \ |
287 | -c grep.patternType=default \ | |
288 | -c grep.extendedRegexp=true \ | |
9afad7a1 | 289 | grep "a+b*c" $H ab >actual && |
84befcd0 S |
290 | test_cmp expected actual |
291 | ' | |
292 | ||
293 | test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" ' | |
9afad7a1 | 294 | echo "${HC}ab:abc" >expected && |
84befcd0 S |
295 | git \ |
296 | -c grep.extendedRegexp=true \ | |
297 | -c grep.patternType=default \ | |
9afad7a1 | 298 | grep "a+b*c" $H ab >actual && |
84befcd0 S |
299 | test_cmp expected actual |
300 | ' | |
301 | ||
9afad7a1 RS |
302 | test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" ' |
303 | echo "${HC}ab:abc" >expected && | |
84befcd0 S |
304 | git \ |
305 | -c grep.patternType=extended \ | |
306 | -c grep.extendedRegexp=false \ | |
9afad7a1 | 307 | grep "a+b*c" $H ab >actual && |
84befcd0 S |
308 | test_cmp expected actual |
309 | ' | |
310 | ||
9afad7a1 RS |
311 | test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" ' |
312 | echo "${HC}ab:a+bc" >expected && | |
84befcd0 S |
313 | git \ |
314 | -c grep.patternType=basic \ | |
315 | -c grep.extendedRegexp=true \ | |
9afad7a1 | 316 | grep "a+b*c" $H ab >actual && |
84befcd0 S |
317 | test_cmp expected actual |
318 | ' | |
319 | ||
9afad7a1 RS |
320 | test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" ' |
321 | echo "${HC}ab:abc" >expected && | |
84befcd0 S |
322 | git \ |
323 | -c grep.extendedRegexp=false \ | |
324 | -c grep.patternType=extended \ | |
9afad7a1 | 325 | grep "a+b*c" $H ab >actual && |
84befcd0 S |
326 | test_cmp expected actual |
327 | ' | |
328 | ||
9afad7a1 RS |
329 | test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" ' |
330 | echo "${HC}ab:a+bc" >expected && | |
84befcd0 S |
331 | git \ |
332 | -c grep.extendedRegexp=true \ | |
333 | -c grep.patternType=basic \ | |
9afad7a1 | 334 | grep "a+b*c" $H ab >actual && |
f76d947a RS |
335 | test_cmp expected actual |
336 | ' | |
337 | ||
338 | test_expect_success "grep --count $L" ' | |
339 | echo ${HC}ab:3 >expected && | |
340 | git grep --count -e b $H -- ab >actual && | |
341 | test_cmp expected actual | |
342 | ' | |
343 | ||
344 | test_expect_success "grep --count -h $L" ' | |
345 | echo 3 >expected && | |
346 | git grep --count -h -e b $H -- ab >actual && | |
84befcd0 S |
347 | test_cmp expected actual |
348 | ' | |
f25b7939 JH |
349 | done |
350 | ||
50dd0f2f AY |
351 | cat >expected <<EOF |
352 | file | |
353 | EOF | |
354 | test_expect_success 'grep -l -C' ' | |
355 | git grep -l -C1 foo >actual && | |
356 | test_cmp expected actual | |
357 | ' | |
358 | ||
359 | cat >expected <<EOF | |
360 | file:5 | |
361 | EOF | |
fe0537aa | 362 | test_expect_success 'grep -c -C' ' |
50dd0f2f AY |
363 | git grep -c -C1 foo >actual && |
364 | test_cmp expected actual | |
365 | ' | |
366 | ||
367 | test_expect_success 'grep -L -C' ' | |
368 | git ls-files >expected && | |
369 | git grep -L -C1 nonexistent_string >actual && | |
370 | test_cmp expected actual | |
371 | ' | |
372 | ||
0f705046 TR |
373 | cat >expected <<EOF |
374 | file:foo mmap bar_mmap | |
375 | EOF | |
376 | ||
377 | test_expect_success 'grep -e A --and -e B' ' | |
378 | git grep -e "foo mmap" --and -e bar_mmap >actual && | |
379 | test_cmp expected actual | |
380 | ' | |
381 | ||
382 | cat >expected <<EOF | |
383 | file:foo_mmap bar mmap | |
384 | file:foo_mmap bar mmap baz | |
385 | EOF | |
386 | ||
387 | ||
388 | test_expect_success 'grep ( -e A --or -e B ) --and -e B' ' | |
389 | git grep \( -e foo_ --or -e baz \) \ | |
390 | --and -e " mmap" >actual && | |
391 | test_cmp expected actual | |
392 | ' | |
393 | ||
394 | cat >expected <<EOF | |
395 | file:foo mmap bar | |
396 | EOF | |
397 | ||
398 | test_expect_success 'grep -e A --and --not -e B' ' | |
399 | git grep -e "foo mmap" --and --not -e bar_mmap >actual && | |
400 | test_cmp expected actual | |
401 | ' | |
402 | ||
b4827599 RS |
403 | test_expect_success 'grep should ignore GREP_OPTIONS' ' |
404 | GREP_OPTIONS=-v git grep " mmap bar\$" >actual && | |
405 | test_cmp expected actual | |
406 | ' | |
407 | ||
cfe370c6 MK |
408 | test_expect_success 'grep -f, non-existent file' ' |
409 | test_must_fail git grep -f patterns | |
410 | ' | |
411 | ||
412 | cat >expected <<EOF | |
413 | file:foo mmap bar | |
414 | file:foo_mmap bar | |
415 | file:foo_mmap bar mmap | |
416 | file:foo mmap bar_mmap | |
417 | file:foo_mmap bar mmap baz | |
418 | EOF | |
419 | ||
420 | cat >pattern <<EOF | |
421 | mmap | |
422 | EOF | |
423 | ||
424 | test_expect_success 'grep -f, one pattern' ' | |
425 | git grep -f pattern >actual && | |
426 | test_cmp expected actual | |
427 | ' | |
428 | ||
429 | cat >expected <<EOF | |
430 | file:foo mmap bar | |
431 | file:foo_mmap bar | |
432 | file:foo_mmap bar mmap | |
433 | file:foo mmap bar_mmap | |
434 | file:foo_mmap bar mmap baz | |
435 | t/a/v:vvv | |
436 | t/v:vvv | |
437 | v:vvv | |
438 | EOF | |
439 | ||
440 | cat >patterns <<EOF | |
441 | mmap | |
442 | vvv | |
443 | EOF | |
444 | ||
445 | test_expect_success 'grep -f, multiple patterns' ' | |
446 | git grep -f patterns >actual && | |
447 | test_cmp expected actual | |
448 | ' | |
449 | ||
526a858a RS |
450 | test_expect_success 'grep, multiple patterns' ' |
451 | git grep "$(cat patterns)" >actual && | |
452 | test_cmp expected actual | |
453 | ' | |
454 | ||
cfe370c6 MK |
455 | cat >expected <<EOF |
456 | file:foo mmap bar | |
457 | file:foo_mmap bar | |
458 | file:foo_mmap bar mmap | |
459 | file:foo mmap bar_mmap | |
460 | file:foo_mmap bar mmap baz | |
461 | t/a/v:vvv | |
462 | t/v:vvv | |
463 | v:vvv | |
464 | EOF | |
465 | ||
466 | cat >patterns <<EOF | |
467 | ||
468 | mmap | |
469 | ||
470 | vvv | |
471 | ||
472 | EOF | |
473 | ||
474 | test_expect_success 'grep -f, ignore empty lines' ' | |
475 | git grep -f patterns >actual && | |
476 | test_cmp expected actual | |
477 | ' | |
478 | ||
c41dd2fd RS |
479 | test_expect_success 'grep -f, ignore empty lines, read patterns from stdin' ' |
480 | git grep -f - <patterns >actual && | |
481 | test_cmp expected actual | |
482 | ' | |
483 | ||
046802d0 RS |
484 | cat >expected <<EOF |
485 | y:y yy | |
486 | -- | |
487 | z:zzz | |
488 | EOF | |
489 | ||
4ff61c21 JH |
490 | test_expect_success 'grep -q, silently report matches' ' |
491 | >empty && | |
492 | git grep -q mmap >actual && | |
493 | test_cmp empty actual && | |
494 | test_must_fail git grep -q qfwfq >actual && | |
495 | test_cmp empty actual | |
496 | ' | |
497 | ||
bbc09c22 JH |
498 | test_expect_success 'grep -C1 hunk mark between files' ' |
499 | git grep -C1 "^[yz]" >actual && | |
046802d0 RS |
500 | test_cmp expected actual |
501 | ' | |
502 | ||
a4d7d2c6 JH |
503 | test_expect_success 'log grep setup' ' |
504 | echo a >>file && | |
505 | test_tick && | |
506 | GIT_AUTHOR_NAME="With * Asterisk" \ | |
507 | GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \ | |
508 | git commit -a -m "second" && | |
509 | ||
510 | echo a >>file && | |
511 | test_tick && | |
5aaeb733 | 512 | git commit -a -m "third" && |
a4d7d2c6 | 513 | |
5aaeb733 JH |
514 | echo a >>file && |
515 | test_tick && | |
516 | GIT_AUTHOR_NAME="Night Fall" \ | |
517 | GIT_AUTHOR_EMAIL="nitfol@frobozz.com" \ | |
518 | git commit -a -m "fourth" | |
a4d7d2c6 JH |
519 | ' |
520 | ||
521 | test_expect_success 'log grep (1)' ' | |
522 | git log --author=author --pretty=tformat:%s >actual && | |
b327bf74 MG |
523 | { |
524 | echo third && echo initial | |
525 | } >expect && | |
a4d7d2c6 JH |
526 | test_cmp expect actual |
527 | ' | |
528 | ||
529 | test_expect_success 'log grep (2)' ' | |
530 | git log --author=" * " -F --pretty=tformat:%s >actual && | |
b327bf74 MG |
531 | { |
532 | echo second | |
533 | } >expect && | |
a4d7d2c6 JH |
534 | test_cmp expect actual |
535 | ' | |
536 | ||
537 | test_expect_success 'log grep (3)' ' | |
538 | git log --author="^A U" --pretty=tformat:%s >actual && | |
b327bf74 MG |
539 | { |
540 | echo third && echo initial | |
541 | } >expect && | |
a4d7d2c6 JH |
542 | test_cmp expect actual |
543 | ' | |
544 | ||
545 | test_expect_success 'log grep (4)' ' | |
546 | git log --author="frotz\.com>$" --pretty=tformat:%s >actual && | |
b327bf74 MG |
547 | { |
548 | echo second | |
549 | } >expect && | |
a4d7d2c6 JH |
550 | test_cmp expect actual |
551 | ' | |
552 | ||
553 | test_expect_success 'log grep (5)' ' | |
80235ba7 | 554 | git log --author=Thor -F --pretty=tformat:%s >actual && |
b327bf74 MG |
555 | { |
556 | echo third && echo initial | |
557 | } >expect && | |
a4d7d2c6 JH |
558 | test_cmp expect actual |
559 | ' | |
560 | ||
561 | test_expect_success 'log grep (6)' ' | |
562 | git log --author=-0700 --pretty=tformat:%s >actual && | |
563 | >expect && | |
564 | test_cmp expect actual | |
57d43466 | 565 | ' |
a4d7d2c6 | 566 | |
72fd13f7 NTND |
567 | test_expect_success 'log grep (7)' ' |
568 | git log -g --grep-reflog="commit: third" --pretty=tformat:%s >actual && | |
569 | echo third >expect && | |
570 | test_cmp expect actual | |
571 | ' | |
572 | ||
573 | test_expect_success 'log grep (8)' ' | |
574 | git log -g --grep-reflog="commit: third" --grep-reflog="commit: second" --pretty=tformat:%s >actual && | |
575 | { | |
576 | echo third && echo second | |
577 | } >expect && | |
578 | test_cmp expect actual | |
579 | ' | |
580 | ||
581 | test_expect_success 'log grep (9)' ' | |
582 | git log -g --grep-reflog="commit: third" --author="Thor" --pretty=tformat:%s >actual && | |
583 | echo third >expect && | |
584 | test_cmp expect actual | |
585 | ' | |
586 | ||
587 | test_expect_success 'log grep (9)' ' | |
2e3a16b2 | 588 | git log -g --grep-reflog="commit: third" --author="non-existent" --pretty=tformat:%s >actual && |
72fd13f7 NTND |
589 | : >expect && |
590 | test_cmp expect actual | |
591 | ' | |
592 | ||
baa6378f JH |
593 | test_expect_success 'log --grep-reflog can only be used under -g' ' |
594 | test_must_fail git log --grep-reflog="commit: third" | |
595 | ' | |
596 | ||
dfe36425 MG |
597 | test_expect_success 'log with multiple --grep uses union' ' |
598 | git log --grep=i --grep=r --format=%s >actual && | |
599 | { | |
600 | echo fourth && echo third && echo initial | |
601 | } >expect && | |
602 | test_cmp expect actual | |
603 | ' | |
604 | ||
605 | test_expect_success 'log --all-match with multiple --grep uses intersection' ' | |
606 | git log --all-match --grep=i --grep=r --format=%s >actual && | |
607 | { | |
608 | echo third | |
609 | } >expect && | |
80235ba7 JH |
610 | test_cmp expect actual |
611 | ' | |
612 | ||
5aaeb733 JH |
613 | test_expect_success 'log with multiple --author uses union' ' |
614 | git log --author="Thor" --author="Aster" --format=%s >actual && | |
615 | { | |
616 | echo third && echo second && echo initial | |
617 | } >expect && | |
618 | test_cmp expect actual | |
619 | ' | |
620 | ||
00f62a64 MG |
621 | test_expect_success 'log --all-match with multiple --author still uses union' ' |
622 | git log --all-match --author="Thor" --author="Aster" --format=%s >actual && | |
623 | { | |
624 | echo third && echo second && echo initial | |
625 | } >expect && | |
626 | test_cmp expect actual | |
627 | ' | |
628 | ||
2cb03e76 MG |
629 | test_expect_success 'log --grep --author uses intersection' ' |
630 | # grep matches only third and fourth | |
631 | # author matches only initial and third | |
632 | git log --author="A U Thor" --grep=r --format=%s >actual && | |
5aaeb733 | 633 | { |
2cb03e76 | 634 | echo third |
5aaeb733 JH |
635 | } >expect && |
636 | test_cmp expect actual | |
637 | ' | |
638 | ||
2cb03e76 MG |
639 | test_expect_success 'log --grep --grep --author takes union of greps and intersects with author' ' |
640 | # grep matches initial and second but not third | |
641 | # author matches only initial and third | |
642 | git log --author="A U Thor" --grep=s --grep=l --format=%s >actual && | |
643 | { | |
644 | echo initial | |
645 | } >expect && | |
646 | test_cmp expect actual | |
647 | ' | |
648 | ||
39f2e017 MG |
649 | test_expect_success 'log ---all-match -grep --author --author still takes union of authors and intersects with grep' ' |
650 | # grep matches only initial and third | |
651 | # author matches all but second | |
652 | git log --all-match --author="Thor" --author="Night" --grep=i --format=%s >actual && | |
653 | { | |
654 | echo third && echo initial | |
655 | } >expect && | |
656 | test_cmp expect actual | |
657 | ' | |
658 | ||
2cb03e76 MG |
659 | test_expect_success 'log --grep --author --author takes union of authors and intersects with grep' ' |
660 | # grep matches only initial and third | |
661 | # author matches all but second | |
5aaeb733 JH |
662 | git log --author="Thor" --author="Night" --grep=i --format=%s >actual && |
663 | { | |
664 | echo third && echo initial | |
665 | } >expect && | |
666 | test_cmp expect actual | |
667 | ' | |
668 | ||
39f2e017 MG |
669 | test_expect_success 'log --all-match --grep --grep --author takes intersection' ' |
670 | # grep matches only third | |
671 | # author matches only initial and third | |
672 | git log --all-match --author="A U Thor" --grep=i --grep=r --format=%s >actual && | |
673 | { | |
674 | echo third | |
675 | } >expect && | |
5aaeb733 JH |
676 | test_cmp expect actual |
677 | ' | |
678 | ||
ad4813b3 NTND |
679 | test_expect_success 'log --author does not search in timestamp' ' |
680 | : >expect && | |
681 | git log --author="$GIT_AUTHOR_DATE" >actual && | |
682 | test_cmp expect actual | |
683 | ' | |
684 | ||
685 | test_expect_success 'log --committer does not search in timestamp' ' | |
686 | : >expect && | |
687 | git log --committer="$GIT_COMMITTER_DATE" >actual && | |
688 | test_cmp expect actual | |
689 | ' | |
690 | ||
57d43466 NTND |
691 | test_expect_success 'grep with CE_VALID file' ' |
692 | git update-index --assume-unchanged t/t && | |
693 | rm t/t && | |
bbc09c22 | 694 | test "$(git grep test)" = "t/t:test" && |
57d43466 NTND |
695 | git update-index --no-assume-unchanged t/t && |
696 | git checkout t/t | |
a4d7d2c6 JH |
697 | ' |
698 | ||
60ecac98 RS |
699 | cat >expected <<EOF |
700 | hello.c=#include <stdio.h> | |
701 | hello.c: return 0; | |
702 | EOF | |
703 | ||
704 | test_expect_success 'grep -p with userdiff' ' | |
705 | git config diff.custom.funcname "^#" && | |
706 | echo "hello.c diff=custom" >.gitattributes && | |
707 | git grep -p return >actual && | |
708 | test_cmp expected actual | |
709 | ' | |
710 | ||
2944e4e6 RS |
711 | cat >expected <<EOF |
712 | hello.c=int main(int argc, const char **argv) | |
713 | hello.c: return 0; | |
714 | EOF | |
715 | ||
716 | test_expect_success 'grep -p' ' | |
60ecac98 | 717 | rm -f .gitattributes && |
2944e4e6 RS |
718 | git grep -p return >actual && |
719 | test_cmp expected actual | |
720 | ' | |
721 | ||
722 | cat >expected <<EOF | |
723 | hello.c-#include <stdio.h> | |
799e09e5 | 724 | hello.c- |
2944e4e6 RS |
725 | hello.c=int main(int argc, const char **argv) |
726 | hello.c-{ | |
727 | hello.c- printf("Hello world.\n"); | |
728 | hello.c: return 0; | |
729 | EOF | |
730 | ||
731 | test_expect_success 'grep -p -B5' ' | |
732 | git grep -p -B5 return >actual && | |
733 | test_cmp expected actual | |
734 | ' | |
735 | ||
ba8ea749 RS |
736 | cat >expected <<EOF |
737 | hello.c=int main(int argc, const char **argv) | |
738 | hello.c-{ | |
739 | hello.c- printf("Hello world.\n"); | |
740 | hello.c: return 0; | |
741 | hello.c- /* char ?? */ | |
742 | hello.c-} | |
743 | EOF | |
744 | ||
745 | test_expect_success 'grep -W' ' | |
746 | git grep -W return >actual && | |
747 | test_cmp expected actual | |
b8ffedca TR |
748 | ' |
749 | ||
799e09e5 RS |
750 | cat >expected <<EOF |
751 | hello.c-#include <assert.h> | |
752 | hello.c:#include <stdio.h> | |
753 | EOF | |
754 | ||
4aa2c475 | 755 | test_expect_success 'grep -W shows no trailing empty lines' ' |
799e09e5 RS |
756 | git grep -W stdio >actual && |
757 | test_cmp expected actual | |
758 | ' | |
759 | ||
b8ffedca TR |
760 | cat >expected <<EOF |
761 | hello.c= printf("Hello world.\n"); | |
762 | hello.c: return 0; | |
763 | hello.c- /* char ?? */ | |
764 | EOF | |
765 | ||
766 | test_expect_success 'grep -W with userdiff' ' | |
767 | test_when_finished "rm -f .gitattributes" && | |
768 | git config diff.custom.xfuncname "(printf.*|})$" && | |
769 | echo "hello.c diff=custom" >.gitattributes && | |
770 | git grep -W return >actual && | |
771 | test_cmp expected actual | |
ba8ea749 RS |
772 | ' |
773 | ||
493b7a08 CB |
774 | test_expect_success 'grep from a subdirectory to search wider area (1)' ' |
775 | mkdir -p s && | |
776 | ( | |
777 | cd s && git grep "x x x" .. | |
778 | ) | |
779 | ' | |
780 | ||
781 | test_expect_success 'grep from a subdirectory to search wider area (2)' ' | |
782 | mkdir -p s && | |
783 | ( | |
784 | cd s || exit 1 | |
785 | ( git grep xxyyzz .. >out ; echo $? >status ) | |
786 | ! test -s out && | |
787 | test 1 = $(cat status) | |
788 | ) | |
789 | ' | |
790 | ||
5183bf67 BC |
791 | cat >expected <<EOF |
792 | hello.c:int main(int argc, const char **argv) | |
793 | EOF | |
794 | ||
795 | test_expect_success 'grep -Fi' ' | |
796 | git grep -Fi "CHAR *" >actual && | |
797 | test_cmp expected actual | |
798 | ' | |
799 | ||
59332d13 JH |
800 | test_expect_success 'outside of git repository' ' |
801 | rm -fr non && | |
802 | mkdir -p non/git/sub && | |
803 | echo hello >non/git/file1 && | |
804 | echo world >non/git/sub/file2 && | |
59332d13 JH |
805 | { |
806 | echo file1:hello && | |
807 | echo sub/file2:world | |
808 | } >non/expect.full && | |
a48fcd83 | 809 | echo file2:world >non/expect.sub && |
59332d13 | 810 | ( |
1f5101ae | 811 | GIT_CEILING_DIRECTORIES="$(pwd)/non" && |
59332d13 JH |
812 | export GIT_CEILING_DIRECTORIES && |
813 | cd non/git && | |
814 | test_must_fail git grep o && | |
815 | git grep --no-index o >../actual.full && | |
1f5101ae | 816 | test_cmp ../expect.full ../actual.full && |
59332d13 JH |
817 | cd sub && |
818 | test_must_fail git grep o && | |
819 | git grep --no-index o >../../actual.sub && | |
820 | test_cmp ../../expect.sub ../../actual.sub | |
0a93fb8a JH |
821 | ) && |
822 | ||
823 | echo ".*o*" >non/git/.gitignore && | |
824 | ( | |
1f5101ae | 825 | GIT_CEILING_DIRECTORIES="$(pwd)/non" && |
0a93fb8a JH |
826 | export GIT_CEILING_DIRECTORIES && |
827 | cd non/git && | |
828 | test_must_fail git grep o && | |
829 | git grep --no-index --exclude-standard o >../actual.full && | |
830 | test_cmp ../expect.full ../actual.full && | |
831 | ||
832 | { | |
1f5101ae | 833 | echo ".gitignore:.*o*" && |
0a93fb8a JH |
834 | cat ../expect.full |
835 | } >../expect.with.ignored && | |
836 | git grep --no-index --no-exclude o >../actual.full && | |
837 | test_cmp ../expect.with.ignored ../actual.full | |
59332d13 JH |
838 | ) |
839 | ' | |
840 | ||
ecd9ba61 TG |
841 | test_expect_success 'outside of git repository with fallbackToNoIndex' ' |
842 | rm -fr non && | |
843 | mkdir -p non/git/sub && | |
844 | echo hello >non/git/file1 && | |
845 | echo world >non/git/sub/file2 && | |
846 | cat <<-\EOF >non/expect.full && | |
847 | file1:hello | |
848 | sub/file2:world | |
849 | EOF | |
850 | echo file2:world >non/expect.sub && | |
851 | ( | |
852 | GIT_CEILING_DIRECTORIES="$(pwd)/non" && | |
853 | export GIT_CEILING_DIRECTORIES && | |
854 | cd non/git && | |
855 | test_must_fail git -c grep.fallbackToNoIndex=false grep o && | |
856 | git -c grep.fallbackToNoIndex=true grep o >../actual.full && | |
857 | test_cmp ../expect.full ../actual.full && | |
858 | cd sub && | |
859 | test_must_fail git -c grep.fallbackToNoIndex=false grep o && | |
860 | git -c grep.fallbackToNoIndex=true grep o >../../actual.sub && | |
861 | test_cmp ../../expect.sub ../../actual.sub | |
862 | ) && | |
863 | ||
864 | echo ".*o*" >non/git/.gitignore && | |
865 | ( | |
866 | GIT_CEILING_DIRECTORIES="$(pwd)/non" && | |
867 | export GIT_CEILING_DIRECTORIES && | |
868 | cd non/git && | |
869 | test_must_fail git -c grep.fallbackToNoIndex=false grep o && | |
870 | git -c grep.fallbackToNoIndex=true grep --exclude-standard o >../actual.full && | |
871 | test_cmp ../expect.full ../actual.full && | |
872 | ||
873 | { | |
874 | echo ".gitignore:.*o*" && | |
875 | cat ../expect.full | |
876 | } >../expect.with.ignored && | |
877 | git -c grep.fallbackToNoIndex grep --no-exclude o >../actual.full && | |
878 | test_cmp ../expect.with.ignored ../actual.full | |
879 | ) | |
880 | ' | |
881 | ||
59332d13 JH |
882 | test_expect_success 'inside git repository but with --no-index' ' |
883 | rm -fr is && | |
884 | mkdir -p is/git/sub && | |
885 | echo hello >is/git/file1 && | |
886 | echo world >is/git/sub/file2 && | |
887 | echo ".*o*" >is/git/.gitignore && | |
888 | { | |
889 | echo file1:hello && | |
890 | echo sub/file2:world | |
0a93fb8a JH |
891 | } >is/expect.unignored && |
892 | { | |
893 | echo ".gitignore:.*o*" && | |
894 | cat is/expect.unignored | |
59332d13 JH |
895 | } >is/expect.full && |
896 | : >is/expect.empty && | |
a48fcd83 | 897 | echo file2:world >is/expect.sub && |
59332d13 JH |
898 | ( |
899 | cd is/git && | |
900 | git init && | |
901 | test_must_fail git grep o >../actual.full && | |
902 | test_cmp ../expect.empty ../actual.full && | |
0a93fb8a JH |
903 | |
904 | git grep --untracked o >../actual.unignored && | |
905 | test_cmp ../expect.unignored ../actual.unignored && | |
906 | ||
59332d13 JH |
907 | git grep --no-index o >../actual.full && |
908 | test_cmp ../expect.full ../actual.full && | |
0a93fb8a JH |
909 | |
910 | git grep --no-index --exclude-standard o >../actual.unignored && | |
911 | test_cmp ../expect.unignored ../actual.unignored && | |
912 | ||
59332d13 JH |
913 | cd sub && |
914 | test_must_fail git grep o >../../actual.sub && | |
915 | test_cmp ../../expect.empty ../../actual.sub && | |
0a93fb8a | 916 | |
59332d13 | 917 | git grep --no-index o >../../actual.sub && |
0a93fb8a JH |
918 | test_cmp ../../expect.sub ../../actual.sub && |
919 | ||
920 | git grep --untracked o >../../actual.sub && | |
59332d13 JH |
921 | test_cmp ../../expect.sub ../../actual.sub |
922 | ) | |
923 | ' | |
924 | ||
85975c0c JK |
925 | test_expect_success 'grep --no-index descends into repos, but not .git' ' |
926 | rm -fr non && | |
927 | mkdir -p non/git && | |
928 | ( | |
929 | GIT_CEILING_DIRECTORIES="$(pwd)/non" && | |
930 | export GIT_CEILING_DIRECTORIES && | |
931 | cd non/git && | |
932 | ||
933 | echo magic >file && | |
934 | git init repo && | |
935 | ( | |
936 | cd repo && | |
937 | echo magic >file && | |
938 | git add file && | |
939 | git commit -m foo && | |
940 | echo magic >.git/file | |
941 | ) && | |
942 | ||
943 | cat >expect <<-\EOF && | |
944 | file | |
945 | repo/file | |
946 | EOF | |
947 | git grep -l --no-index magic >actual && | |
948 | test_cmp expect actual | |
949 | ) | |
950 | ' | |
951 | ||
1123c67c JK |
952 | test_expect_success 'setup double-dash tests' ' |
953 | cat >double-dash <<EOF && | |
954 | -- | |
955 | -> | |
956 | other | |
957 | EOF | |
958 | git add double-dash | |
959 | ' | |
960 | ||
961 | cat >expected <<EOF | |
962 | double-dash:-> | |
963 | EOF | |
964 | test_expect_success 'grep -- pattern' ' | |
965 | git grep -- "->" >actual && | |
966 | test_cmp expected actual | |
967 | ' | |
968 | test_expect_success 'grep -- pattern -- pathspec' ' | |
969 | git grep -- "->" -- double-dash >actual && | |
970 | test_cmp expected actual | |
971 | ' | |
972 | test_expect_success 'grep -e pattern -- path' ' | |
973 | git grep -e "->" -- double-dash >actual && | |
974 | test_cmp expected actual | |
975 | ' | |
976 | ||
977 | cat >expected <<EOF | |
978 | double-dash:-- | |
979 | EOF | |
980 | test_expect_success 'grep -e -- -- path' ' | |
981 | git grep -e -- -- double-dash >actual && | |
982 | test_cmp expected actual | |
983 | ' | |
984 | ||
dca3b5f5 JT |
985 | test_expect_success 'grep --no-index pattern -- path' ' |
986 | rm -fr non && | |
987 | mkdir -p non/git && | |
988 | ( | |
989 | GIT_CEILING_DIRECTORIES="$(pwd)/non" && | |
990 | export GIT_CEILING_DIRECTORIES && | |
991 | cd non/git && | |
992 | echo hello >hello && | |
993 | echo goodbye >goodbye && | |
994 | echo hello:hello >expect && | |
995 | git grep --no-index o -- hello >actual && | |
996 | test_cmp expect actual | |
997 | ) | |
998 | ' | |
999 | ||
8f852ce6 MK |
1000 | cat >expected <<EOF |
1001 | hello.c:int main(int argc, const char **argv) | |
1002 | hello.c: printf("Hello world.\n"); | |
1003 | EOF | |
1004 | ||
1005 | test_expect_success LIBPCRE 'grep --perl-regexp pattern' ' | |
1006 | git grep --perl-regexp "\p{Ps}.*?\p{Pe}" hello.c >actual && | |
1007 | test_cmp expected actual | |
1008 | ' | |
1009 | ||
1010 | test_expect_success LIBPCRE 'grep -P pattern' ' | |
1011 | git grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual && | |
1012 | test_cmp expected actual | |
1013 | ' | |
1014 | ||
f556e4af | 1015 | test_expect_success 'grep pattern with grep.extendedRegexp=true' ' |
d0042abe | 1016 | >empty && |
f556e4af MK |
1017 | test_must_fail git -c grep.extendedregexp=true \ |
1018 | grep "\p{Ps}.*?\p{Pe}" hello.c >actual && | |
1019 | test_cmp empty actual | |
1020 | ' | |
1021 | ||
1022 | test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' ' | |
1023 | git -c grep.extendedregexp=true \ | |
1024 | grep -P "\p{Ps}.*?\p{Pe}" hello.c >actual && | |
1025 | test_cmp expected actual | |
1026 | ' | |
1027 | ||
1028 | test_expect_success LIBPCRE 'grep -P -v pattern' ' | |
1029 | { | |
d0042abe MK |
1030 | echo "ab:a+b*c" |
1031 | echo "ab:a+bc" | |
f556e4af | 1032 | } >expected && |
d0042abe | 1033 | git grep -P -v "abc" ab >actual && |
f556e4af MK |
1034 | test_cmp expected actual |
1035 | ' | |
1036 | ||
8f852ce6 | 1037 | test_expect_success LIBPCRE 'grep -P -i pattern' ' |
93d5e0c2 JH |
1038 | cat >expected <<-EOF && |
1039 | hello.c: printf("Hello world.\n"); | |
1040 | EOF | |
8f852ce6 MK |
1041 | git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual && |
1042 | test_cmp expected actual | |
1043 | ' | |
1044 | ||
1045 | test_expect_success LIBPCRE 'grep -P -w pattern' ' | |
1046 | { | |
1047 | echo "hello_world:Hello world" | |
1048 | echo "hello_world:HeLLo world" | |
1049 | } >expected && | |
1050 | git grep -P -w "He((?i)ll)o" hello_world >actual && | |
1051 | test_cmp expected actual | |
1052 | ' | |
1053 | ||
f556e4af MK |
1054 | test_expect_success 'grep -G invalidpattern properly dies ' ' |
1055 | test_must_fail git grep -G "a[" | |
1056 | ' | |
1057 | ||
84befcd0 S |
1058 | test_expect_success 'grep invalidpattern properly dies with grep.patternType=basic' ' |
1059 | test_must_fail git -c grep.patterntype=basic grep "a[" | |
1060 | ' | |
1061 | ||
f556e4af MK |
1062 | test_expect_success 'grep -E invalidpattern properly dies ' ' |
1063 | test_must_fail git grep -E "a[" | |
1064 | ' | |
1065 | ||
84befcd0 S |
1066 | test_expect_success 'grep invalidpattern properly dies with grep.patternType=extended' ' |
1067 | test_must_fail git -c grep.patterntype=extended grep "a[" | |
1068 | ' | |
1069 | ||
f556e4af MK |
1070 | test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' ' |
1071 | test_must_fail git grep -P "a[" | |
1072 | ' | |
1073 | ||
84befcd0 S |
1074 | test_expect_success LIBPCRE 'grep invalidpattern properly dies with grep.patternType=perl' ' |
1075 | test_must_fail git -c grep.patterntype=perl grep "a[" | |
1076 | ' | |
1077 | ||
d0042abe MK |
1078 | test_expect_success 'grep -G -E -F pattern' ' |
1079 | echo "ab:a+b*c" >expected && | |
1080 | git grep -G -E -F "a+b*c" ab >actual && | |
f556e4af MK |
1081 | test_cmp expected actual |
1082 | ' | |
1083 | ||
84befcd0 S |
1084 | test_expect_success 'grep pattern with grep.patternType=basic, =extended, =fixed' ' |
1085 | echo "ab:a+b*c" >expected && | |
1086 | git \ | |
1087 | -c grep.patterntype=basic \ | |
1088 | -c grep.patterntype=extended \ | |
1089 | -c grep.patterntype=fixed \ | |
1090 | grep "a+b*c" ab >actual && | |
1091 | test_cmp expected actual | |
1092 | ' | |
1093 | ||
f556e4af | 1094 | test_expect_success 'grep -E -F -G pattern' ' |
d0042abe MK |
1095 | echo "ab:a+bc" >expected && |
1096 | git grep -E -F -G "a+b*c" ab >actual && | |
f556e4af MK |
1097 | test_cmp expected actual |
1098 | ' | |
1099 | ||
84befcd0 S |
1100 | test_expect_success 'grep pattern with grep.patternType=extended, =fixed, =basic' ' |
1101 | echo "ab:a+bc" >expected && | |
1102 | git \ | |
1103 | -c grep.patterntype=extended \ | |
1104 | -c grep.patterntype=fixed \ | |
1105 | -c grep.patterntype=basic \ | |
1106 | grep "a+b*c" ab >actual && | |
1107 | test_cmp expected actual | |
1108 | ' | |
1109 | ||
d0042abe MK |
1110 | test_expect_success 'grep -F -G -E pattern' ' |
1111 | echo "ab:abc" >expected && | |
1112 | git grep -F -G -E "a+b*c" ab >actual && | |
f556e4af MK |
1113 | test_cmp expected actual |
1114 | ' | |
1115 | ||
84befcd0 S |
1116 | test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =extended' ' |
1117 | echo "ab:abc" >expected && | |
1118 | git \ | |
1119 | -c grep.patterntype=fixed \ | |
1120 | -c grep.patterntype=basic \ | |
1121 | -c grep.patterntype=extended \ | |
1122 | grep "a+b*c" ab >actual && | |
1123 | test_cmp expected actual | |
1124 | ' | |
1125 | ||
d0042abe | 1126 | test_expect_success 'grep -G -F -P -E pattern' ' |
7675c7bd JK |
1127 | echo "d0:d" >expected && |
1128 | git grep -G -F -P -E "[\d]" d0 >actual && | |
1129 | test_cmp expected actual | |
f556e4af MK |
1130 | ' |
1131 | ||
84befcd0 | 1132 | test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =extended' ' |
7675c7bd JK |
1133 | echo "d0:d" >expected && |
1134 | git \ | |
84befcd0 S |
1135 | -c grep.patterntype=fixed \ |
1136 | -c grep.patterntype=basic \ | |
1137 | -c grep.patterntype=perl \ | |
1138 | -c grep.patterntype=extended \ | |
7675c7bd JK |
1139 | grep "[\d]" d0 >actual && |
1140 | test_cmp expected actual | |
84befcd0 S |
1141 | ' |
1142 | ||
d0042abe | 1143 | test_expect_success LIBPCRE 'grep -G -F -E -P pattern' ' |
7675c7bd JK |
1144 | echo "d0:0" >expected && |
1145 | git grep -G -F -E -P "[\d]" d0 >actual && | |
f556e4af MK |
1146 | test_cmp expected actual |
1147 | ' | |
1148 | ||
84befcd0 | 1149 | test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' ' |
7675c7bd | 1150 | echo "d0:0" >expected && |
84befcd0 S |
1151 | git \ |
1152 | -c grep.patterntype=fixed \ | |
1153 | -c grep.patterntype=basic \ | |
1154 | -c grep.patterntype=extended \ | |
1155 | -c grep.patterntype=perl \ | |
7675c7bd | 1156 | grep "[\d]" d0 >actual && |
84befcd0 S |
1157 | test_cmp expected actual |
1158 | ' | |
1159 | ||
1160 | test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' ' | |
1161 | echo "ab:a+b*c" >expected && | |
1162 | git \ | |
1163 | -c grep.patterntype=fixed \ | |
1164 | grep -P "a\x{2b}b\x{2a}c" ab >actual && | |
1165 | test_cmp expected actual | |
1166 | ' | |
1167 | ||
1168 | test_expect_success 'grep -F pattern with grep.patternType=basic' ' | |
1169 | echo "ab:a+b*c" >expected && | |
1170 | git \ | |
1171 | -c grep.patterntype=basic \ | |
1172 | grep -F "*c" ab >actual && | |
1173 | test_cmp expected actual | |
1174 | ' | |
1175 | ||
1176 | test_expect_success 'grep -G pattern with grep.patternType=fixed' ' | |
1177 | { | |
1178 | echo "ab:a+b*c" | |
1179 | echo "ab:a+bc" | |
1180 | } >expected && | |
1181 | git \ | |
1182 | -c grep.patterntype=fixed \ | |
1183 | grep -G "a+b" ab >actual && | |
1184 | test_cmp expected actual | |
1185 | ' | |
1186 | ||
1187 | test_expect_success 'grep -E pattern with grep.patternType=fixed' ' | |
1188 | { | |
1189 | echo "ab:a+b*c" | |
1190 | echo "ab:a+bc" | |
1191 | echo "ab:abc" | |
1192 | } >expected && | |
1193 | git \ | |
1194 | -c grep.patterntype=fixed \ | |
1195 | grep -E "a+" ab >actual && | |
1196 | test_cmp expected actual | |
1197 | ' | |
1198 | ||
08303c36 RS |
1199 | cat >expected <<EOF |
1200 | hello.c<RED>:<RESET>int main(int argc, const char **argv) | |
1201 | hello.c<RED>-<RESET>{ | |
1202 | <RED>--<RESET> | |
1203 | hello.c<RED>:<RESET> /* char ?? */ | |
1204 | hello.c<RED>-<RESET>} | |
1205 | <RED>--<RESET> | |
1206 | hello_world<RED>:<RESET>Hello_world | |
1207 | hello_world<RED>-<RESET>HeLLo_world | |
1208 | EOF | |
1209 | ||
1210 | test_expect_success 'grep --color, separator' ' | |
1211 | test_config color.grep.context normal && | |
1212 | test_config color.grep.filename normal && | |
1213 | test_config color.grep.function normal && | |
1214 | test_config color.grep.linenumber normal && | |
1215 | test_config color.grep.match normal && | |
1216 | test_config color.grep.selected normal && | |
1217 | test_config color.grep.separator red && | |
1218 | ||
1219 | git grep --color=always -A1 -e char -e lo_w hello.c hello_world | | |
1220 | test_decode_color >actual && | |
1221 | test_cmp expected actual | |
1222 | ' | |
1223 | ||
a8f0e764 RS |
1224 | cat >expected <<EOF |
1225 | hello.c:int main(int argc, const char **argv) | |
1226 | hello.c: /* char ?? */ | |
1227 | ||
1228 | hello_world:Hello_world | |
1229 | EOF | |
1230 | ||
1231 | test_expect_success 'grep --break' ' | |
1232 | git grep --break -e char -e lo_w hello.c hello_world >actual && | |
1233 | test_cmp expected actual | |
1234 | ' | |
1235 | ||
1236 | cat >expected <<EOF | |
1237 | hello.c:int main(int argc, const char **argv) | |
1238 | hello.c-{ | |
1239 | -- | |
1240 | hello.c: /* char ?? */ | |
1241 | hello.c-} | |
1242 | ||
1243 | hello_world:Hello_world | |
1244 | hello_world-HeLLo_world | |
1245 | EOF | |
1246 | ||
1247 | test_expect_success 'grep --break with context' ' | |
1248 | git grep --break -A1 -e char -e lo_w hello.c hello_world >actual && | |
1249 | test_cmp expected actual | |
1250 | ' | |
1251 | ||
1d84f72e RS |
1252 | cat >expected <<EOF |
1253 | hello.c | |
1254 | int main(int argc, const char **argv) | |
1255 | /* char ?? */ | |
1256 | hello_world | |
1257 | Hello_world | |
1258 | EOF | |
1259 | ||
1260 | test_expect_success 'grep --heading' ' | |
1261 | git grep --heading -e char -e lo_w hello.c hello_world >actual && | |
1262 | test_cmp expected actual | |
1263 | ' | |
1264 | ||
1265 | cat >expected <<EOF | |
1266 | <BOLD;GREEN>hello.c<RESET> | |
799e09e5 RS |
1267 | 4:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv) |
1268 | 8: /* <BLACK;BYELLOW>char<RESET> ?? */ | |
1d84f72e RS |
1269 | |
1270 | <BOLD;GREEN>hello_world<RESET> | |
1271 | 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld | |
1272 | EOF | |
1273 | ||
1274 | test_expect_success 'mimic ack-grep --group' ' | |
1275 | test_config color.grep.context normal && | |
1276 | test_config color.grep.filename "bold green" && | |
1277 | test_config color.grep.function normal && | |
1278 | test_config color.grep.linenumber normal && | |
1279 | test_config color.grep.match "black yellow" && | |
1280 | test_config color.grep.selected normal && | |
1281 | test_config color.grep.separator normal && | |
1282 | ||
1283 | git grep --break --heading -n --color \ | |
1284 | -e char -e lo_w hello.c hello_world | | |
1285 | test_decode_color >actual && | |
1286 | test_cmp expected actual | |
1287 | ' | |
1288 | ||
d29d787c MK |
1289 | cat >expected <<EOF |
1290 | space: line with leading space1 | |
1291 | space: line with leading space2 | |
1292 | space: line with leading space3 | |
1293 | EOF | |
1294 | ||
1295 | test_expect_success LIBPCRE 'grep -E "^ "' ' | |
1296 | git grep -E "^ " space >actual && | |
1297 | test_cmp expected actual | |
1298 | ' | |
1299 | ||
1300 | test_expect_success LIBPCRE 'grep -P "^ "' ' | |
1301 | git grep -P "^ " space >actual && | |
1302 | test_cmp expected actual | |
1303 | ' | |
1304 | ||
79a77109 RS |
1305 | cat >expected <<EOF |
1306 | space-line without leading space1 | |
1307 | space: line <RED>with <RESET>leading space1 | |
1308 | space: line <RED>with <RESET>leading <RED>space2<RESET> | |
1309 | space: line <RED>with <RESET>leading space3 | |
1310 | space:line without leading <RED>space2<RESET> | |
1311 | EOF | |
1312 | ||
1313 | test_expect_success 'grep --color -e A -e B with context' ' | |
1314 | test_config color.grep.context normal && | |
1315 | test_config color.grep.filename normal && | |
1316 | test_config color.grep.function normal && | |
1317 | test_config color.grep.linenumber normal && | |
1318 | test_config color.grep.matchContext normal && | |
1319 | test_config color.grep.matchSelected red && | |
1320 | test_config color.grep.selected normal && | |
1321 | test_config color.grep.separator normal && | |
1322 | ||
1323 | git grep --color=always -C2 -e "with " -e space2 space | | |
1324 | test_decode_color >actual && | |
1325 | test_cmp expected actual | |
1326 | ' | |
1327 | ||
1328 | cat >expected <<EOF | |
1329 | space-line without leading space1 | |
1330 | space- line with leading space1 | |
1331 | space: line <RED>with <RESET>leading <RED>space2<RESET> | |
1332 | space- line with leading space3 | |
1333 | space-line without leading space2 | |
1334 | EOF | |
1335 | ||
1336 | test_expect_success 'grep --color -e A --and -e B with context' ' | |
1337 | test_config color.grep.context normal && | |
1338 | test_config color.grep.filename normal && | |
1339 | test_config color.grep.function normal && | |
1340 | test_config color.grep.linenumber normal && | |
1341 | test_config color.grep.matchContext normal && | |
1342 | test_config color.grep.matchSelected red && | |
1343 | test_config color.grep.selected normal && | |
1344 | test_config color.grep.separator normal && | |
1345 | ||
1346 | git grep --color=always -C2 -e "with " --and -e space2 space | | |
1347 | test_decode_color >actual && | |
1348 | test_cmp expected actual | |
1349 | ' | |
1350 | ||
1351 | cat >expected <<EOF | |
1352 | space-line without leading space1 | |
1353 | space: line <RED>with <RESET>leading space1 | |
1354 | space- line with leading space2 | |
1355 | space: line <RED>with <RESET>leading space3 | |
1356 | space-line without leading space2 | |
1357 | EOF | |
1358 | ||
1359 | test_expect_success 'grep --color -e A --and --not -e B with context' ' | |
1360 | test_config color.grep.context normal && | |
1361 | test_config color.grep.filename normal && | |
1362 | test_config color.grep.function normal && | |
1363 | test_config color.grep.linenumber normal && | |
1364 | test_config color.grep.matchContext normal && | |
1365 | test_config color.grep.matchSelected red && | |
1366 | test_config color.grep.selected normal && | |
1367 | test_config color.grep.separator normal && | |
1368 | ||
1369 | git grep --color=always -C2 -e "with " --and --not -e space2 space | | |
1370 | test_decode_color >actual && | |
1371 | test_cmp expected actual | |
1372 | ' | |
1373 | ||
1374 | cat >expected <<EOF | |
799e09e5 | 1375 | hello.c- |
79a77109 RS |
1376 | hello.c=int main(int argc, const char **argv) |
1377 | hello.c-{ | |
1378 | hello.c: pr<RED>int<RESET>f("<RED>Hello<RESET> world.\n"); | |
1379 | hello.c- return 0; | |
1380 | hello.c- /* char ?? */ | |
1381 | hello.c-} | |
1382 | EOF | |
1383 | ||
1384 | test_expect_success 'grep --color -e A --and -e B -p with context' ' | |
1385 | test_config color.grep.context normal && | |
1386 | test_config color.grep.filename normal && | |
1387 | test_config color.grep.function normal && | |
1388 | test_config color.grep.linenumber normal && | |
1389 | test_config color.grep.matchContext normal && | |
1390 | test_config color.grep.matchSelected red && | |
1391 | test_config color.grep.selected normal && | |
1392 | test_config color.grep.separator normal && | |
1393 | ||
1394 | git grep --color=always -p -C3 -e int --and -e Hello --no-index hello.c | | |
1395 | test_decode_color >actual && | |
1396 | test_cmp expected actual | |
1397 | ' | |
1398 | ||
b8e47d1a CB |
1399 | test_expect_success 'grep can find things only in the work tree' ' |
1400 | : >work-tree-only && | |
1401 | git add work-tree-only && | |
1402 | test_when_finished "git rm -f work-tree-only" && | |
1403 | echo "find in work tree" >work-tree-only && | |
1404 | git grep --quiet "find in work tree" && | |
1405 | test_must_fail git grep --quiet --cached "find in work tree" && | |
1406 | test_must_fail git grep --quiet "find in work tree" HEAD | |
1407 | ' | |
1408 | ||
1409 | test_expect_success 'grep can find things only in the work tree (i-t-a)' ' | |
1410 | echo "intend to add this" >intend-to-add && | |
1411 | git add -N intend-to-add && | |
1412 | test_when_finished "git rm -f intend-to-add" && | |
1413 | git grep --quiet "intend to add this" && | |
1414 | test_must_fail git grep --quiet --cached "intend to add this" && | |
1415 | test_must_fail git grep --quiet "intend to add this" HEAD | |
1416 | ' | |
1417 | ||
1418 | test_expect_success 'grep does not search work tree with assume unchanged' ' | |
1419 | echo "intend to add this" >intend-to-add && | |
1420 | git add -N intend-to-add && | |
1421 | git update-index --assume-unchanged intend-to-add && | |
1422 | test_when_finished "git rm -f intend-to-add" && | |
1423 | test_must_fail git grep --quiet "intend to add this" && | |
1424 | test_must_fail git grep --quiet --cached "intend to add this" && | |
1425 | test_must_fail git grep --quiet "intend to add this" HEAD | |
1426 | ' | |
1427 | ||
1428 | test_expect_success 'grep can find things only in the index' ' | |
1429 | echo "only in the index" >cache-this && | |
1430 | git add cache-this && | |
1431 | rm cache-this && | |
1432 | test_when_finished "git rm --cached cache-this" && | |
1433 | test_must_fail git grep --quiet "only in the index" && | |
1434 | git grep --quiet --cached "only in the index" && | |
1435 | test_must_fail git grep --quiet "only in the index" HEAD | |
1436 | ' | |
1437 | ||
1438 | test_expect_success 'grep does not report i-t-a with -L --cached' ' | |
1439 | echo "intend to add this" >intend-to-add && | |
1440 | git add -N intend-to-add && | |
1441 | test_when_finished "git rm -f intend-to-add" && | |
1442 | git ls-files | grep -v "^intend-to-add\$" >expected && | |
1443 | git grep -L --cached "nonexistent_string" >actual && | |
1444 | test_cmp expected actual | |
1445 | ' | |
1446 | ||
1447 | test_expect_success 'grep does not report i-t-a and assume unchanged with -L' ' | |
1448 | echo "intend to add this" >intend-to-add-assume-unchanged && | |
1449 | git add -N intend-to-add-assume-unchanged && | |
1450 | test_when_finished "git rm -f intend-to-add-assume-unchanged" && | |
1451 | git update-index --assume-unchanged intend-to-add-assume-unchanged && | |
1452 | git ls-files | grep -v "^intend-to-add-assume-unchanged\$" >expected && | |
1453 | git grep -L "nonexistent_string" >actual && | |
1454 | test_cmp expected actual | |
1455 | ' | |
1456 | ||
f25b7939 | 1457 | test_done |