#!/bin/sh # # Copyright (c) 2005 Johannes Schindelin # global test_description := ''Test diff of symlinks. '' source ./test-lib.sh source "$TEST_DIRECTORY"/diff-lib.sh test_expect_success 'diff new symlink and file' ' cat >expected <<-\EOF && diff --git a/frotz b/frotz new file mode 120000 index 0000000..7c465af --- /dev/null +++ b/frotz @@ -0,0 +1 @@ +xyzzy \ 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 # the empty tree git update-index && tree=$(git write-tree) && test_ln_s_add xyzzy frotz && echo xyzzy >nitfol && git update-index --add nitfol && GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current && compare_diff_patch expected current ' test_expect_success 'diff unchanged symlink and file' ' tree=$(git write-tree) && git update-index frotz nitfol && test -z "$(git diff-index --name-only $tree)" ' test_expect_success 'diff removed symlink and file' ' 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 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 'diff identical, but newly created symlink and file' ' >expected && rm -f frotz nitfol && echo xyzzy >nitfol && test-chmtime +10 nitfol && if test_have_prereq SYMLINKS then ln -s xyzzy frotz else printf xyzzy >frotz # the symlink property propagates from the index fi && git diff-index -M -p $tree >current && compare_diff_patch expected current && >expected && git diff-index -M -p -w $tree >current && compare_diff_patch expected current ' test_expect_success 'diff different symlink and file' ' cat >expected <<-\EOF && diff --git a/frotz b/frotz index 7c465af..df1db54 120000 --- a/frotz +++ 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 && if test_have_prereq SYMLINKS then ln -s yxyyz frotz else printf yxyyz >frotz # the symlink property propagates from the index fi && echo yxyyz >nitfol && git diff-index -M -p $tree >current && compare_diff_patch expected current ' 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 && ! test -s output.err ' 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' ' 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 diff file.bin link.bin >actual && test_cmp expect actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"Test diff of symlinks.\n"> <"\n">)} spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (C {(.)} {(DQ ($ VSub_Name "$TEST_DIRECTORY")) (/diff-lib.sh)}) (C {(test_expect_success)} {(SQ <"diff new symlink and file">)} { (SQ <"\n"> <"\tcat >expected <<-\\EOF &&\n"> <"\tdiff --git a/frotz b/frotz\n"> <"\tnew file mode 120000\n"> <"\tindex 0000000..7c465af\n"> <"\t--- /dev/null\n"> <"\t+++ b/frotz\n"> <"\t@@ -0,0 +1 @@\n"> <"\t+xyzzy\n"> <"\t\\ No newline at end of file\n"> <"\tdiff --git a/nitfol b/nitfol\n"> <"\tnew file mode 100644\n"> <"\tindex 0000000..7c465af\n"> <"\t--- /dev/null\n"> <"\t+++ b/nitfol\n"> <"\t@@ -0,0 +1 @@\n"> <"\t+xyzzy\n"> <"\tEOF\n"> <"\n"> <"\t# the empty tree\n"> <"\tgit update-index &&\n"> <"\ttree=$(git write-tree) &&\n"> <"\n"> <"\ttest_ln_s_add xyzzy frotz &&\n"> <"\techo xyzzy >nitfol &&\n"> <"\tgit update-index --add nitfol &&\n"> <"\tGIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current &&\n"> <"\tcompare_diff_patch expected current\n"> ) } ) (C {(test_expect_success)} {(SQ <"diff unchanged symlink and file">)} { (SQ <"\n"> <"\ttree=$(git write-tree) &&\n"> <"\tgit update-index frotz nitfol &&\n"> <"\ttest -z \"$(git diff-index --name-only $tree)\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"diff removed symlink and file">)} { (SQ <"\n"> <"\tcat >expected <<-\\EOF &&\n"> <"\tdiff --git a/frotz b/frotz\n"> <"\tdeleted file mode 120000\n"> <"\tindex 7c465af..0000000\n"> <"\t--- a/frotz\n"> <"\t+++ /dev/null\n"> <"\t@@ -1 +0,0 @@\n"> <"\t-xyzzy\n"> <"\t\\ No newline at end of file\n"> <"\tdiff --git a/nitfol b/nitfol\n"> <"\tdeleted file mode 100644\n"> <"\tindex 7c465af..0000000\n"> <"\t--- a/nitfol\n"> <"\t+++ /dev/null\n"> <"\t@@ -1 +0,0 @@\n"> <"\t-xyzzy\n"> <"\tEOF\n"> <"\tmv frotz frotz2 &&\n"> <"\tmv nitfol nitfol2 &&\n"> <"\tgit diff-index -M -p $tree >current &&\n"> <"\tcompare_diff_patch expected current\n"> ) } ) (C {(test_expect_success)} {(SQ <"diff identical, but newly created symlink and file">)} { (SQ <"\n"> <"\t>expected &&\n"> <"\trm -f frotz nitfol &&\n"> <"\techo xyzzy >nitfol &&\n"> <"\ttest-chmtime +10 nitfol &&\n"> <"\tif test_have_prereq SYMLINKS\n"> <"\tthen\n"> <"\t\tln -s xyzzy frotz\n"> <"\telse\n"> <"\t\tprintf xyzzy >frotz\n"> <"\t\t# the symlink property propagates from the index\n"> <"\tfi &&\n"> <"\tgit diff-index -M -p $tree >current &&\n"> <"\tcompare_diff_patch expected current &&\n"> <"\n"> <"\t>expected &&\n"> <"\tgit diff-index -M -p -w $tree >current &&\n"> <"\tcompare_diff_patch expected current\n"> ) } ) (C {(test_expect_success)} {(SQ <"diff different symlink and file">)} { (SQ <"\n"> <"\tcat >expected <<-\\EOF &&\n"> <"\tdiff --git a/frotz b/frotz\n"> <"\tindex 7c465af..df1db54 120000\n"> <"\t--- a/frotz\n"> <"\t+++ b/frotz\n"> <"\t@@ -1 +1 @@\n"> <"\t-xyzzy\n"> <"\t\\ No newline at end of file\n"> <"\t+yxyyz\n"> <"\t\\ No newline at end of file\n"> <"\tdiff --git a/nitfol b/nitfol\n"> <"\tindex 7c465af..df1db54 100644\n"> <"\t--- a/nitfol\n"> <"\t+++ b/nitfol\n"> <"\t@@ -1 +1 @@\n"> <"\t-xyzzy\n"> <"\t+yxyyz\n"> <"\tEOF\n"> <"\trm -f frotz &&\n"> <"\tif test_have_prereq SYMLINKS\n"> <"\tthen\n"> <"\t\tln -s yxyyz frotz\n"> <"\telse\n"> <"\t\tprintf yxyyz >frotz\n"> <"\t\t# the symlink property propagates from the index\n"> <"\tfi &&\n"> <"\techo yxyyz >nitfol &&\n"> <"\tgit diff-index -M -p $tree >current &&\n"> <"\tcompare_diff_patch expected current\n"> ) } ) (C {(test_expect_success)} {(SYMLINKS)} {(SQ <"diff symlinks with non-existing targets">)} { (SQ <"\n"> <"\tln -s narf pinky &&\n"> <"\tln -s take\\ over brain &&\n"> <"\ttest_must_fail git diff --no-index pinky brain >output 2>output.err &&\n"> <"\tgrep narf output &&\n"> <"\t! test -s output.err\n"> ) } ) (C {(test_expect_success)} {(SYMLINKS)} {(SQ <"setup symlinks with attributes">)} { (SQ <"\n"> <"\techo \"*.bin diff=bin\" >>.gitattributes &&\n"> <"\techo content >file.bin &&\n"> <"\tln -s file.bin link.bin &&\n"> <"\tgit add -N file.bin link.bin\n"> ) } ) (C {(test_expect_success)} {(SYMLINKS)} {(SQ <"symlinks do not respect userdiff config by path">)} { (SQ <"\n"> <"\tcat >expect <<-\\EOF &&\n"> <"\tdiff --git a/file.bin b/file.bin\n"> <"\tindex e69de29..d95f3ad 100644\n"> <"\tBinary files a/file.bin and b/file.bin differ\n"> <"\tdiff --git a/link.bin b/link.bin\n"> <"\tindex e69de29..dce41ec 120000\n"> <"\t--- a/link.bin\n"> <"\t+++ b/link.bin\n"> <"\t@@ -0,0 +1 @@\n"> <"\t+file.bin\n"> <"\t\\ No newline at end of file\n"> <"\tEOF\n"> <"\tgit config diff.bin.binary true &&\n"> <"\tgit diff file.bin link.bin >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_done)}) ] )