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