@@ -1318,48 +1318,59 @@ test_expect_success 'no effect from --color-moved with --word-diff' '
1318
1318
test_cmp expect actual
1319
1319
'
1320
1320
1321
- test_expect_success ' move detection ignoring whitespace ' '
1321
+ test_expect_success ' set up whitespace tests ' '
1322
1322
git reset --hard &&
1323
- cat <<\EOF >lines.txt &&
1324
- line 1
1325
- line 2
1326
- line 3
1327
- line 4
1328
- long line 5
1329
- long line 6
1330
- long line 7
1331
- EOF
1332
- git add lines.txt &&
1333
- git commit -m "add poetry" &&
1334
- cat <<\EOF >lines.txt &&
1335
- long line 5
1323
+ # Note that these lines have no leading or trailing whitespace.
1324
+ cat <<-\EOF >lines.txt &&
1325
+ line 1
1326
+ line 2
1327
+ line 3
1328
+ line 4
1329
+ line 5
1336
1330
long line 6
1337
1331
long line 7
1338
- line 1
1339
- line 2
1340
- line 3
1341
- line 4
1342
- EOF
1343
- test_config color.diff.oldMoved "magenta" &&
1344
- test_config color.diff.newMoved "cyan" &&
1332
+ long line 8
1333
+ long line 9
1334
+ EOF
1335
+ git add lines.txt &&
1336
+ git commit -m "add poetry" &&
1337
+ git config color.diff.oldMoved "magenta" &&
1338
+ git config color.diff.newMoved "cyan"
1339
+ '
1340
+
1341
+ test_expect_success ' move detection ignoring whitespace ' '
1342
+ q_to_tab <<-\EOF >lines.txt &&
1343
+ Qlong line 6
1344
+ Qlong line 7
1345
+ Qlong line 8
1346
+ Qchanged long line 9
1347
+ line 1
1348
+ line 2
1349
+ line 3
1350
+ line 4
1351
+ line 5
1352
+ EOF
1345
1353
git diff HEAD --no-renames --color-moved --color |
1346
1354
grep -v "index" |
1347
1355
test_decode_color >actual &&
1348
1356
cat <<-\EOF >expected &&
1349
1357
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1350
1358
<BOLD>--- a/lines.txt<RESET>
1351
1359
<BOLD>+++ b/lines.txt<RESET>
1352
- <CYAN>@@ -1,7 +1,7 @@<RESET>
1353
- <GREEN>+<RESET> <GREEN>long line 5<RESET>
1360
+ <CYAN>@@ -1,9 +1,9 @@<RESET>
1354
1361
<GREEN>+<RESET> <GREEN>long line 6<RESET>
1355
1362
<GREEN>+<RESET> <GREEN>long line 7<RESET>
1363
+ <GREEN>+<RESET> <GREEN>long line 8<RESET>
1364
+ <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1356
1365
line 1<RESET>
1357
1366
line 2<RESET>
1358
1367
line 3<RESET>
1359
1368
line 4<RESET>
1360
- <RED>-long line 5<RESET>
1369
+ line 5<RESET>
1361
1370
<RED>-long line 6<RESET>
1362
1371
<RED>-long line 7<RESET>
1372
+ <RED>-long line 8<RESET>
1373
+ <RED>-long line 9<RESET>
1363
1374
EOF
1364
1375
test_cmp expected actual &&
1365
1376
@@ -1370,21 +1381,160 @@ EOF
1370
1381
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1371
1382
<BOLD>--- a/lines.txt<RESET>
1372
1383
<BOLD>+++ b/lines.txt<RESET>
1373
- <CYAN>@@ -1,7 +1,7 @@<RESET>
1374
- <CYAN>+<RESET> <CYAN>long line 5<RESET>
1384
+ <CYAN>@@ -1,9 +1,9 @@<RESET>
1375
1385
<CYAN>+<RESET> <CYAN>long line 6<RESET>
1376
1386
<CYAN>+<RESET> <CYAN>long line 7<RESET>
1387
+ <CYAN>+<RESET> <CYAN>long line 8<RESET>
1388
+ <GREEN>+<RESET> <GREEN>changed long line 9<RESET>
1389
+ line 1<RESET>
1390
+ line 2<RESET>
1391
+ line 3<RESET>
1392
+ line 4<RESET>
1393
+ line 5<RESET>
1394
+ <MAGENTA>-long line 6<RESET>
1395
+ <MAGENTA>-long line 7<RESET>
1396
+ <MAGENTA>-long line 8<RESET>
1397
+ <RED>-long line 9<RESET>
1398
+ EOF
1399
+ test_cmp expected actual
1400
+ '
1401
+
1402
+ test_expect_success ' move detection ignoring whitespace changes' '
1403
+ git reset --hard &&
1404
+ # Lines 6-8 have a space change, but 9 is new whitespace
1405
+ q_to_tab <<-\EOF >lines.txt &&
1406
+ longQline 6
1407
+ longQline 7
1408
+ longQline 8
1409
+ long liQne 9
1410
+ line 1
1411
+ line 2
1412
+ line 3
1413
+ line 4
1414
+ line 5
1415
+ EOF
1416
+
1417
+ git diff HEAD --no-renames --color-moved --color |
1418
+ grep -v "index" |
1419
+ test_decode_color >actual &&
1420
+ cat <<-\EOF >expected &&
1421
+ <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1422
+ <BOLD>--- a/lines.txt<RESET>
1423
+ <BOLD>+++ b/lines.txt<RESET>
1424
+ <CYAN>@@ -1,9 +1,9 @@<RESET>
1425
+ <GREEN>+<RESET><GREEN>long line 6<RESET>
1426
+ <GREEN>+<RESET><GREEN>long line 7<RESET>
1427
+ <GREEN>+<RESET><GREEN>long line 8<RESET>
1428
+ <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1429
+ line 1<RESET>
1430
+ line 2<RESET>
1431
+ line 3<RESET>
1432
+ line 4<RESET>
1433
+ line 5<RESET>
1434
+ <RED>-long line 6<RESET>
1435
+ <RED>-long line 7<RESET>
1436
+ <RED>-long line 8<RESET>
1437
+ <RED>-long line 9<RESET>
1438
+ EOF
1439
+ test_cmp expected actual &&
1440
+
1441
+ git diff HEAD --no-renames -b --color-moved --color |
1442
+ grep -v "index" |
1443
+ test_decode_color >actual &&
1444
+ cat <<-\EOF >expected &&
1445
+ <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1446
+ <BOLD>--- a/lines.txt<RESET>
1447
+ <BOLD>+++ b/lines.txt<RESET>
1448
+ <CYAN>@@ -1,9 +1,9 @@<RESET>
1449
+ <CYAN>+<RESET><CYAN>long line 6<RESET>
1450
+ <CYAN>+<RESET><CYAN>long line 7<RESET>
1451
+ <CYAN>+<RESET><CYAN>long line 8<RESET>
1452
+ <GREEN>+<RESET><GREEN>long li ne 9<RESET>
1453
+ line 1<RESET>
1454
+ line 2<RESET>
1455
+ line 3<RESET>
1456
+ line 4<RESET>
1457
+ line 5<RESET>
1458
+ <MAGENTA>-long line 6<RESET>
1459
+ <MAGENTA>-long line 7<RESET>
1460
+ <MAGENTA>-long line 8<RESET>
1461
+ <RED>-long line 9<RESET>
1462
+ EOF
1463
+ test_cmp expected actual
1464
+ '
1465
+
1466
+ test_expect_success ' move detection ignoring whitespace at eol' '
1467
+ git reset --hard &&
1468
+ # Lines 6-9 have new eol whitespace, but 9 also has it in the middle
1469
+ q_to_tab <<-\EOF >lines.txt &&
1470
+ long line 6Q
1471
+ long line 7Q
1472
+ long line 8Q
1473
+ longQline 9Q
1474
+ line 1
1475
+ line 2
1476
+ line 3
1477
+ line 4
1478
+ line 5
1479
+ EOF
1480
+
1481
+ # avoid cluttering the output with complaints about our eol whitespace
1482
+ test_config core.whitespace -blank-at-eol &&
1483
+
1484
+ git diff HEAD --no-renames --color-moved --color |
1485
+ grep -v "index" |
1486
+ test_decode_color >actual &&
1487
+ cat <<-\EOF >expected &&
1488
+ <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1489
+ <BOLD>--- a/lines.txt<RESET>
1490
+ <BOLD>+++ b/lines.txt<RESET>
1491
+ <CYAN>@@ -1,9 +1,9 @@<RESET>
1492
+ <GREEN>+<RESET><GREEN>long line 6 <RESET>
1493
+ <GREEN>+<RESET><GREEN>long line 7 <RESET>
1494
+ <GREEN>+<RESET><GREEN>long line 8 <RESET>
1495
+ <GREEN>+<RESET><GREEN>long line 9 <RESET>
1496
+ line 1<RESET>
1497
+ line 2<RESET>
1498
+ line 3<RESET>
1499
+ line 4<RESET>
1500
+ line 5<RESET>
1501
+ <RED>-long line 6<RESET>
1502
+ <RED>-long line 7<RESET>
1503
+ <RED>-long line 8<RESET>
1504
+ <RED>-long line 9<RESET>
1505
+ EOF
1506
+ test_cmp expected actual &&
1507
+
1508
+ git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color |
1509
+ grep -v "index" |
1510
+ test_decode_color >actual &&
1511
+ cat <<-\EOF >expected &&
1512
+ <BOLD>diff --git a/lines.txt b/lines.txt<RESET>
1513
+ <BOLD>--- a/lines.txt<RESET>
1514
+ <BOLD>+++ b/lines.txt<RESET>
1515
+ <CYAN>@@ -1,9 +1,9 @@<RESET>
1516
+ <CYAN>+<RESET><CYAN>long line 6 <RESET>
1517
+ <CYAN>+<RESET><CYAN>long line 7 <RESET>
1518
+ <CYAN>+<RESET><CYAN>long line 8 <RESET>
1519
+ <GREEN>+<RESET><GREEN>long line 9 <RESET>
1377
1520
line 1<RESET>
1378
1521
line 2<RESET>
1379
1522
line 3<RESET>
1380
1523
line 4<RESET>
1381
- <MAGENTA>-long line 5<RESET>
1524
+ line 5<RESET>
1382
1525
<MAGENTA>-long line 6<RESET>
1383
1526
<MAGENTA>-long line 7<RESET>
1527
+ <MAGENTA>-long line 8<RESET>
1528
+ <RED>-long line 9<RESET>
1384
1529
EOF
1385
1530
test_cmp expected actual
1386
1531
'
1387
1532
1533
+ test_expect_success ' clean up whitespace-test colors' '
1534
+ git config --unset color.diff.oldMoved &&
1535
+ git config --unset color.diff.newMoved
1536
+ '
1537
+
1388
1538
test_expect_success ' --color-moved block at end of diff output respects MIN_ALNUM_COUNT' '
1389
1539
git reset --hard &&
1390
1540
>bar &&
@@ -1530,13 +1680,4 @@ test_expect_success 'move detection with submodules' '
1530
1680
test_cmp expect decoded_actual
1531
1681
'
1532
1682
1533
- test_expect_success ' move detection with whitespace changes' '
1534
- test_when_finished "git reset --hard" &&
1535
- test_seq 10 >test &&
1536
- git add test &&
1537
- sed s/3/42/ <test >test.tmp &&
1538
- mv test.tmp test &&
1539
- git -c diff.colormoved diff --ignore-space-change -- test
1540
- '
1541
-
1542
1683
test_done
0 commit comments