1296
test_cmp expected actual
1297
'
1298
1299
+test_expect_success 'grep can find things only in the work tree' '
1300
+ : >work-tree-only &&
1301
+ git add work-tree-only &&
1302
+ test_when_finished "git rm -f work-tree-only" &&
1303
+ echo "find in work tree" >work-tree-only &&
1304
+ git grep --quiet "find in work tree" &&
1305
+ test_must_fail git grep --quiet --cached "find in work tree" &&
1306
+ test_must_fail git grep --quiet "find in work tree" HEAD
1307
+'
1308
+
1309
+test_expect_success 'grep can find things only in the work tree (i-t-a)' '
1310
+ echo "intend to add this" >intend-to-add &&
1311
+ git add -N intend-to-add &&
1312
+ test_when_finished "git rm -f intend-to-add" &&
1313
+ git grep --quiet "intend to add this" &&
1314
+ test_must_fail git grep --quiet --cached "intend to add this" &&
1315
+ test_must_fail git grep --quiet "intend to add this" HEAD
1316
+'
1317
+
1318
+test_expect_success 'grep does not search work tree with assume unchanged' '
1319
+ echo "intend to add this" >intend-to-add &&
1320
+ git add -N intend-to-add &&
1321
+ git update-index --assume-unchanged intend-to-add &&
1322
+ test_when_finished "git rm -f intend-to-add" &&
1323
+ test_must_fail git grep --quiet "intend to add this" &&
1324
+ test_must_fail git grep --quiet --cached "intend to add this" &&
1325
+ test_must_fail git grep --quiet "intend to add this" HEAD
1326
+'
1327
+
1328
+test_expect_success 'grep can find things only in the index' '
1329
+ echo "only in the index" >cache-this &&
1330
+ git add cache-this &&
1331
+ rm cache-this &&
1332
+ test_when_finished "git rm --cached cache-this" &&
1333
+ test_must_fail git grep --quiet "only in the index" &&
1334
+ git grep --quiet --cached "only in the index" &&
1335
+ test_must_fail git grep --quiet "only in the index" HEAD
1336
+'
1337
+
1338
+test_expect_success 'grep does not report i-t-a with -L --cached' '
1339
+ echo "intend to add this" >intend-to-add &&
1340
+ git add -N intend-to-add &&
1341
+ test_when_finished "git rm -f intend-to-add" &&
1342
+ git ls-files | grep -v "^intend-to-add\$" >expected &&
1343
+ git grep -L --cached "nonexistent_string" >actual &&
1344
+ test_cmp expected actual
1345
+'
1346
+
1347
+test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '
1348
+ echo "intend to add this" >intend-to-add-assume-unchanged &&
1349
+ git add -N intend-to-add-assume-unchanged &&
1350
+ test_when_finished "git rm -f intend-to-add-assume-unchanged" &&
1351
+ git update-index --assume-unchanged intend-to-add-assume-unchanged &&
1352
+ git ls-files | grep -v "^intend-to-add-assume-unchanged\$" >expected &&
1353
+ git grep -L "nonexistent_string" >actual &&
1354
+ test_cmp expected actual
1355
+'
1356
+
1357
test_done