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
This commit is contained in:
Junio C Hamano 2012-03-12 15:46:32 -07:00
commit fce8b5d82f
2 changed files with 111 additions and 86 deletions

2
diff.c
View File

@ -2210,7 +2210,7 @@ static void builtin_diff(const char *name_a,
struct emit_callback ecbdata; struct emit_callback ecbdata;
const struct userdiff_funcname *pe; const struct userdiff_funcname *pe;
if (!DIFF_XDL_TST(o, WHITESPACE_FLAGS) || must_show_header) { if (must_show_header) {
fprintf(o->file, "%s", header.buf); fprintf(o->file, "%s", header.buf);
strbuf_reset(&header); strbuf_reset(&header);
} }

View File

@ -9,7 +9,8 @@ test_description='Test diff of symlinks.
. ./test-lib.sh . ./test-lib.sh
. "$TEST_DIRECTORY"/diff-lib.sh . "$TEST_DIRECTORY"/diff-lib.sh
cat > expected << EOF test_expect_success SYMLINKS 'diff new symlink and file' '
cat >expected <<-\EOF &&
diff --git a/frotz b/frotz diff --git a/frotz b/frotz
new file mode 120000 new file mode 120000
index 0000000..7c465af index 0000000..7c465af
@ -18,24 +19,31 @@ index 0000000..7c465af
@@ -0,0 +1 @@ @@ -0,0 +1 @@
+xyzzy +xyzzy
\ No newline at end of file \ No newline at end of file
diff --git a/nitfol b/nitfol
new file mode 100644
index 0000000..7c465af
--- /dev/null
+++ b/nitfol
@@ -0,0 +1 @@
+xyzzy
EOF EOF
ln -s xyzzy frotz &&
test_expect_success SYMLINKS \ echo xyzzy >nitfol &&
'diff new symlink' \
'ln -s xyzzy frotz &&
git update-index && git update-index &&
tree=$(git write-tree) && tree=$(git write-tree) &&
git update-index --add frotz && git update-index --add frotz nitfol &&
GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current && GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
compare_diff_patch current expected' compare_diff_patch expected current
'
test_expect_success SYMLINKS \ test_expect_success SYMLINKS 'diff unchanged symlink and file' '
'diff unchanged symlink' \ tree=$(git write-tree) &&
'tree=$(git write-tree) && git update-index frotz nitfol &&
git update-index frotz && test -z "$(git diff-index --name-only $tree)"
test -z "$(git diff-index --name-only $tree)"' '
cat > expected << EOF test_expect_success SYMLINKS 'diff removed symlink and file' '
cat >expected <<-\EOF &&
diff --git a/frotz b/frotz diff --git a/frotz b/frotz
deleted file mode 120000 deleted file mode 120000
index 7c465af..0000000 index 7c465af..0000000
@ -44,25 +52,36 @@ index 7c465af..0000000
@@ -1 +0,0 @@ @@ -1 +0,0 @@
-xyzzy -xyzzy
\ No newline at end of file \ No newline at end of file
diff --git a/nitfol b/nitfol
deleted file mode 100644
index 7c465af..0000000
--- a/nitfol
+++ /dev/null
@@ -1 +0,0 @@
-xyzzy
EOF EOF
mv frotz frotz2 &&
test_expect_success SYMLINKS \ mv nitfol nitfol2 &&
'diff removed symlink' \
'mv frotz frotz2 &&
git diff-index -M -p $tree >current && git diff-index -M -p $tree >current &&
compare_diff_patch current expected' compare_diff_patch expected current
'
cat > expected << EOF test_expect_success SYMLINKS 'diff identical, but newly created symlink and file' '
diff --git a/frotz b/frotz >expected &&
EOF rm -f frotz nitfol &&
echo xyzzy >nitfol &&
test_expect_success SYMLINKS \ test-chmtime +10 nitfol &&
'diff identical, but newly created symlink' \ ln -s xyzzy frotz &&
'ln -s xyzzy frotz &&
git diff-index -M -p $tree >current && git diff-index -M -p $tree >current &&
compare_diff_patch current expected' compare_diff_patch expected current &&
cat > expected << EOF >expected &&
git diff-index -M -p -w $tree >current &&
compare_diff_patch expected current
'
test_expect_success SYMLINKS 'diff different symlink and file' '
cat >expected <<-\EOF &&
diff --git a/frotz b/frotz diff --git a/frotz b/frotz
index 7c465af..df1db54 120000 index 7c465af..df1db54 120000
--- a/frotz --- a/frotz
@ -72,22 +91,28 @@ index 7c465af..df1db54 120000
\ No newline at end of file \ No newline at end of file
+yxyyz +yxyyz
\ No newline at end of file \ No newline at end of file
diff --git a/nitfol b/nitfol
index 7c465af..df1db54 100644
--- a/nitfol
+++ b/nitfol
@@ -1 +1 @@
-xyzzy
+yxyyz
EOF EOF
rm -f frotz &&
test_expect_success SYMLINKS \
'diff different symlink' \
'rm frotz &&
ln -s yxyyz frotz && ln -s yxyyz frotz &&
echo yxyyz >nitfol &&
git diff-index -M -p $tree >current && git diff-index -M -p $tree >current &&
compare_diff_patch current expected' compare_diff_patch expected current
'
test_expect_success SYMLINKS \ test_expect_success SYMLINKS 'diff symlinks with non-existing targets' '
'diff symlinks with non-existing targets' \ ln -s narf pinky &&
'ln -s narf pinky &&
ln -s take\ over brain && ln -s take\ over brain &&
test_must_fail git diff --no-index pinky brain >output 2>output.err && test_must_fail git diff --no-index pinky brain >output 2>output.err &&
grep narf output && grep narf output &&
! grep error output.err' ! test -s output.err
'
test_expect_success SYMLINKS 'setup symlinks with attributes' ' test_expect_success SYMLINKS 'setup symlinks with attributes' '
echo "*.bin diff=bin" >>.gitattributes && echo "*.bin diff=bin" >>.gitattributes &&
@ -96,7 +121,8 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
git add -N file.bin link.bin git add -N file.bin link.bin
' '
cat >expect <<'EOF' test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
cat >expect <<-\EOF &&
diff --git a/file.bin b/file.bin diff --git a/file.bin b/file.bin
index e69de29..d95f3ad 100644 index e69de29..d95f3ad 100644
Binary files a/file.bin and b/file.bin differ Binary files a/file.bin and b/file.bin differ
@ -108,7 +134,6 @@ index e69de29..dce41ec 120000
+file.bin +file.bin
\ No newline at end of file \ No newline at end of file
EOF EOF
test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
git config diff.bin.binary true && git config diff.bin.binary true &&
git diff file.bin link.bin >actual && git diff file.bin link.bin >actual &&
test_cmp expect actual test_cmp expect actual