3 test_description
='CRLF conversion'
8 tr '\015' Q
<"$1" |
grep Q
>/dev
/null
11 test_expect_success setup
'
13 git config core.autocrlf false &&
15 for w in Hello world how are you; do echo $w; done >LFonly &&
16 for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >CRLFonly &&
17 for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >LFwithNUL &&
20 git commit -m initial &&
22 LFonly=$(git rev-parse HEAD:LFonly) &&
23 CRLFonly=$(git rev-parse HEAD:CRLFonly) &&
24 LFwithNUL=$(git rev-parse HEAD:LFwithNUL) &&
29 test_expect_success
'default settings cause no changes' '
31 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
32 git read-tree --reset -u HEAD &&
36 LFonlydiff=$(git diff LFonly) &&
37 CRLFonlydiff=$(git diff CRLFonly) &&
38 LFwithNULdiff=$(git diff LFwithNUL) &&
39 test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
42 test_expect_success
'crlf=true causes a CRLF file to be normalized' '
44 # Backwards compatibility check
45 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
46 echo "CRLFonly crlf" > .gitattributes &&
47 git read-tree --reset -u HEAD &&
49 # Note, "normalized" means that git will normalize it if added
51 CRLFonlydiff=$(git diff CRLFonly) &&
52 test -n "$CRLFonlydiff"
55 test_expect_success
'text=true causes a CRLF file to be normalized' '
57 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
58 echo "CRLFonly text" > .gitattributes &&
59 git read-tree --reset -u HEAD &&
61 # Note, "normalized" means that git will normalize it if added
63 CRLFonlydiff=$(git diff CRLFonly) &&
64 test -n "$CRLFonlydiff"
67 test_expect_success
'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
69 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
70 git config core.autocrlf false &&
71 echo "LFonly eol=crlf" > .gitattributes &&
72 git read-tree --reset -u HEAD &&
75 LFonlydiff=$(git diff LFonly) &&
79 test_expect_success
'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
81 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
82 git config core.autocrlf input &&
83 echo "LFonly eol=crlf" > .gitattributes &&
84 git read-tree --reset -u HEAD &&
87 LFonlydiff=$(git diff LFonly) &&
91 test_expect_success
'eol=lf gives a normalized file LFs with autocrlf=true' '
93 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
94 git config core.autocrlf true &&
95 echo "LFonly eol=lf" > .gitattributes &&
96 git read-tree --reset -u HEAD &&
99 LFonlydiff=$(git diff LFonly) &&
100 test -z "$LFonlydiff"
103 test_expect_success
'autocrlf=true does not normalize CRLF files' '
105 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
106 git config core.autocrlf true &&
107 git read-tree --reset -u HEAD &&
111 LFonlydiff=$(git diff LFonly) &&
112 CRLFonlydiff=$(git diff CRLFonly) &&
113 LFwithNULdiff=$(git diff LFwithNUL) &&
114 test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
117 test_expect_success
'text=auto, autocrlf=true does not normalize CRLF files' '
119 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
120 git config core.autocrlf true &&
121 echo "* text=auto" > .gitattributes &&
122 git read-tree --reset -u HEAD &&
126 LFonlydiff=$(git diff LFonly) &&
127 CRLFonlydiff=$(git diff CRLFonly) &&
128 LFwithNULdiff=$(git diff LFwithNUL) &&
129 test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
132 test_expect_success
'text=auto, autocrlf=true does not normalize binary files' '
134 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
135 git config core.autocrlf true &&
136 echo "* text=auto" > .gitattributes &&
137 git read-tree --reset -u HEAD &&
139 ! has_cr LFwithNUL &&
140 LFwithNULdiff=$(git diff LFwithNUL) &&
141 test -z "$LFwithNULdiff"
144 test_expect_success
'eol=crlf _does_ normalize binary files' '
146 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
147 echo "LFwithNUL eol=crlf" > .gitattributes &&
148 git read-tree --reset -u HEAD &&
151 LFwithNULdiff=$(git diff LFwithNUL) &&
152 test -z "$LFwithNULdiff"