|
177 | 177 |
|
178 | 178 | test_expect_success "grep -c $L (no /dev/null)" '
|
179 | 179 | ! git grep -c test $H | grep /dev/null
|
180 |
| - ' |
| 180 | + ' |
181 | 181 |
|
182 | 182 | test_expect_success "grep --max-depth -1 $L" '
|
183 | 183 | {
|
@@ -1377,4 +1377,62 @@ test_expect_success 'grep --color -e A --and -e B -p with context' '
|
1377 | 1377 | test_cmp expected actual
|
1378 | 1378 | '
|
1379 | 1379 |
|
| 1380 | +test_expect_success 'grep can find things only in the work tree' ' |
| 1381 | + : >work-tree-only && |
| 1382 | + git add work-tree-only && |
| 1383 | + test_when_finished "git rm -f work-tree-only" && |
| 1384 | + echo "find in work tree" >work-tree-only && |
| 1385 | + git grep --quiet "find in work tree" && |
| 1386 | + test_must_fail git grep --quiet --cached "find in work tree" && |
| 1387 | + test_must_fail git grep --quiet "find in work tree" HEAD |
| 1388 | +' |
| 1389 | + |
| 1390 | +test_expect_success 'grep can find things only in the work tree (i-t-a)' ' |
| 1391 | + echo "intend to add this" >intend-to-add && |
| 1392 | + git add -N intend-to-add && |
| 1393 | + test_when_finished "git rm -f intend-to-add" && |
| 1394 | + git grep --quiet "intend to add this" && |
| 1395 | + test_must_fail git grep --quiet --cached "intend to add this" && |
| 1396 | + test_must_fail git grep --quiet "intend to add this" HEAD |
| 1397 | +' |
| 1398 | + |
| 1399 | +test_expect_success 'grep does not search work tree with assume unchanged' ' |
| 1400 | + echo "intend to add this" >intend-to-add && |
| 1401 | + git add -N intend-to-add && |
| 1402 | + git update-index --assume-unchanged intend-to-add && |
| 1403 | + test_when_finished "git rm -f intend-to-add" && |
| 1404 | + test_must_fail git grep --quiet "intend to add this" && |
| 1405 | + test_must_fail git grep --quiet --cached "intend to add this" && |
| 1406 | + test_must_fail git grep --quiet "intend to add this" HEAD |
| 1407 | +' |
| 1408 | + |
| 1409 | +test_expect_success 'grep can find things only in the index' ' |
| 1410 | + echo "only in the index" >cache-this && |
| 1411 | + git add cache-this && |
| 1412 | + rm cache-this && |
| 1413 | + test_when_finished "git rm --cached cache-this" && |
| 1414 | + test_must_fail git grep --quiet "only in the index" && |
| 1415 | + git grep --quiet --cached "only in the index" && |
| 1416 | + test_must_fail git grep --quiet "only in the index" HEAD |
| 1417 | +' |
| 1418 | + |
| 1419 | +test_expect_success 'grep does not report i-t-a with -L --cached' ' |
| 1420 | + echo "intend to add this" >intend-to-add && |
| 1421 | + git add -N intend-to-add && |
| 1422 | + test_when_finished "git rm -f intend-to-add" && |
| 1423 | + git ls-files | grep -v "^intend-to-add\$" >expected && |
| 1424 | + git grep -L --cached "nonexistent_string" >actual && |
| 1425 | + test_cmp expected actual |
| 1426 | +' |
| 1427 | + |
| 1428 | +test_expect_success 'grep does not report i-t-a and assume unchanged with -L' ' |
| 1429 | + echo "intend to add this" >intend-to-add-assume-unchanged && |
| 1430 | + git add -N intend-to-add-assume-unchanged && |
| 1431 | + test_when_finished "git rm -f intend-to-add-assume-unchanged" && |
| 1432 | + git update-index --assume-unchanged intend-to-add-assume-unchanged && |
| 1433 | + git ls-files | grep -v "^intend-to-add-assume-unchanged\$" >expected && |
| 1434 | + git grep -L "nonexistent_string" >actual && |
| 1435 | + test_cmp expected actual |
| 1436 | +' |
| 1437 | + |
1380 | 1438 | test_done
|
0 commit comments