2005-12-26 21:31:42 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Johannes Schindelin
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test diff of symlinks.
|
|
|
|
|
|
|
|
'
|
2021-10-30 22:24:19 +00:00
|
|
|
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2005-12-26 21:31:42 +00:00
|
|
|
. ./test-lib.sh
|
2021-02-12 13:29:40 +00:00
|
|
|
. "$TEST_DIRECTORY"/lib-diff.sh
|
2005-12-26 21:31:42 +00:00
|
|
|
|
2019-10-28 00:58:59 +00:00
|
|
|
# Print the short OID of a symlink with the given name.
|
|
|
|
symlink_oid () {
|
|
|
|
local oid=$(printf "%s" "$1" | git hash-object --stdin) &&
|
|
|
|
git rev-parse --short "$oid"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Print the short OID of the given file.
|
|
|
|
short_oid () {
|
|
|
|
local oid=$(git hash-object "$1") &&
|
|
|
|
git rev-parse --short "$oid"
|
|
|
|
}
|
|
|
|
|
2013-06-07 20:53:34 +00:00
|
|
|
test_expect_success 'diff new symlink and file' '
|
2019-10-28 00:58:59 +00:00
|
|
|
symlink=$(symlink_oid xyzzy) &&
|
|
|
|
cat >expected <<-EOF &&
|
2012-03-01 02:14:14 +00:00
|
|
|
diff --git a/frotz b/frotz
|
|
|
|
new file mode 120000
|
2019-10-28 00:58:59 +00:00
|
|
|
index 0000000..$symlink
|
2012-03-01 02:14:14 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/frotz
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+xyzzy
|
|
|
|
\ No newline at end of file
|
2012-03-01 02:14:15 +00:00
|
|
|
diff --git a/nitfol b/nitfol
|
|
|
|
new file mode 100644
|
2019-10-28 00:58:59 +00:00
|
|
|
index 0000000..$symlink
|
2012-03-01 02:14:15 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/nitfol
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+xyzzy
|
2012-03-01 02:14:14 +00:00
|
|
|
EOF
|
2013-06-07 20:53:34 +00:00
|
|
|
|
|
|
|
# the empty tree
|
2012-03-01 02:14:14 +00:00
|
|
|
git update-index &&
|
|
|
|
tree=$(git write-tree) &&
|
2013-06-07 20:53:34 +00:00
|
|
|
|
|
|
|
test_ln_s_add xyzzy frotz &&
|
|
|
|
echo xyzzy >nitfol &&
|
|
|
|
git update-index --add nitfol &&
|
2012-03-01 02:14:14 +00:00
|
|
|
GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&
|
|
|
|
compare_diff_patch expected current
|
|
|
|
'
|
2005-12-26 21:31:42 +00:00
|
|
|
|
2013-06-07 20:53:34 +00:00
|
|
|
test_expect_success 'diff unchanged symlink and file' '
|
2012-03-01 02:14:14 +00:00
|
|
|
tree=$(git write-tree) &&
|
2012-03-01 02:14:15 +00:00
|
|
|
git update-index frotz nitfol &&
|
2012-03-01 02:14:14 +00:00
|
|
|
test -z "$(git diff-index --name-only $tree)"
|
|
|
|
'
|
2005-12-26 21:31:42 +00:00
|
|
|
|
2013-06-07 20:53:34 +00:00
|
|
|
test_expect_success 'diff removed symlink and file' '
|
2019-10-28 00:58:59 +00:00
|
|
|
cat >expected <<-EOF &&
|
2012-03-01 02:14:14 +00:00
|
|
|
diff --git a/frotz b/frotz
|
|
|
|
deleted file mode 120000
|
2019-10-28 00:58:59 +00:00
|
|
|
index $symlink..0000000
|
2012-03-01 02:14:14 +00:00
|
|
|
--- a/frotz
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-xyzzy
|
|
|
|
\ No newline at end of file
|
2012-03-01 02:14:15 +00:00
|
|
|
diff --git a/nitfol b/nitfol
|
|
|
|
deleted file mode 100644
|
2019-10-28 00:58:59 +00:00
|
|
|
index $symlink..0000000
|
2012-03-01 02:14:15 +00:00
|
|
|
--- a/nitfol
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-xyzzy
|
2012-03-01 02:14:14 +00:00
|
|
|
EOF
|
|
|
|
mv frotz frotz2 &&
|
2012-03-01 02:14:15 +00:00
|
|
|
mv nitfol nitfol2 &&
|
2012-03-01 02:14:14 +00:00
|
|
|
git diff-index -M -p $tree >current &&
|
|
|
|
compare_diff_patch expected current
|
|
|
|
'
|
2005-12-26 21:31:42 +00:00
|
|
|
|
2013-06-07 20:53:34 +00:00
|
|
|
test_expect_success 'diff identical, but newly created symlink and file' '
|
diff -p: squelch "diff --git" header for stat-dirty paths
The plumbing "diff" commands look at the working tree files without
refreshing the index themselves for performance reasons (the calling
script is expected to do that upfront just once, before calling one or
more of them). In the early days of git, they showed the "diff --git"
header before they actually ask the xdiff machinery to produce patches,
and ended up showing only these headers if the real contents are the same
and the difference they noticed was only because the stat info cached in
the index did not match that of the working tree. It was too late for the
implementation to take the header that it already emitted back.
But 3e97c7c (No diff -b/-w output for all-whitespace changes, 2009-11-19)
introduced necessary logic to keep the meta-information headers in a
strbuf and delay their output until the xdiff machinery noticed actual
changes. This was primarily in order to generate patches that ignore
whitespaces. When operating under "-w" mode, we wouldn't know if the
header is needed until we actually look at the resulting patch, so it was
a sensible thing to do, but we did not realize that the same reasoning
applies to stat-dirty paths.
Later, 296c6bb (diff: fix "git show -C -C" output when renaming a binary
file, 2010-05-26) generalized this machinery and added must_show_header
toggle. This is turned on when the header must be shown even when there
is no patch to be produced, e.g. only the mode was changed, or the path
was renamed, without changing the contents. However, when it did so, it
still kept the special case for the "-w" mode, which meant that the
plumbing would keep showing these phantom changes.
This corrects this historical inconsistency by allowing the plumbing to
omit paths that are only stat-dirty from its output in the same way as it
handles whitespace only changes under "-w" option.
The change in the behaviour can be seen in the updated test.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-01 02:14:16 +00:00
|
|
|
>expected &&
|
2012-03-01 02:14:15 +00:00
|
|
|
rm -f frotz nitfol &&
|
|
|
|
echo xyzzy >nitfol &&
|
2018-03-24 07:44:31 +00:00
|
|
|
test-tool chmtime +10 nitfol &&
|
2013-06-07 20:53:34 +00:00
|
|
|
if test_have_prereq SYMLINKS
|
|
|
|
then
|
|
|
|
ln -s xyzzy frotz
|
|
|
|
else
|
|
|
|
printf xyzzy >frotz
|
|
|
|
# the symlink property propagates from the index
|
|
|
|
fi &&
|
2012-03-01 02:14:14 +00:00
|
|
|
git diff-index -M -p $tree >current &&
|
2012-03-01 02:14:15 +00:00
|
|
|
compare_diff_patch expected current &&
|
|
|
|
|
|
|
|
>expected &&
|
|
|
|
git diff-index -M -p -w $tree >current &&
|
2012-03-01 02:14:14 +00:00
|
|
|
compare_diff_patch expected current
|
|
|
|
'
|
2005-12-26 21:31:42 +00:00
|
|
|
|
2013-06-07 20:53:34 +00:00
|
|
|
test_expect_success 'diff different symlink and file' '
|
2019-10-28 00:58:59 +00:00
|
|
|
new=$(symlink_oid yxyyz) &&
|
|
|
|
cat >expected <<-EOF &&
|
2012-03-01 02:14:14 +00:00
|
|
|
diff --git a/frotz b/frotz
|
2019-10-28 00:58:59 +00:00
|
|
|
index $symlink..$new 120000
|
2012-03-01 02:14:14 +00:00
|
|
|
--- a/frotz
|
|
|
|
+++ b/frotz
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-xyzzy
|
|
|
|
\ No newline at end of file
|
|
|
|
+yxyyz
|
|
|
|
\ No newline at end of file
|
2012-03-01 02:14:15 +00:00
|
|
|
diff --git a/nitfol b/nitfol
|
2019-10-28 00:58:59 +00:00
|
|
|
index $symlink..$new 100644
|
2012-03-01 02:14:15 +00:00
|
|
|
--- a/nitfol
|
|
|
|
+++ b/nitfol
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-xyzzy
|
|
|
|
+yxyyz
|
2012-03-01 02:14:14 +00:00
|
|
|
EOF
|
|
|
|
rm -f frotz &&
|
2013-06-07 20:53:34 +00:00
|
|
|
if test_have_prereq SYMLINKS
|
|
|
|
then
|
|
|
|
ln -s yxyyz frotz
|
|
|
|
else
|
|
|
|
printf yxyyz >frotz
|
|
|
|
# the symlink property propagates from the index
|
|
|
|
fi &&
|
2012-03-01 02:14:15 +00:00
|
|
|
echo yxyyz >nitfol &&
|
2012-03-01 02:14:14 +00:00
|
|
|
git diff-index -M -p $tree >current &&
|
|
|
|
compare_diff_patch expected current
|
|
|
|
'
|
2005-12-26 21:31:42 +00:00
|
|
|
|
2012-03-01 02:14:14 +00:00
|
|
|
test_expect_success SYMLINKS 'diff symlinks with non-existing targets' '
|
|
|
|
ln -s narf pinky &&
|
|
|
|
ln -s take\ over brain &&
|
|
|
|
test_must_fail git diff --no-index pinky brain >output 2>output.err &&
|
|
|
|
grep narf output &&
|
2018-08-19 21:57:22 +00:00
|
|
|
test_must_be_empty output.err
|
2012-03-01 02:14:14 +00:00
|
|
|
'
|
2010-09-21 21:01:24 +00:00
|
|
|
|
|
|
|
test_expect_success SYMLINKS 'setup symlinks with attributes' '
|
|
|
|
echo "*.bin diff=bin" >>.gitattributes &&
|
|
|
|
echo content >file.bin &&
|
|
|
|
ln -s file.bin link.bin &&
|
|
|
|
git add -N file.bin link.bin
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
|
2019-10-28 00:58:59 +00:00
|
|
|
file=$(short_oid file.bin) &&
|
|
|
|
link=$(symlink_oid file.bin) &&
|
|
|
|
cat >expect <<-EOF &&
|
2012-03-01 02:14:14 +00:00
|
|
|
diff --git a/file.bin b/file.bin
|
2018-05-26 12:08:44 +00:00
|
|
|
new file mode 100644
|
2019-10-28 00:58:59 +00:00
|
|
|
index 0000000..$file
|
2018-05-26 12:08:44 +00:00
|
|
|
Binary files /dev/null and b/file.bin differ
|
2012-03-01 02:14:14 +00:00
|
|
|
diff --git a/link.bin b/link.bin
|
2018-05-26 12:08:44 +00:00
|
|
|
new file mode 120000
|
2019-10-28 00:58:59 +00:00
|
|
|
index 0000000..$link
|
2018-05-26 12:08:44 +00:00
|
|
|
--- /dev/null
|
2012-03-01 02:14:14 +00:00
|
|
|
+++ b/link.bin
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+file.bin
|
|
|
|
\ No newline at end of file
|
|
|
|
EOF
|
2010-09-21 21:01:24 +00:00
|
|
|
git config diff.bin.binary true &&
|
|
|
|
git diff file.bin link.bin >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2005-12-26 21:31:42 +00:00
|
|
|
test_done
|