Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='CRLF conversion' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 7 | has_cr() { |
| 8 | tr '\015' Q <"$1" | grep Q >/dev/null |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 9 | } |
| 10 | |
| 11 | test_expect_success setup ' |
| 12 | |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 13 | git config core.autocrlf false && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 14 | |
| 15 | for w in Hello world how are you; do echo $w; done >one && |
| 16 | mkdir dir && |
| 17 | for w in I am very very fine thank you; do echo $w; done >dir/two && |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 18 | for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 19 | git add . && |
| 20 | |
| 21 | git commit -m initial && |
| 22 | |
| 23 | one=`git rev-parse HEAD:one` && |
| 24 | dir=`git rev-parse HEAD:dir` && |
| 25 | two=`git rev-parse HEAD:dir/two` && |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 26 | three=`git rev-parse HEAD:three` && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 27 | |
| 28 | for w in Some extra lines here; do echo $w; done >>one && |
| 29 | git diff >patch.file && |
| 30 | patched=`git hash-object --stdin <one` && |
| 31 | git read-tree --reset -u HEAD && |
| 32 | |
| 33 | echo happy. |
| 34 | ' |
| 35 | |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 36 | test_expect_success 'safecrlf: autocrlf=input, all CRLF' ' |
| 37 | |
| 38 | git config core.autocrlf input && |
| 39 | git config core.safecrlf true && |
| 40 | |
| 41 | for w in I am all CRLF; do echo $w; done | append_cr >allcrlf && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 42 | test_must_fail git add allcrlf |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 43 | ' |
| 44 | |
| 45 | test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' ' |
| 46 | |
| 47 | git config core.autocrlf input && |
| 48 | git config core.safecrlf true && |
| 49 | |
| 50 | for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 51 | test_must_fail git add mixed |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 52 | ' |
| 53 | |
| 54 | test_expect_success 'safecrlf: autocrlf=true, all LF' ' |
| 55 | |
| 56 | git config core.autocrlf true && |
| 57 | git config core.safecrlf true && |
| 58 | |
| 59 | for w in I am all LF; do echo $w; done >alllf && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 60 | test_must_fail git add alllf |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 61 | ' |
| 62 | |
| 63 | test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' ' |
| 64 | |
| 65 | git config core.autocrlf true && |
| 66 | git config core.safecrlf true && |
| 67 | |
| 68 | for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 69 | test_must_fail git add mixed |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 70 | ' |
| 71 | |
| 72 | test_expect_success 'safecrlf: print warning only once' ' |
| 73 | |
| 74 | git config core.autocrlf input && |
| 75 | git config core.safecrlf warn && |
| 76 | |
| 77 | for w in I am all LF; do echo $w; done >doublewarn && |
| 78 | git add doublewarn && |
| 79 | git commit -m "nowarn" && |
| 80 | for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn && |
| 81 | test $(git add doublewarn 2>&1 | grep "CRLF will be replaced by LF" | wc -l) = 1 |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'switch off autocrlf, safecrlf, reset HEAD' ' |
| 85 | git config core.autocrlf false && |
| 86 | git config core.safecrlf false && |
| 87 | git reset --hard HEAD^ |
| 88 | ' |
| 89 | |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 90 | test_expect_success 'update with autocrlf=input' ' |
| 91 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 92 | rm -f tmp one dir/two three && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 93 | git read-tree --reset -u HEAD && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 94 | git config core.autocrlf input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 95 | |
| 96 | for f in one dir/two |
| 97 | do |
| 98 | append_cr <$f >tmp && mv -f tmp $f && |
| 99 | git update-index -- $f || { |
| 100 | echo Oops |
| 101 | false |
| 102 | break |
| 103 | } |
| 104 | done && |
| 105 | |
| 106 | differs=`git diff-index --cached HEAD` && |
| 107 | test -z "$differs" || { |
| 108 | echo Oops "$differs" |
| 109 | false |
| 110 | } |
| 111 | |
| 112 | ' |
| 113 | |
| 114 | test_expect_success 'update with autocrlf=true' ' |
| 115 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 116 | rm -f tmp one dir/two three && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 117 | git read-tree --reset -u HEAD && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 118 | git config core.autocrlf true && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 119 | |
| 120 | for f in one dir/two |
| 121 | do |
| 122 | append_cr <$f >tmp && mv -f tmp $f && |
| 123 | git update-index -- $f || { |
| 124 | echo "Oops $f" |
| 125 | false |
| 126 | break |
| 127 | } |
| 128 | done && |
| 129 | |
| 130 | differs=`git diff-index --cached HEAD` && |
| 131 | test -z "$differs" || { |
| 132 | echo Oops "$differs" |
| 133 | false |
| 134 | } |
| 135 | |
| 136 | ' |
| 137 | |
| 138 | test_expect_success 'checkout with autocrlf=true' ' |
| 139 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 140 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 141 | git config core.autocrlf true && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 142 | git read-tree --reset -u HEAD && |
| 143 | |
| 144 | for f in one dir/two |
| 145 | do |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 146 | remove_cr <"$f" >tmp && mv -f tmp $f && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 147 | git update-index -- $f || { |
| 148 | echo "Eh? $f" |
| 149 | false |
| 150 | break |
| 151 | } |
| 152 | done && |
| 153 | test "$one" = `git hash-object --stdin <one` && |
| 154 | test "$two" = `git hash-object --stdin <dir/two` && |
| 155 | differs=`git diff-index --cached HEAD` && |
| 156 | test -z "$differs" || { |
| 157 | echo Oops "$differs" |
| 158 | false |
| 159 | } |
| 160 | ' |
| 161 | |
| 162 | test_expect_success 'checkout with autocrlf=input' ' |
| 163 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 164 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 165 | git config core.autocrlf input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 166 | git read-tree --reset -u HEAD && |
| 167 | |
| 168 | for f in one dir/two |
| 169 | do |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 170 | if has_cr "$f" |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 171 | then |
| 172 | echo "Eh? $f" |
| 173 | false |
| 174 | break |
| 175 | else |
| 176 | git update-index -- $f |
| 177 | fi |
| 178 | done && |
| 179 | test "$one" = `git hash-object --stdin <one` && |
| 180 | test "$two" = `git hash-object --stdin <dir/two` && |
| 181 | differs=`git diff-index --cached HEAD` && |
| 182 | test -z "$differs" || { |
| 183 | echo Oops "$differs" |
| 184 | false |
| 185 | } |
| 186 | ' |
| 187 | |
| 188 | test_expect_success 'apply patch (autocrlf=input)' ' |
| 189 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 190 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 191 | git config core.autocrlf input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 192 | git read-tree --reset -u HEAD && |
| 193 | |
| 194 | git apply patch.file && |
| 195 | test "$patched" = "`git hash-object --stdin <one`" || { |
| 196 | echo "Eh? apply without index" |
| 197 | false |
| 198 | } |
| 199 | ' |
| 200 | |
| 201 | test_expect_success 'apply patch --cached (autocrlf=input)' ' |
| 202 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 203 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 204 | git config core.autocrlf input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 205 | git read-tree --reset -u HEAD && |
| 206 | |
| 207 | git apply --cached patch.file && |
| 208 | test "$patched" = `git rev-parse :one` || { |
| 209 | echo "Eh? apply with --cached" |
| 210 | false |
| 211 | } |
| 212 | ' |
| 213 | |
| 214 | test_expect_success 'apply patch --index (autocrlf=input)' ' |
| 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 input && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 218 | git read-tree --reset -u HEAD && |
| 219 | |
| 220 | git apply --index patch.file && |
| 221 | test "$patched" = `git rev-parse :one` && |
| 222 | test "$patched" = `git hash-object --stdin <one` || { |
| 223 | echo "Eh? apply with --index" |
| 224 | false |
| 225 | } |
| 226 | ' |
| 227 | |
| 228 | test_expect_success 'apply patch (autocrlf=true)' ' |
| 229 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 230 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 231 | git config core.autocrlf true && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 232 | git read-tree --reset -u HEAD && |
| 233 | |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 234 | git apply patch.file && |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 235 | test "$patched" = "`remove_cr <one | git hash-object --stdin`" || { |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 236 | echo "Eh? apply without index" |
| 237 | false |
| 238 | } |
| 239 | ' |
| 240 | |
| 241 | test_expect_success 'apply patch --cached (autocrlf=true)' ' |
| 242 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 243 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 244 | git config core.autocrlf true && |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 245 | git read-tree --reset -u HEAD && |
| 246 | |
| 247 | git apply --cached patch.file && |
| 248 | test "$patched" = `git rev-parse :one` || { |
| 249 | echo "Eh? apply without index" |
| 250 | false |
| 251 | } |
| 252 | ' |
| 253 | |
Junio C Hamano | 6716027 | 2007-02-17 12:37:25 -0800 | [diff] [blame] | 254 | test_expect_success 'apply patch --index (autocrlf=true)' ' |
| 255 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 256 | rm -f tmp one dir/two three && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 257 | git config core.autocrlf true && |
Junio C Hamano | 6716027 | 2007-02-17 12:37:25 -0800 | [diff] [blame] | 258 | git read-tree --reset -u HEAD && |
| 259 | |
| 260 | git apply --index patch.file && |
| 261 | test "$patched" = `git rev-parse :one` && |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 262 | test "$patched" = "`remove_cr <one | git hash-object --stdin`" || { |
Junio C Hamano | 6716027 | 2007-02-17 12:37:25 -0800 | [diff] [blame] | 263 | echo "Eh? apply with --index" |
| 264 | false |
| 265 | } |
| 266 | ' |
| 267 | |
Junio C Hamano | 35ebfd6 | 2007-04-12 22:30:05 -0700 | [diff] [blame] | 268 | test_expect_success '.gitattributes says two is binary' ' |
| 269 | |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 270 | rm -f tmp one dir/two three && |
Junio C Hamano | e4aee10 | 2007-04-15 14:56:09 -0700 | [diff] [blame] | 271 | echo "two -crlf" >.gitattributes && |
Junio C Hamano | 5c66d0d | 2008-01-17 22:52:40 -0800 | [diff] [blame] | 272 | git config core.autocrlf true && |
Junio C Hamano | 35ebfd6 | 2007-04-12 22:30:05 -0700 | [diff] [blame] | 273 | git read-tree --reset -u HEAD && |
| 274 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 275 | if has_cr dir/two |
Junio C Hamano | 35ebfd6 | 2007-04-12 22:30:05 -0700 | [diff] [blame] | 276 | then |
| 277 | echo "Huh?" |
| 278 | false |
| 279 | else |
| 280 | : happy |
| 281 | fi && |
| 282 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 283 | if has_cr one |
Junio C Hamano | 35ebfd6 | 2007-04-12 22:30:05 -0700 | [diff] [blame] | 284 | then |
| 285 | : happy |
| 286 | else |
| 287 | echo "Huh?" |
| 288 | false |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 289 | fi && |
| 290 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 291 | if has_cr three |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 292 | then |
| 293 | echo "Huh?" |
| 294 | false |
| 295 | else |
| 296 | : happy |
| 297 | fi |
| 298 | ' |
| 299 | |
| 300 | test_expect_success '.gitattributes says two is input' ' |
| 301 | |
| 302 | rm -f tmp one dir/two three && |
| 303 | echo "two crlf=input" >.gitattributes && |
| 304 | git read-tree --reset -u HEAD && |
| 305 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 306 | if has_cr dir/two |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 307 | then |
| 308 | echo "Huh?" |
| 309 | false |
| 310 | else |
| 311 | : happy |
| 312 | fi |
| 313 | ' |
| 314 | |
| 315 | test_expect_success '.gitattributes says two and three are text' ' |
| 316 | |
| 317 | rm -f tmp one dir/two three && |
| 318 | echo "t* crlf" >.gitattributes && |
| 319 | git read-tree --reset -u HEAD && |
| 320 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 321 | if has_cr dir/two |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 322 | then |
| 323 | : happy |
| 324 | else |
| 325 | echo "Huh?" |
| 326 | false |
| 327 | fi && |
| 328 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 329 | if has_cr three |
Junio C Hamano | 163b959 | 2007-04-19 22:37:19 -0700 | [diff] [blame] | 330 | then |
| 331 | : happy |
| 332 | else |
| 333 | echo "Huh?" |
| 334 | false |
Junio C Hamano | 35ebfd6 | 2007-04-12 22:30:05 -0700 | [diff] [blame] | 335 | fi |
| 336 | ' |
| 337 | |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 338 | test_expect_success 'in-tree .gitattributes (1)' ' |
| 339 | |
| 340 | echo "one -crlf" >>.gitattributes && |
| 341 | git add .gitattributes && |
| 342 | git commit -m "Add .gitattributes" && |
| 343 | |
| 344 | rm -rf tmp one dir .gitattributes patch.file three && |
| 345 | git read-tree --reset -u HEAD && |
| 346 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 347 | if has_cr one |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 348 | then |
| 349 | echo "Eh? one should not have CRLF" |
| 350 | false |
| 351 | else |
| 352 | : happy |
| 353 | fi && |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 354 | has_cr three || { |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 355 | echo "Eh? three should still have CRLF" |
| 356 | false |
| 357 | } |
| 358 | ' |
| 359 | |
| 360 | test_expect_success 'in-tree .gitattributes (2)' ' |
| 361 | |
| 362 | rm -rf tmp one dir .gitattributes patch.file three && |
| 363 | git read-tree --reset HEAD && |
| 364 | git checkout-index -f -q -u -a && |
| 365 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 366 | if has_cr one |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 367 | then |
| 368 | echo "Eh? one should not have CRLF" |
| 369 | false |
| 370 | else |
| 371 | : happy |
| 372 | fi && |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 373 | has_cr three || { |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 374 | echo "Eh? three should still have CRLF" |
| 375 | false |
| 376 | } |
| 377 | ' |
| 378 | |
| 379 | test_expect_success 'in-tree .gitattributes (3)' ' |
| 380 | |
| 381 | rm -rf tmp one dir .gitattributes patch.file three && |
| 382 | git read-tree --reset HEAD && |
| 383 | git checkout-index -u .gitattributes && |
| 384 | git checkout-index -u one dir/two three && |
| 385 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 386 | if has_cr one |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 387 | then |
| 388 | echo "Eh? one should not have CRLF" |
| 389 | false |
| 390 | else |
| 391 | : happy |
| 392 | fi && |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 393 | has_cr three || { |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 394 | echo "Eh? three should still have CRLF" |
| 395 | false |
| 396 | } |
| 397 | ' |
| 398 | |
| 399 | test_expect_success 'in-tree .gitattributes (4)' ' |
| 400 | |
| 401 | rm -rf tmp one dir .gitattributes patch.file three && |
| 402 | git read-tree --reset HEAD && |
| 403 | git checkout-index -u one dir/two three && |
| 404 | git checkout-index -u .gitattributes && |
| 405 | |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 406 | if has_cr one |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 407 | then |
| 408 | echo "Eh? one should not have CRLF" |
| 409 | false |
| 410 | else |
| 411 | : happy |
| 412 | fi && |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 413 | has_cr three || { |
Junio C Hamano | 1a9d7e9 | 2007-08-14 01:41:02 -0700 | [diff] [blame] | 414 | echo "Eh? three should still have CRLF" |
| 415 | false |
| 416 | } |
| 417 | ' |
| 418 | |
Kristian Amlie | b997045 | 2009-03-20 10:32:09 +0100 | [diff] [blame] | 419 | test_expect_success 'checkout with existing .gitattributes' ' |
| 420 | |
| 421 | git config core.autocrlf true && |
| 422 | git config --unset core.safecrlf && |
| 423 | echo ".file2 -crlfQ" | q_to_cr >> .gitattributes && |
| 424 | git add .gitattributes && |
| 425 | git commit -m initial && |
| 426 | echo ".file -crlfQ" | q_to_cr >> .gitattributes && |
| 427 | echo "contents" > .file && |
| 428 | git add .gitattributes .file && |
| 429 | git commit -m second && |
| 430 | |
| 431 | git checkout master~1 && |
| 432 | git checkout master && |
| 433 | test "$(git diff-files --raw)" = "" |
| 434 | |
| 435 | ' |
| 436 | |
| 437 | test_expect_success 'checkout when deleting .gitattributes' ' |
| 438 | |
| 439 | git rm .gitattributes && |
| 440 | echo "contentsQ" | q_to_cr > .file2 && |
| 441 | git add .file2 && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 442 | git commit -m third && |
Kristian Amlie | b997045 | 2009-03-20 10:32:09 +0100 | [diff] [blame] | 443 | |
| 444 | git checkout master~1 && |
| 445 | git checkout master && |
Stephen Boyd | c4f3f55 | 2010-01-25 16:33:57 -0800 | [diff] [blame] | 446 | has_cr .file2 |
Kristian Amlie | b997045 | 2009-03-20 10:32:09 +0100 | [diff] [blame] | 447 | |
| 448 | ' |
| 449 | |
Steffen Prohaska | d7b0a09 | 2007-10-18 22:02:35 +0200 | [diff] [blame] | 450 | test_expect_success 'invalid .gitattributes (must not crash)' ' |
| 451 | |
| 452 | echo "three +crlf" >>.gitattributes && |
| 453 | git diff |
| 454 | |
| 455 | ' |
Finn Arne Gangstad | c480539 | 2010-05-12 00:37:57 +0200 | [diff] [blame] | 456 | # Some more tests here to add new autocrlf functionality. |
| 457 | # We want to have a known state here, so start a bit from scratch |
| 458 | |
| 459 | test_expect_success 'setting up for new autocrlf tests' ' |
| 460 | git config core.autocrlf false && |
| 461 | git config core.safecrlf false && |
| 462 | rm -rf .????* * && |
| 463 | for w in I am all LF; do echo $w; done >alllf && |
| 464 | for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed && |
| 465 | for w in I am all CRLF; do echo $w; done | append_cr >allcrlf && |
| 466 | git add -A . && |
| 467 | git commit -m "alllf, allcrlf and mixed only" && |
| 468 | git tag -a -m "message" autocrlf-checkpoint |
| 469 | ' |
| 470 | |
| 471 | test_expect_success 'report no change after setting autocrlf' ' |
| 472 | git config core.autocrlf true && |
| 473 | touch * && |
| 474 | git diff --exit-code |
| 475 | ' |
| 476 | |
| 477 | test_expect_success 'files are clean after checkout' ' |
| 478 | rm * && |
| 479 | git checkout -f && |
| 480 | git diff --exit-code |
| 481 | ' |
| 482 | |
| 483 | cr_to_Q_no_NL () { |
| 484 | tr '\015' Q | tr -d '\012' |
| 485 | } |
| 486 | |
| 487 | test_expect_success 'LF only file gets CRLF with autocrlf' ' |
| 488 | test "$(cr_to_Q_no_NL < alllf)" = "IQamQallQLFQ" |
| 489 | ' |
| 490 | |
| 491 | test_expect_success 'Mixed file is still mixed with autocrlf' ' |
| 492 | test "$(cr_to_Q_no_NL < mixed)" = "OhhereisCRLFQintext" |
| 493 | ' |
| 494 | |
| 495 | test_expect_success 'CRLF only file has CRLF with autocrlf' ' |
| 496 | test "$(cr_to_Q_no_NL < allcrlf)" = "IQamQallQCRLFQ" |
| 497 | ' |
| 498 | |
| 499 | test_expect_success 'New CRLF file gets LF in repo' ' |
| 500 | tr -d "\015" < alllf | append_cr > alllf2 && |
| 501 | git add alllf2 && |
| 502 | git commit -m "alllf2 added" && |
| 503 | git config core.autocrlf false && |
| 504 | rm * && |
| 505 | git checkout -f && |
| 506 | test_cmp alllf alllf2 |
| 507 | ' |
Steffen Prohaska | d7b0a09 | 2007-10-18 22:02:35 +0200 | [diff] [blame] | 508 | |
Junio C Hamano | 634ede3 | 2007-02-14 14:54:00 -0800 | [diff] [blame] | 509 | test_done |