Skip to content

Commit fce8b5d

Browse files
committed
Merge branch 'jc/maint-diff-patch-header' into maint
"git diff-index" and its friends at the plumbing level showed the "diff --git" header and nothing else for a path whose cached stat info is dirty without actual difference when asked to produce a patch. This was a longstanding bug that we could have fixed long time ago. By Junio C Hamano * jc/maint-diff-patch-header: diff -p: squelch "diff --git" header for stat-dirty paths t4011: illustrate "diff-index -p" on stat-dirty paths t4011: modernise style
2 parents f629c23 + b3f01ff commit fce8b5d

File tree

2 files changed

+111
-86
lines changed

2 files changed

+111
-86
lines changed

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ static void builtin_diff(const char *name_a,
22102210
struct emit_callback ecbdata;
22112211
const struct userdiff_funcname *pe;
22122212

2213-
if (!DIFF_XDL_TST(o, WHITESPACE_FLAGS) || must_show_header) {
2213+
if (must_show_header) {
22142214
fprintf(o->file, "%s", header.buf);
22152215
strbuf_reset(&header);
22162216
}

t/t4011-diff-symlink.sh

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

12-
cat > expected << EOF
13-
diff --git a/frotz b/frotz
14-
new file mode 120000
15-
index 0000000..7c465af
16-
--- /dev/null
17-
+++ b/frotz
18-
@@ -0,0 +1 @@
19-
+xyzzy
20-
\ No newline at end of file
21-
EOF
22-
23-
test_expect_success SYMLINKS \
24-
'diff new symlink' \
25-
'ln -s xyzzy frotz &&
26-
git update-index &&
27-
tree=$(git write-tree) &&
28-
git update-index --add frotz &&
29-
GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree > current &&
30-
compare_diff_patch current expected'
31-
32-
test_expect_success SYMLINKS \
33-
'diff unchanged symlink' \
34-
'tree=$(git write-tree) &&
35-
git update-index frotz &&
36-
test -z "$(git diff-index --name-only $tree)"'
37-
38-
cat > expected << EOF
39-
diff --git a/frotz b/frotz
40-
deleted file mode 120000
41-
index 7c465af..0000000
42-
--- a/frotz
43-
+++ /dev/null
44-
@@ -1 +0,0 @@
45-
-xyzzy
46-
\ No newline at end of file
47-
EOF
12+
test_expect_success SYMLINKS 'diff new symlink and file' '
13+
cat >expected <<-\EOF &&
14+
diff --git a/frotz b/frotz
15+
new file mode 120000
16+
index 0000000..7c465af
17+
--- /dev/null
18+
+++ b/frotz
19+
@@ -0,0 +1 @@
20+
+xyzzy
21+
\ 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
29+
EOF
30+
ln -s xyzzy frotz &&
31+
echo xyzzy >nitfol &&
32+
git update-index &&
33+
tree=$(git write-tree) &&
34+
git update-index --add frotz nitfol &&
35+
GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
36+
compare_diff_patch expected current
37+
'
4838

49-
test_expect_success SYMLINKS \
50-
'diff removed symlink' \
51-
'mv frotz frotz2 &&
52-
git diff-index -M -p $tree > current &&
53-
compare_diff_patch current expected'
39+
test_expect_success SYMLINKS 'diff unchanged symlink and file' '
40+
tree=$(git write-tree) &&
41+
git update-index frotz nitfol &&
42+
test -z "$(git diff-index --name-only $tree)"
43+
'
5444

55-
cat > expected << EOF
56-
diff --git a/frotz b/frotz
57-
EOF
45+
test_expect_success SYMLINKS 'diff removed symlink and file' '
46+
cat >expected <<-\EOF &&
47+
diff --git a/frotz b/frotz
48+
deleted file mode 120000
49+
index 7c465af..0000000
50+
--- a/frotz
51+
+++ /dev/null
52+
@@ -1 +0,0 @@
53+
-xyzzy
54+
\ 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
62+
EOF
63+
mv frotz frotz2 &&
64+
mv nitfol nitfol2 &&
65+
git diff-index -M -p $tree >current &&
66+
compare_diff_patch expected current
67+
'
5868

59-
test_expect_success SYMLINKS \
60-
'diff identical, but newly created symlink' \
61-
'ln -s xyzzy frotz &&
62-
git diff-index -M -p $tree > current &&
63-
compare_diff_patch current expected'
69+
test_expect_success SYMLINKS 'diff identical, but newly created symlink and file' '
70+
>expected &&
71+
rm -f frotz nitfol &&
72+
echo xyzzy >nitfol &&
73+
test-chmtime +10 nitfol &&
74+
ln -s xyzzy frotz &&
75+
git diff-index -M -p $tree >current &&
76+
compare_diff_patch expected current &&
6477
65-
cat > expected << EOF
66-
diff --git a/frotz b/frotz
67-
index 7c465af..df1db54 120000
68-
--- a/frotz
69-
+++ b/frotz
70-
@@ -1 +1 @@
71-
-xyzzy
72-
\ No newline at end of file
73-
+yxyyz
74-
\ No newline at end of file
75-
EOF
78+
>expected &&
79+
git diff-index -M -p -w $tree >current &&
80+
compare_diff_patch expected current
81+
'
7682

77-
test_expect_success SYMLINKS \
78-
'diff different symlink' \
79-
'rm frotz &&
80-
ln -s yxyyz frotz &&
81-
git diff-index -M -p $tree > current &&
82-
compare_diff_patch current expected'
83+
test_expect_success SYMLINKS 'diff different symlink and file' '
84+
cat >expected <<-\EOF &&
85+
diff --git a/frotz b/frotz
86+
index 7c465af..df1db54 120000
87+
--- a/frotz
88+
+++ b/frotz
89+
@@ -1 +1 @@
90+
-xyzzy
91+
\ No newline at end of file
92+
+yxyyz
93+
\ No newline at end of file
94+
diff --git a/nitfol b/nitfol
95+
index 7c465af..df1db54 100644
96+
--- a/nitfol
97+
+++ b/nitfol
98+
@@ -1 +1 @@
99+
-xyzzy
100+
+yxyyz
101+
EOF
102+
rm -f frotz &&
103+
ln -s yxyyz frotz &&
104+
echo yxyyz >nitfol &&
105+
git diff-index -M -p $tree >current &&
106+
compare_diff_patch expected current
107+
'
83108

84-
test_expect_success SYMLINKS \
85-
'diff symlinks with non-existing targets' \
86-
'ln -s narf pinky &&
87-
ln -s take\ over brain &&
88-
test_must_fail git diff --no-index pinky brain > output 2> output.err &&
89-
grep narf output &&
90-
! grep error output.err'
109+
test_expect_success SYMLINKS 'diff symlinks with non-existing targets' '
110+
ln -s narf pinky &&
111+
ln -s take\ over brain &&
112+
test_must_fail git diff --no-index pinky brain >output 2>output.err &&
113+
grep narf output &&
114+
! test -s output.err
115+
'
91116

92117
test_expect_success SYMLINKS 'setup symlinks with attributes' '
93118
echo "*.bin diff=bin" >>.gitattributes &&
@@ -96,19 +121,19 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
96121
git add -N file.bin link.bin
97122
'
98123

99-
cat >expect <<'EOF'
100-
diff --git a/file.bin b/file.bin
101-
index e69de29..d95f3ad 100644
102-
Binary files a/file.bin and b/file.bin differ
103-
diff --git a/link.bin b/link.bin
104-
index e69de29..dce41ec 120000
105-
--- a/link.bin
106-
+++ b/link.bin
107-
@@ -0,0 +1 @@
108-
+file.bin
109-
\ No newline at end of file
110-
EOF
111124
test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
125+
cat >expect <<-\EOF &&
126+
diff --git a/file.bin b/file.bin
127+
index e69de29..d95f3ad 100644
128+
Binary files a/file.bin and b/file.bin differ
129+
diff --git a/link.bin b/link.bin
130+
index e69de29..dce41ec 120000
131+
--- a/link.bin
132+
+++ b/link.bin
133+
@@ -0,0 +1 @@
134+
+file.bin
135+
\ No newline at end of file
136+
EOF
112137
git config diff.bin.binary true &&
113138
git diff file.bin link.bin >actual &&
114139
test_cmp expect actual

0 commit comments

Comments
 (0)