Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='CRLF conversion' |
| 4 | |
Johannes Schindelin | 06d5314 | 2020-11-18 23:44:21 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Ævar Arnfjörð Bjarmason | 9081a42 | 2021-11-16 19:27:38 +0100 | [diff] [blame] | 8 | TEST_PASSES_SANITIZE_LEAK=true |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 9 | . ./test-lib.sh |
| 10 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 11 | has_cr() { |
| 12 | tr '\015' Q <"$1" | grep Q >/dev/null |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 13 | } |
| 14 | |
Jeff King | fd77714 | 2015-03-25 01:28:44 -0400 | [diff] [blame] | 15 | # add or remove CRs to disk file in-place |
| 16 | # usage: munge_cr <append|remove> <file> |
| 17 | munge_cr () { |
| 18 | "${1}_cr" <"$2" >tmp && |
| 19 | mv tmp "$2" |
| 20 | } |
| 21 | |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 22 | test_expect_success setup ' |
| 23 | |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 24 | git config core.autocrlf false && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 25 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 26 | test_write_lines Hello world how are you >one && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 27 | mkdir dir && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 28 | test_write_lines I am very very fine thank you >dir/two && |
| 29 | test_write_lines Oh here is NULQin text here | q_to_nul >three && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 30 | git add . && |
| 31 | |
| 32 | git commit -m initial && |
| 33 | |
Elia Pinto | def226b | 2014-04-28 05:57:26 -0700 | [diff] [blame] | 34 | one=$(git rev-parse HEAD:one) && |
| 35 | dir=$(git rev-parse HEAD:dir) && |
| 36 | two=$(git rev-parse HEAD:dir/two) && |
| 37 | three=$(git rev-parse HEAD:three) && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 38 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 39 | test_write_lines Some extra lines here >>one && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 40 | git diff >patch.file && |
Elia Pinto | def226b | 2014-04-28 05:57:26 -0700 | [diff] [blame] | 41 | patched=$(git hash-object --stdin <one) && |
Jeff King | be86fb3 | 2015-03-25 01:31:41 -0400 | [diff] [blame] | 42 | git read-tree --reset -u HEAD |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 43 | ' |
| 44 | |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 45 | test_expect_success 'safecrlf: autocrlf=input, all CRLF' ' |
| 46 | |
| 47 | git config core.autocrlf input && |
| 48 | git config core.safecrlf true && |
| 49 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 50 | test_write_lines I am all CRLF | append_cr >allcrlf && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 51 | test_must_fail git add allcrlf |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 52 | ' |
| 53 | |
| 54 | test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' ' |
| 55 | |
| 56 | git config core.autocrlf input && |
| 57 | git config core.safecrlf true && |
| 58 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 59 | test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 60 | test_must_fail git add mixed |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 61 | ' |
| 62 | |
| 63 | test_expect_success 'safecrlf: autocrlf=true, all LF' ' |
| 64 | |
| 65 | git config core.autocrlf true && |
| 66 | git config core.safecrlf true && |
| 67 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 68 | test_write_lines I am all LF >alllf && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 69 | test_must_fail git add alllf |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 70 | ' |
| 71 | |
| 72 | test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' ' |
| 73 | |
| 74 | git config core.autocrlf true && |
| 75 | git config core.safecrlf true && |
| 76 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 77 | test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 78 | test_must_fail git add mixed |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 79 | ' |
| 80 | |
| 81 | test_expect_success 'safecrlf: print warning only once' ' |
| 82 | |
| 83 | git config core.autocrlf input && |
| 84 | git config core.safecrlf warn && |
| 85 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 86 | test_write_lines I am all LF >doublewarn && |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 87 | git add doublewarn && |
| 88 | git commit -m "nowarn" && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 89 | test_write_lines Oh here is CRLFQ in text | q_to_cr >doublewarn && |
Vasco Almeida | 87cb784 | 2016-10-17 13:15:27 +0000 | [diff] [blame] | 90 | git add doublewarn 2>err && |
Ævar Arnfjörð Bjarmason | b1e0798 | 2021-02-11 02:53:52 +0100 | [diff] [blame] | 91 | grep "CRLF will be replaced by LF" err >err.warnings && |
| 92 | test_line_count = 1 err.warnings |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 93 | ' |
| 94 | |
Junio C Hamano | 5430bb2 | 2013-06-24 14:35:04 -0700 | [diff] [blame] | 95 | |
| 96 | test_expect_success 'safecrlf: git diff demotes safecrlf=true to warn' ' |
| 97 | git config core.autocrlf input && |
| 98 | git config core.safecrlf true && |
| 99 | git diff HEAD |
| 100 | ' |
| 101 | |
| 102 | |
Anthony Sottile | 6cb0912 | 2018-06-04 13:17:42 -0700 | [diff] [blame] | 103 | test_expect_success 'safecrlf: no warning with safecrlf=false' ' |
| 104 | git config core.autocrlf input && |
| 105 | git config core.safecrlf false && |
| 106 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 107 | test_write_lines I am all CRLF | append_cr >allcrlf && |
Anthony Sottile | 6cb0912 | 2018-06-04 13:17:42 -0700 | [diff] [blame] | 108 | git add allcrlf 2>err && |
| 109 | test_must_be_empty err |
| 110 | ' |
| 111 | |
| 112 | |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 113 | test_expect_success 'switch off autocrlf, safecrlf, reset HEAD' ' |
| 114 | git config core.autocrlf false && |
| 115 | git config core.safecrlf false && |
| 116 | git reset --hard HEAD^ |
| 117 | ' |
| 118 | |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 119 | test_expect_success 'update with autocrlf=input' ' |
| 120 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 121 | rm -f tmp one dir/two three && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 122 | git read-tree --reset -u HEAD && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 123 | git config core.autocrlf input && |
Jeff King | fd77714 | 2015-03-25 01:28:44 -0400 | [diff] [blame] | 124 | munge_cr append one && |
| 125 | munge_cr append dir/two && |
| 126 | git update-index -- one dir/two && |
Elia Pinto | def226b | 2014-04-28 05:57:26 -0700 | [diff] [blame] | 127 | differs=$(git diff-index --cached HEAD) && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 128 | test -z "$differs" |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 129 | |
| 130 | ' |
| 131 | |
| 132 | test_expect_success 'update with autocrlf=true' ' |
| 133 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 134 | rm -f tmp one dir/two three && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 135 | git read-tree --reset -u HEAD && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 136 | git config core.autocrlf true && |
Jeff King | fd77714 | 2015-03-25 01:28:44 -0400 | [diff] [blame] | 137 | munge_cr append one && |
| 138 | munge_cr append dir/two && |
| 139 | git update-index -- one dir/two && |
Elia Pinto | def226b | 2014-04-28 05:57:26 -0700 | [diff] [blame] | 140 | differs=$(git diff-index --cached HEAD) && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 141 | test -z "$differs" |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 142 | |
| 143 | ' |
| 144 | |
| 145 | test_expect_success 'checkout with autocrlf=true' ' |
| 146 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 147 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 148 | git config core.autocrlf true && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 149 | git read-tree --reset -u HEAD && |
Jeff King | fd77714 | 2015-03-25 01:28:44 -0400 | [diff] [blame] | 150 | munge_cr remove one && |
| 151 | munge_cr remove dir/two && |
| 152 | git update-index -- one dir/two && |
Elia Pinto | def226b | 2014-04-28 05:57:26 -0700 | [diff] [blame] | 153 | test "$one" = $(git hash-object --stdin <one) && |
| 154 | test "$two" = $(git hash-object --stdin <dir/two) && |
| 155 | differs=$(git diff-index --cached HEAD) && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 156 | test -z "$differs" |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 157 | ' |
| 158 | |
| 159 | test_expect_success 'checkout with autocrlf=input' ' |
| 160 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 161 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 162 | git config core.autocrlf input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 163 | git read-tree --reset -u HEAD && |
Denton Liu | f6041ab | 2019-12-20 10:15:53 -0800 | [diff] [blame] | 164 | ! has_cr one && |
| 165 | ! has_cr dir/two && |
Jeff King | fd77714 | 2015-03-25 01:28:44 -0400 | [diff] [blame] | 166 | git update-index -- one dir/two && |
Elia Pinto | def226b | 2014-04-28 05:57:26 -0700 | [diff] [blame] | 167 | test "$one" = $(git hash-object --stdin <one) && |
| 168 | test "$two" = $(git hash-object --stdin <dir/two) && |
| 169 | differs=$(git diff-index --cached HEAD) && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 170 | test -z "$differs" |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 171 | ' |
| 172 | |
| 173 | test_expect_success 'apply patch (autocrlf=input)' ' |
| 174 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 175 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 176 | git config core.autocrlf input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 177 | git read-tree --reset -u HEAD && |
| 178 | |
| 179 | git apply patch.file && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 180 | test "$patched" = "$(git hash-object --stdin <one)" |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 181 | ' |
| 182 | |
| 183 | test_expect_success 'apply patch --cached (autocrlf=input)' ' |
| 184 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 185 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 186 | git config core.autocrlf input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 187 | git read-tree --reset -u HEAD && |
| 188 | |
| 189 | git apply --cached patch.file && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 190 | test "$patched" = $(git rev-parse :one) |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 191 | ' |
| 192 | |
| 193 | test_expect_success 'apply patch --index (autocrlf=input)' ' |
| 194 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 195 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 196 | git config core.autocrlf input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 197 | git read-tree --reset -u HEAD && |
| 198 | |
| 199 | git apply --index patch.file && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 200 | test "$patched" = $(git rev-parse :one) && |
| 201 | test "$patched" = $(git hash-object --stdin <one) |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 202 | ' |
| 203 | |
| 204 | test_expect_success 'apply patch (autocrlf=true)' ' |
| 205 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 206 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 207 | git config core.autocrlf true && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 208 | git read-tree --reset -u HEAD && |
| 209 | |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 210 | git apply patch.file && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 211 | test "$patched" = "$(remove_cr <one | git hash-object --stdin)" |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 212 | ' |
| 213 | |
| 214 | test_expect_success 'apply patch --cached (autocrlf=true)' ' |
| 215 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 216 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 217 | git config core.autocrlf true && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 218 | git read-tree --reset -u HEAD && |
| 219 | |
| 220 | git apply --cached patch.file && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 221 | test "$patched" = $(git rev-parse :one) |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 222 | ' |
| 223 | |
Junio C Hamano | 6716027 | 2007-02-17 12:37:25 -0800 | [diff] [blame] | 224 | test_expect_success 'apply patch --index (autocrlf=true)' ' |
| 225 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 226 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 227 | git config core.autocrlf true && |
Junio C Hamano | 6716027 | 2007-02-17 12:37:25 -0800 | [diff] [blame] | 228 | git read-tree --reset -u HEAD && |
| 229 | |
| 230 | git apply --index patch.file && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 231 | test "$patched" = $(git rev-parse :one) && |
| 232 | test "$patched" = "$(remove_cr <one | git hash-object --stdin)" |
Junio C Hamano | 6716027 | 2007-02-17 12:37:25 -0800 | [diff] [blame] | 233 | ' |
| 234 | |
Junio C Hamano | 35ebfd6 | 2007-04-12 22:30:05 -0700 | [diff] [blame] | 235 | test_expect_success '.gitattributes says two is binary' ' |
| 236 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 237 | rm -f tmp one dir/two three && |
Junio C Hamano | e4aee10 | 2007-04-15 14:56:09 -0700 | [diff] [blame] | 238 | echo "two -crlf" >.gitattributes && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 239 | git config core.autocrlf true && |
Junio C Hamano | 35ebfd6 | 2007-04-12 22:30:05 -0700 | [diff] [blame] | 240 | git read-tree --reset -u HEAD && |
| 241 | |
Denton Liu | f6041ab | 2019-12-20 10:15:53 -0800 | [diff] [blame] | 242 | ! has_cr dir/two && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 243 | has_cr one && |
Denton Liu | f6041ab | 2019-12-20 10:15:53 -0800 | [diff] [blame] | 244 | ! has_cr three |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 245 | ' |
| 246 | |
| 247 | test_expect_success '.gitattributes says two is input' ' |
| 248 | |
| 249 | rm -f tmp one dir/two three && |
| 250 | echo "two crlf=input" >.gitattributes && |
| 251 | git read-tree --reset -u HEAD && |
| 252 | |
Denton Liu | f6041ab | 2019-12-20 10:15:53 -0800 | [diff] [blame] | 253 | ! has_cr dir/two |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 254 | ' |
| 255 | |
| 256 | test_expect_success '.gitattributes says two and three are text' ' |
| 257 | |
| 258 | rm -f tmp one dir/two three && |
| 259 | echo "t* crlf" >.gitattributes && |
| 260 | git read-tree --reset -u HEAD && |
| 261 | |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 262 | has_cr dir/two && |
| 263 | has_cr three |
Junio C Hamano | 35ebfd6 | 2007-04-12 22:30:05 -0700 | [diff] [blame] | 264 | ' |
| 265 | |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 266 | test_expect_success 'in-tree .gitattributes (1)' ' |
| 267 | |
| 268 | echo "one -crlf" >>.gitattributes && |
| 269 | git add .gitattributes && |
| 270 | git commit -m "Add .gitattributes" && |
| 271 | |
| 272 | rm -rf tmp one dir .gitattributes patch.file three && |
| 273 | git read-tree --reset -u HEAD && |
| 274 | |
Denton Liu | f6041ab | 2019-12-20 10:15:53 -0800 | [diff] [blame] | 275 | ! has_cr one && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 276 | has_cr three |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 277 | ' |
| 278 | |
| 279 | test_expect_success 'in-tree .gitattributes (2)' ' |
| 280 | |
| 281 | rm -rf tmp one dir .gitattributes patch.file three && |
| 282 | git read-tree --reset HEAD && |
| 283 | git checkout-index -f -q -u -a && |
| 284 | |
Denton Liu | f6041ab | 2019-12-20 10:15:53 -0800 | [diff] [blame] | 285 | ! has_cr one && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 286 | has_cr three |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 287 | ' |
| 288 | |
| 289 | test_expect_success 'in-tree .gitattributes (3)' ' |
| 290 | |
| 291 | rm -rf tmp one dir .gitattributes patch.file three && |
| 292 | git read-tree --reset HEAD && |
| 293 | git checkout-index -u .gitattributes && |
| 294 | git checkout-index -u one dir/two three && |
| 295 | |
Denton Liu | f6041ab | 2019-12-20 10:15:53 -0800 | [diff] [blame] | 296 | ! has_cr one && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 297 | has_cr three |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 298 | ' |
| 299 | |
| 300 | test_expect_success 'in-tree .gitattributes (4)' ' |
| 301 | |
| 302 | rm -rf tmp one dir .gitattributes patch.file three && |
| 303 | git read-tree --reset HEAD && |
| 304 | git checkout-index -u one dir/two three && |
| 305 | git checkout-index -u .gitattributes && |
| 306 | |
Denton Liu | f6041ab | 2019-12-20 10:15:53 -0800 | [diff] [blame] | 307 | ! has_cr one && |
Jeff King | 8ddfce7 | 2023-05-08 15:04:57 -0400 | [diff] [blame] | 308 | has_cr three |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 309 | ' |
| 310 | |
Kristian Amlie | b997045 | 2009-03-20 10:32:09 +0100 | [diff] [blame] | 311 | test_expect_success 'checkout with existing .gitattributes' ' |
| 312 | |
| 313 | git config core.autocrlf true && |
| 314 | git config --unset core.safecrlf && |
| 315 | echo ".file2 -crlfQ" | q_to_cr >> .gitattributes && |
| 316 | git add .gitattributes && |
| 317 | git commit -m initial && |
| 318 | echo ".file -crlfQ" | q_to_cr >> .gitattributes && |
| 319 | echo "contents" > .file && |
| 320 | git add .gitattributes .file && |
| 321 | git commit -m second && |
| 322 | |
Johannes Schindelin | 06d5314 | 2020-11-18 23:44:21 +0000 | [diff] [blame] | 323 | git checkout main~1 && |
| 324 | git checkout main && |
Kristian Amlie | b997045 | 2009-03-20 10:32:09 +0100 | [diff] [blame] | 325 | test "$(git diff-files --raw)" = "" |
| 326 | |
| 327 | ' |
| 328 | |
| 329 | test_expect_success 'checkout when deleting .gitattributes' ' |
| 330 | |
| 331 | git rm .gitattributes && |
| 332 | echo "contentsQ" | q_to_cr > .file2 && |
| 333 | git add .file2 && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 334 | git commit -m third && |
Kristian Amlie | b997045 | 2009-03-20 10:32:09 +0100 | [diff] [blame] | 335 | |
Johannes Schindelin | 06d5314 | 2020-11-18 23:44:21 +0000 | [diff] [blame] | 336 | git checkout main~1 && |
| 337 | git checkout main && |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 338 | has_cr .file2 |
Kristian Amlie | b997045 | 2009-03-20 10:32:09 +0100 | [diff] [blame] | 339 | |
| 340 | ' |
| 341 | |
Steffen Prohaska | d7b0a09 | 2007-10-18 22:02:35 +0200 | [diff] [blame] | 342 | test_expect_success 'invalid .gitattributes (must not crash)' ' |
| 343 | |
| 344 | echo "three +crlf" >>.gitattributes && |
| 345 | git diff |
| 346 | |
| 347 | ' |
Finn Arne Gangstad | c480539 | 2010-05-12 00:37:57 +0200 | [diff] [blame] | 348 | # Some more tests here to add new autocrlf functionality. |
| 349 | # We want to have a known state here, so start a bit from scratch |
| 350 | |
| 351 | test_expect_success 'setting up for new autocrlf tests' ' |
| 352 | git config core.autocrlf false && |
| 353 | git config core.safecrlf false && |
| 354 | rm -rf .????* * && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 355 | test_write_lines I am all LF >alllf && |
| 356 | test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed && |
| 357 | test_write_lines I am all CRLF | append_cr >allcrlf && |
Finn Arne Gangstad | c480539 | 2010-05-12 00:37:57 +0200 | [diff] [blame] | 358 | git add -A . && |
| 359 | git commit -m "alllf, allcrlf and mixed only" && |
| 360 | git tag -a -m "message" autocrlf-checkpoint |
| 361 | ' |
| 362 | |
| 363 | test_expect_success 'report no change after setting autocrlf' ' |
| 364 | git config core.autocrlf true && |
| 365 | touch * && |
| 366 | git diff --exit-code |
| 367 | ' |
| 368 | |
| 369 | test_expect_success 'files are clean after checkout' ' |
| 370 | rm * && |
| 371 | git checkout -f && |
| 372 | git diff --exit-code |
| 373 | ' |
| 374 | |
| 375 | cr_to_Q_no_NL () { |
| 376 | tr '\015' Q | tr -d '\012' |
| 377 | } |
| 378 | |
| 379 | test_expect_success 'LF only file gets CRLF with autocrlf' ' |
| 380 | test "$(cr_to_Q_no_NL < alllf)" = "IQamQallQLFQ" |
| 381 | ' |
| 382 | |
| 383 | test_expect_success 'Mixed file is still mixed with autocrlf' ' |
| 384 | test "$(cr_to_Q_no_NL < mixed)" = "OhhereisCRLFQintext" |
| 385 | ' |
| 386 | |
| 387 | test_expect_success 'CRLF only file has CRLF with autocrlf' ' |
| 388 | test "$(cr_to_Q_no_NL < allcrlf)" = "IQamQallQCRLFQ" |
| 389 | ' |
| 390 | |
| 391 | test_expect_success 'New CRLF file gets LF in repo' ' |
| 392 | tr -d "\015" < alllf | append_cr > alllf2 && |
| 393 | git add alllf2 && |
| 394 | git commit -m "alllf2 added" && |
| 395 | git config core.autocrlf false && |
| 396 | rm * && |
| 397 | git checkout -f && |
| 398 | test_cmp alllf alllf2 |
| 399 | ' |
Steffen Prohaska | d7b0a09 | 2007-10-18 22:02:35 +0200 | [diff] [blame] | 400 | |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 401 | test_done |