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