Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Johannes Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='Test diff of symlinks. |
| 7 | |
| 8 | ' |
| 9 | . ./test-lib.sh |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 10 | . "$TEST_DIRECTORY"/diff-lib.sh |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 11 | |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 12 | # Print the short OID of a symlink with the given name. |
| 13 | symlink_oid () { |
| 14 | local oid=$(printf "%s" "$1" | git hash-object --stdin) && |
| 15 | git rev-parse --short "$oid" |
| 16 | } |
| 17 | |
| 18 | # Print the short OID of the given file. |
| 19 | short_oid () { |
| 20 | local oid=$(git hash-object "$1") && |
| 21 | git rev-parse --short "$oid" |
| 22 | } |
| 23 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 24 | test_expect_success 'diff new symlink and file' ' |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 25 | symlink=$(symlink_oid xyzzy) && |
| 26 | cat >expected <<-EOF && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 27 | diff --git a/frotz b/frotz |
| 28 | new file mode 120000 |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 29 | index 0000000..$symlink |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 30 | --- /dev/null |
| 31 | +++ b/frotz |
| 32 | @@ -0,0 +1 @@ |
| 33 | +xyzzy |
| 34 | \ No newline at end of file |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 35 | diff --git a/nitfol b/nitfol |
| 36 | new file mode 100644 |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 37 | index 0000000..$symlink |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 38 | --- /dev/null |
| 39 | +++ b/nitfol |
| 40 | @@ -0,0 +1 @@ |
| 41 | +xyzzy |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 42 | EOF |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 43 | |
| 44 | # the empty tree |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 45 | git update-index && |
| 46 | tree=$(git write-tree) && |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 47 | |
| 48 | test_ln_s_add xyzzy frotz && |
| 49 | echo xyzzy >nitfol && |
| 50 | git update-index --add nitfol && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 51 | GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current && |
| 52 | compare_diff_patch expected current |
| 53 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 54 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 55 | test_expect_success 'diff unchanged symlink and file' ' |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 56 | tree=$(git write-tree) && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 57 | git update-index frotz nitfol && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 58 | test -z "$(git diff-index --name-only $tree)" |
| 59 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 60 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 61 | test_expect_success 'diff removed symlink and file' ' |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 62 | cat >expected <<-EOF && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 63 | diff --git a/frotz b/frotz |
| 64 | deleted file mode 120000 |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 65 | index $symlink..0000000 |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 66 | --- a/frotz |
| 67 | +++ /dev/null |
| 68 | @@ -1 +0,0 @@ |
| 69 | -xyzzy |
| 70 | \ No newline at end of file |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 71 | diff --git a/nitfol b/nitfol |
| 72 | deleted file mode 100644 |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 73 | index $symlink..0000000 |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 74 | --- a/nitfol |
| 75 | +++ /dev/null |
| 76 | @@ -1 +0,0 @@ |
| 77 | -xyzzy |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 78 | EOF |
| 79 | mv frotz frotz2 && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 80 | mv nitfol nitfol2 && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 81 | git diff-index -M -p $tree >current && |
| 82 | compare_diff_patch expected current |
| 83 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 84 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 85 | test_expect_success 'diff identical, but newly created symlink and file' ' |
Junio C Hamano | b3f01ff | 2012-02-29 18:14:16 -0800 | [diff] [blame] | 86 | >expected && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 87 | rm -f frotz nitfol && |
| 88 | echo xyzzy >nitfol && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 89 | test-tool chmtime +10 nitfol && |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 90 | if test_have_prereq SYMLINKS |
| 91 | then |
| 92 | ln -s xyzzy frotz |
| 93 | else |
| 94 | printf xyzzy >frotz |
| 95 | # the symlink property propagates from the index |
| 96 | fi && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 97 | git diff-index -M -p $tree >current && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 98 | compare_diff_patch expected current && |
| 99 | |
| 100 | >expected && |
| 101 | git diff-index -M -p -w $tree >current && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 102 | compare_diff_patch expected current |
| 103 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 104 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 105 | test_expect_success 'diff different symlink and file' ' |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 106 | new=$(symlink_oid yxyyz) && |
| 107 | cat >expected <<-EOF && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 108 | diff --git a/frotz b/frotz |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 109 | index $symlink..$new 120000 |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 110 | --- a/frotz |
| 111 | +++ b/frotz |
| 112 | @@ -1 +1 @@ |
| 113 | -xyzzy |
| 114 | \ No newline at end of file |
| 115 | +yxyyz |
| 116 | \ No newline at end of file |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 117 | diff --git a/nitfol b/nitfol |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 118 | index $symlink..$new 100644 |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 119 | --- a/nitfol |
| 120 | +++ b/nitfol |
| 121 | @@ -1 +1 @@ |
| 122 | -xyzzy |
| 123 | +yxyyz |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 124 | EOF |
| 125 | rm -f frotz && |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 126 | if test_have_prereq SYMLINKS |
| 127 | then |
| 128 | ln -s yxyyz frotz |
| 129 | else |
| 130 | printf yxyyz >frotz |
| 131 | # the symlink property propagates from the index |
| 132 | fi && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 133 | echo yxyyz >nitfol && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 134 | git diff-index -M -p $tree >current && |
| 135 | compare_diff_patch expected current |
| 136 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 137 | |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 138 | test_expect_success SYMLINKS 'diff symlinks with non-existing targets' ' |
| 139 | ln -s narf pinky && |
| 140 | ln -s take\ over brain && |
| 141 | test_must_fail git diff --no-index pinky brain >output 2>output.err && |
| 142 | grep narf output && |
SZEDER Gábor | ec10b01 | 2018-08-19 23:57:22 +0200 | [diff] [blame] | 143 | test_must_be_empty output.err |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 144 | ' |
Jeff King | d391c0f | 2010-09-21 17:01:24 -0400 | [diff] [blame] | 145 | |
| 146 | test_expect_success SYMLINKS 'setup symlinks with attributes' ' |
| 147 | echo "*.bin diff=bin" >>.gitattributes && |
| 148 | echo content >file.bin && |
| 149 | ln -s file.bin link.bin && |
| 150 | git add -N file.bin link.bin |
| 151 | ' |
| 152 | |
Jeff King | d391c0f | 2010-09-21 17:01:24 -0400 | [diff] [blame] | 153 | test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' ' |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 154 | file=$(short_oid file.bin) && |
| 155 | link=$(symlink_oid file.bin) && |
| 156 | cat >expect <<-EOF && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 157 | diff --git a/file.bin b/file.bin |
Nguyễn Thái Ngọc Duy | 0231ae7 | 2018-05-26 14:08:44 +0200 | [diff] [blame] | 158 | new file mode 100644 |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 159 | index 0000000..$file |
Nguyễn Thái Ngọc Duy | 0231ae7 | 2018-05-26 14:08:44 +0200 | [diff] [blame] | 160 | Binary files /dev/null and b/file.bin differ |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 161 | diff --git a/link.bin b/link.bin |
Nguyễn Thái Ngọc Duy | 0231ae7 | 2018-05-26 14:08:44 +0200 | [diff] [blame] | 162 | new file mode 120000 |
brian m. carlson | 840624f | 2019-10-28 00:58:59 +0000 | [diff] [blame] | 163 | index 0000000..$link |
Nguyễn Thái Ngọc Duy | 0231ae7 | 2018-05-26 14:08:44 +0200 | [diff] [blame] | 164 | --- /dev/null |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 165 | +++ b/link.bin |
| 166 | @@ -0,0 +1 @@ |
| 167 | +file.bin |
| 168 | \ No newline at end of file |
| 169 | EOF |
Jeff King | d391c0f | 2010-09-21 17:01:24 -0400 | [diff] [blame] | 170 | git config diff.bin.binary true && |
| 171 | git diff file.bin link.bin >actual && |
| 172 | test_cmp expect actual |
| 173 | ' |
| 174 | |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 175 | test_done |