Browse Source

Merge branch 'jc/maint-diff-patch-header'

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
maint
Junio C Hamano 13 years ago
parent
commit
239d6eddcd
  1. 2
      diff.c
  2. 195
      t/t4011-diff-symlink.sh

2
diff.c

@ -2255,7 +2255,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);
} }

195
t/t4011-diff-symlink.sh

@ -9,85 +9,110 @@ 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' '
diff --git a/frotz b/frotz cat >expected <<-\EOF &&
new file mode 120000 diff --git a/frotz b/frotz
index 0000000..7c465af new file mode 120000
--- /dev/null index 0000000..7c465af
+++ b/frotz --- /dev/null
@@ -0,0 +1 @@ +++ b/frotz
+xyzzy @@ -0,0 +1 @@
\ No newline at end of file +xyzzy
EOF \ No newline at end of file

diff --git a/nitfol b/nitfol
test_expect_success SYMLINKS \ new file mode 100644
'diff new symlink' \ index 0000000..7c465af
'ln -s xyzzy frotz && --- /dev/null
git update-index && +++ b/nitfol
tree=$(git write-tree) && @@ -0,0 +1 @@
git update-index --add frotz && +xyzzy
GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree > current && EOF
compare_diff_patch current expected' ln -s xyzzy frotz &&

echo xyzzy >nitfol &&
test_expect_success SYMLINKS \ git update-index &&
'diff unchanged symlink' \ tree=$(git write-tree) &&
'tree=$(git write-tree) && git update-index --add frotz nitfol &&
git update-index frotz && GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
test -z "$(git diff-index --name-only $tree)"' compare_diff_patch expected current

'
cat > expected << EOF
diff --git a/frotz b/frotz
deleted file mode 120000
index 7c465af..0000000
--- a/frotz
+++ /dev/null
@@ -1 +0,0 @@
-xyzzy
\ No newline at end of file
EOF


test_expect_success SYMLINKS \ test_expect_success SYMLINKS 'diff unchanged symlink and file' '
'diff removed symlink' \ tree=$(git write-tree) &&
'mv frotz frotz2 && git update-index frotz nitfol &&
git diff-index -M -p $tree > current && test -z "$(git diff-index --name-only $tree)"
compare_diff_patch current expected' '


cat > expected << EOF test_expect_success SYMLINKS 'diff removed symlink and file' '
diff --git a/frotz b/frotz cat >expected <<-\EOF &&
EOF diff --git a/frotz b/frotz
deleted file mode 120000
index 7c465af..0000000
--- a/frotz
+++ /dev/null
@@ -1 +0,0 @@
-xyzzy
\ 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
mv frotz frotz2 &&
mv nitfol nitfol2 &&
git diff-index -M -p $tree >current &&
compare_diff_patch expected current
'


test_expect_success SYMLINKS \ test_expect_success SYMLINKS 'diff identical, but newly created symlink and file' '
'diff identical, but newly created symlink' \ >expected &&
'ln -s xyzzy frotz && rm -f frotz nitfol &&
git diff-index -M -p $tree > current && echo xyzzy >nitfol &&
compare_diff_patch current expected' test-chmtime +10 nitfol &&
ln -s xyzzy frotz &&
git diff-index -M -p $tree >current &&
compare_diff_patch expected current &&


cat > expected << EOF >expected &&
diff --git a/frotz b/frotz git diff-index -M -p -w $tree >current &&
index 7c465af..df1db54 120000 compare_diff_patch expected current
--- a/frotz '
+++ b/frotz
@@ -1 +1 @@
-xyzzy
\ No newline at end of file
+yxyyz
\ No newline at end of file
EOF


test_expect_success SYMLINKS \ test_expect_success SYMLINKS 'diff different symlink and file' '
'diff different symlink' \ cat >expected <<-\EOF &&
'rm frotz && diff --git a/frotz b/frotz
ln -s yxyyz frotz && index 7c465af..df1db54 120000
git diff-index -M -p $tree > current && --- a/frotz
compare_diff_patch current expected' +++ b/frotz
@@ -1 +1 @@
-xyzzy
\ No newline at end of file
+yxyyz
\ 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
rm -f frotz &&
ln -s yxyyz frotz &&
echo yxyyz >nitfol &&
git diff-index -M -p $tree >current &&
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 && ! test -s output.err
! grep error 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,19 +121,19 @@ 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'
diff --git a/file.bin b/file.bin
index e69de29..d95f3ad 100644
Binary files a/file.bin and b/file.bin differ
diff --git a/link.bin b/link.bin
index e69de29..dce41ec 120000
--- a/link.bin
+++ b/link.bin
@@ -0,0 +1 @@
+file.bin
\ No newline at end of file
EOF
test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' ' test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
cat >expect <<-\EOF &&
diff --git a/file.bin b/file.bin
index e69de29..d95f3ad 100644
Binary files a/file.bin and b/file.bin differ
diff --git a/link.bin b/link.bin
index e69de29..dce41ec 120000
--- a/link.bin
+++ b/link.bin
@@ -0,0 +1 @@
+file.bin
\ No newline at end of file
EOF
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

Loading…
Cancel
Save