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 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 12 | test_expect_success 'diff new symlink and file' ' |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 13 | cat >expected <<-\EOF && |
| 14 | diff --git a/frotz b/frotz |
| 15 | new file mode 120000 |
| 16 | index 0000000..7c465af |
| 17 | --- /dev/null |
| 18 | +++ b/frotz |
| 19 | @@ -0,0 +1 @@ |
| 20 | +xyzzy |
| 21 | \ No newline at end of file |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 22 | diff --git a/nitfol b/nitfol |
| 23 | new file mode 100644 |
| 24 | index 0000000..7c465af |
| 25 | --- /dev/null |
| 26 | +++ b/nitfol |
| 27 | @@ -0,0 +1 @@ |
| 28 | +xyzzy |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 29 | EOF |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 30 | |
| 31 | # the empty tree |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 32 | git update-index && |
| 33 | tree=$(git write-tree) && |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 34 | |
| 35 | test_ln_s_add xyzzy frotz && |
| 36 | echo xyzzy >nitfol && |
| 37 | git update-index --add nitfol && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 38 | GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current && |
| 39 | compare_diff_patch expected current |
| 40 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 41 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 42 | test_expect_success 'diff unchanged symlink and file' ' |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 43 | tree=$(git write-tree) && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 44 | git update-index frotz nitfol && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 45 | test -z "$(git diff-index --name-only $tree)" |
| 46 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 47 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 48 | test_expect_success 'diff removed symlink and file' ' |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 49 | cat >expected <<-\EOF && |
| 50 | diff --git a/frotz b/frotz |
| 51 | deleted file mode 120000 |
| 52 | index 7c465af..0000000 |
| 53 | --- a/frotz |
| 54 | +++ /dev/null |
| 55 | @@ -1 +0,0 @@ |
| 56 | -xyzzy |
| 57 | \ No newline at end of file |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 58 | diff --git a/nitfol b/nitfol |
| 59 | deleted file mode 100644 |
| 60 | index 7c465af..0000000 |
| 61 | --- a/nitfol |
| 62 | +++ /dev/null |
| 63 | @@ -1 +0,0 @@ |
| 64 | -xyzzy |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 65 | EOF |
| 66 | mv frotz frotz2 && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 67 | mv nitfol nitfol2 && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 68 | git diff-index -M -p $tree >current && |
| 69 | compare_diff_patch expected current |
| 70 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 71 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 72 | test_expect_success 'diff identical, but newly created symlink and file' ' |
Junio C Hamano | b3f01ff | 2012-02-29 18:14:16 -0800 | [diff] [blame] | 73 | >expected && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 74 | rm -f frotz nitfol && |
| 75 | echo xyzzy >nitfol && |
| 76 | test-chmtime +10 nitfol && |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 77 | if test_have_prereq SYMLINKS |
| 78 | then |
| 79 | ln -s xyzzy frotz |
| 80 | else |
| 81 | printf xyzzy >frotz |
| 82 | # the symlink property propagates from the index |
| 83 | fi && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 84 | git diff-index -M -p $tree >current && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 85 | compare_diff_patch expected current && |
| 86 | |
| 87 | >expected && |
| 88 | git diff-index -M -p -w $tree >current && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 89 | compare_diff_patch expected current |
| 90 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 91 | |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 92 | test_expect_success 'diff different symlink and file' ' |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 93 | cat >expected <<-\EOF && |
| 94 | diff --git a/frotz b/frotz |
| 95 | index 7c465af..df1db54 120000 |
| 96 | --- a/frotz |
| 97 | +++ b/frotz |
| 98 | @@ -1 +1 @@ |
| 99 | -xyzzy |
| 100 | \ No newline at end of file |
| 101 | +yxyyz |
| 102 | \ No newline at end of file |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 103 | diff --git a/nitfol b/nitfol |
| 104 | index 7c465af..df1db54 100644 |
| 105 | --- a/nitfol |
| 106 | +++ b/nitfol |
| 107 | @@ -1 +1 @@ |
| 108 | -xyzzy |
| 109 | +yxyyz |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 110 | EOF |
| 111 | rm -f frotz && |
Johannes Sixt | 70836a6 | 2013-06-07 22:53:34 +0200 | [diff] [blame] | 112 | if test_have_prereq SYMLINKS |
| 113 | then |
| 114 | ln -s yxyyz frotz |
| 115 | else |
| 116 | printf yxyyz >frotz |
| 117 | # the symlink property propagates from the index |
| 118 | fi && |
Junio C Hamano | 5597e84 | 2012-02-29 18:14:15 -0800 | [diff] [blame] | 119 | echo yxyyz >nitfol && |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 120 | git diff-index -M -p $tree >current && |
| 121 | compare_diff_patch expected current |
| 122 | ' |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 123 | |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 124 | test_expect_success SYMLINKS 'diff symlinks with non-existing targets' ' |
| 125 | ln -s narf pinky && |
| 126 | ln -s take\ over brain && |
| 127 | test_must_fail git diff --no-index pinky brain >output 2>output.err && |
| 128 | grep narf output && |
| 129 | ! test -s output.err |
| 130 | ' |
Jeff King | d391c0f | 2010-09-21 17:01:24 -0400 | [diff] [blame] | 131 | |
| 132 | test_expect_success SYMLINKS 'setup symlinks with attributes' ' |
| 133 | echo "*.bin diff=bin" >>.gitattributes && |
| 134 | echo content >file.bin && |
| 135 | ln -s file.bin link.bin && |
| 136 | git add -N file.bin link.bin |
| 137 | ' |
| 138 | |
Jeff King | d391c0f | 2010-09-21 17:01:24 -0400 | [diff] [blame] | 139 | test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' ' |
Junio C Hamano | 13a4899 | 2012-02-29 18:14:14 -0800 | [diff] [blame] | 140 | cat >expect <<-\EOF && |
| 141 | diff --git a/file.bin b/file.bin |
| 142 | index e69de29..d95f3ad 100644 |
| 143 | Binary files a/file.bin and b/file.bin differ |
| 144 | diff --git a/link.bin b/link.bin |
| 145 | index e69de29..dce41ec 120000 |
| 146 | --- a/link.bin |
| 147 | +++ b/link.bin |
| 148 | @@ -0,0 +1 @@ |
| 149 | +file.bin |
| 150 | \ No newline at end of file |
| 151 | EOF |
Jeff King | d391c0f | 2010-09-21 17:01:24 -0400 | [diff] [blame] | 152 | git config diff.bin.binary true && |
| 153 | git diff file.bin link.bin >actual && |
| 154 | test_cmp expect actual |
| 155 | ' |
| 156 | |
Johannes Schindelin | 975b31d | 2005-12-26 22:31:42 +0100 | [diff] [blame] | 157 | test_done |