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