Skip to content

Commit 5597e84

Browse files
committed
t4011: illustrate "diff-index -p" on stat-dirty paths
The plumbing that looks at the working tree, i.e. "diff-index" and "diff-files", always emit the "diff --git a/path b/path" header lines without anything else for paths that are only stat-dirty (i.e. different only because the cached stat information in the index no longer matches that of the working tree, but the real contents are the same), when these commands are run with "-p" option to produce patches. Illustrate this current behaviour. Also demonstrate that with the "-w" option, we (correctly) hold off showing a "diff --git" header until actual differences have been found. This also suppresses the header for merely stat-dirty files, which is inconsistent. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 13a4899 commit 5597e84

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

t/t4011-diff-symlink.sh

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test_description='Test diff of symlinks.
99
. ./test-lib.sh
1010
. "$TEST_DIRECTORY"/diff-lib.sh
1111

12-
test_expect_success SYMLINKS 'diff new symlink' '
12+
test_expect_success SYMLINKS 'diff new symlink and file' '
1313
cat >expected <<-\EOF &&
1414
diff --git a/frotz b/frotz
1515
new file mode 120000
@@ -19,22 +19,30 @@ test_expect_success SYMLINKS 'diff new symlink' '
1919
@@ -0,0 +1 @@
2020
+xyzzy
2121
\ No newline at end of file
22+
diff --git a/nitfol b/nitfol
23+
new file mode 100644
24+
index 0000000..7c465af
25+
--- /dev/null
26+
+++ b/nitfol
27+
@@ -0,0 +1 @@
28+
+xyzzy
2229
EOF
2330
ln -s xyzzy frotz &&
31+
echo xyzzy >nitfol &&
2432
git update-index &&
2533
tree=$(git write-tree) &&
26-
git update-index --add frotz &&
34+
git update-index --add frotz nitfol &&
2735
GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
2836
compare_diff_patch expected current
2937
'
3038

31-
test_expect_success SYMLINKS 'diff unchanged symlink' '
39+
test_expect_success SYMLINKS 'diff unchanged symlink and file' '
3240
tree=$(git write-tree) &&
33-
git update-index frotz &&
41+
git update-index frotz nitfol &&
3442
test -z "$(git diff-index --name-only $tree)"
3543
'
3644

37-
test_expect_success SYMLINKS 'diff removed symlink' '
45+
test_expect_success SYMLINKS 'diff removed symlink and file' '
3846
cat >expected <<-\EOF &&
3947
diff --git a/frotz b/frotz
4048
deleted file mode 120000
@@ -44,22 +52,38 @@ test_expect_success SYMLINKS 'diff removed symlink' '
4452
@@ -1 +0,0 @@
4553
-xyzzy
4654
\ No newline at end of file
55+
diff --git a/nitfol b/nitfol
56+
deleted file mode 100644
57+
index 7c465af..0000000
58+
--- a/nitfol
59+
+++ /dev/null
60+
@@ -1 +0,0 @@
61+
-xyzzy
4762
EOF
4863
mv frotz frotz2 &&
64+
mv nitfol nitfol2 &&
4965
git diff-index -M -p $tree >current &&
5066
compare_diff_patch expected current
5167
'
5268

53-
test_expect_success SYMLINKS 'diff identical, but newly created symlink' '
69+
test_expect_success SYMLINKS 'diff identical, but newly created symlink and file' '
5470
cat >expected <<-\EOF &&
5571
diff --git a/frotz b/frotz
72+
diff --git a/nitfol b/nitfol
5673
EOF
74+
rm -f frotz nitfol &&
75+
echo xyzzy >nitfol &&
76+
test-chmtime +10 nitfol &&
5777
ln -s xyzzy frotz &&
5878
git diff-index -M -p $tree >current &&
79+
compare_diff_patch expected current &&
80+
81+
>expected &&
82+
git diff-index -M -p -w $tree >current &&
5983
compare_diff_patch expected current
6084
'
6185

62-
test_expect_success SYMLINKS 'diff different symlink' '
86+
test_expect_success SYMLINKS 'diff different symlink and file' '
6387
cat >expected <<-\EOF &&
6488
diff --git a/frotz b/frotz
6589
index 7c465af..df1db54 120000
@@ -70,9 +94,17 @@ test_expect_success SYMLINKS 'diff different symlink' '
7094
\ No newline at end of file
7195
+yxyyz
7296
\ No newline at end of file
97+
diff --git a/nitfol b/nitfol
98+
index 7c465af..df1db54 100644
99+
--- a/nitfol
100+
+++ b/nitfol
101+
@@ -1 +1 @@
102+
-xyzzy
103+
+yxyyz
73104
EOF
74105
rm -f frotz &&
75106
ln -s yxyyz frotz &&
107+
echo yxyyz >nitfol &&
76108
git diff-index -M -p $tree >current &&
77109
compare_diff_patch expected current
78110
'

0 commit comments

Comments
 (0)