Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='CRLF conversion' |
| 4 | |
Ævar Arnfjörð Bjarmason | c150064 | 2021-10-12 15:56:37 +0200 | [diff] [blame] | 5 | TEST_PASSES_SANITIZE_LEAK=true |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 6 | . ./test-lib.sh |
| 7 | |
| 8 | has_cr() { |
| 9 | tr '\015' Q <"$1" | grep Q >/dev/null |
| 10 | } |
| 11 | |
| 12 | test_expect_success setup ' |
| 13 | |
| 14 | git config core.autocrlf false && |
| 15 | |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 16 | echo "one text" > .gitattributes && |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 17 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 18 | test_write_lines Hello world how are you >one && |
| 19 | test_write_lines I am very very fine thank you >two && |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 20 | git add . && |
| 21 | |
| 22 | git commit -m initial && |
| 23 | |
Elia Pinto | 8deeab4 | 2014-04-28 05:57:28 -0700 | [diff] [blame] | 24 | one=$(git rev-parse HEAD:one) && |
| 25 | two=$(git rev-parse HEAD:two) && |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 26 | |
| 27 | echo happy. |
| 28 | ' |
| 29 | |
| 30 | test_expect_success 'eol=lf puts LFs in normalized file' ' |
| 31 | |
| 32 | rm -f .gitattributes tmp one two && |
| 33 | git config core.eol lf && |
| 34 | git read-tree --reset -u HEAD && |
| 35 | |
| 36 | ! has_cr one && |
| 37 | ! has_cr two && |
Elia Pinto | 8deeab4 | 2014-04-28 05:57:28 -0700 | [diff] [blame] | 38 | onediff=$(git diff one) && |
| 39 | twodiff=$(git diff two) && |
Elia Pinto | 66e1fe7 | 2014-06-06 07:55:56 -0700 | [diff] [blame] | 40 | test -z "$onediff" && test -z "$twodiff" |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 41 | ' |
| 42 | |
| 43 | test_expect_success 'eol=crlf puts CRLFs in normalized file' ' |
| 44 | |
| 45 | rm -f .gitattributes tmp one two && |
| 46 | git config core.eol crlf && |
| 47 | git read-tree --reset -u HEAD && |
| 48 | |
| 49 | has_cr one && |
| 50 | ! has_cr two && |
Elia Pinto | 8deeab4 | 2014-04-28 05:57:28 -0700 | [diff] [blame] | 51 | onediff=$(git diff one) && |
| 52 | twodiff=$(git diff two) && |
Elia Pinto | 66e1fe7 | 2014-06-06 07:55:56 -0700 | [diff] [blame] | 53 | test -z "$onediff" && test -z "$twodiff" |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 54 | ' |
| 55 | |
| 56 | test_expect_success 'autocrlf=true overrides eol=lf' ' |
| 57 | |
| 58 | rm -f .gitattributes tmp one two && |
| 59 | git config core.eol lf && |
| 60 | git config core.autocrlf true && |
| 61 | git read-tree --reset -u HEAD && |
| 62 | |
| 63 | has_cr one && |
| 64 | has_cr two && |
Elia Pinto | 8deeab4 | 2014-04-28 05:57:28 -0700 | [diff] [blame] | 65 | onediff=$(git diff one) && |
| 66 | twodiff=$(git diff two) && |
Elia Pinto | 66e1fe7 | 2014-06-06 07:55:56 -0700 | [diff] [blame] | 67 | test -z "$onediff" && test -z "$twodiff" |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 68 | ' |
| 69 | |
| 70 | test_expect_success 'autocrlf=true overrides unset eol' ' |
| 71 | |
| 72 | rm -f .gitattributes tmp one two && |
| 73 | git config --unset-all core.eol && |
| 74 | git config core.autocrlf true && |
| 75 | git read-tree --reset -u HEAD && |
| 76 | |
| 77 | has_cr one && |
| 78 | has_cr two && |
Elia Pinto | 8deeab4 | 2014-04-28 05:57:28 -0700 | [diff] [blame] | 79 | onediff=$(git diff one) && |
| 80 | twodiff=$(git diff two) && |
Elia Pinto | 66e1fe7 | 2014-06-06 07:55:56 -0700 | [diff] [blame] | 81 | test -z "$onediff" && test -z "$twodiff" |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 82 | ' |
| 83 | |
Pat Thoyts | 5491e9e | 2014-08-30 23:38:59 +0200 | [diff] [blame] | 84 | test_expect_success NATIVE_CRLF 'eol native is crlf' ' |
| 85 | |
| 86 | rm -rf native_eol && mkdir native_eol && |
| 87 | ( |
| 88 | cd native_eol && |
| 89 | printf "*.txt text\n" >.gitattributes && |
| 90 | printf "one\r\ntwo\r\nthree\r\n" >filedos.txt && |
| 91 | printf "one\ntwo\nthree\n" >fileunix.txt && |
| 92 | git init && |
| 93 | git config core.autocrlf false && |
| 94 | git config core.eol native && |
| 95 | git add filedos.txt fileunix.txt && |
| 96 | git commit -m "first" && |
| 97 | rm file*.txt && |
| 98 | git reset --hard HEAD && |
| 99 | has_cr filedos.txt && |
| 100 | has_cr fileunix.txt |
| 101 | ) |
| 102 | ' |
| 103 | |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 104 | test_done |