msysGit-based Git for Windows 1.x was superseded by Git for Windows 2.x
[git/mingw/4msysgit.git] / t / t0025-crlf-auto.sh
blobc164b4662a06d26bc23b58287f88023ed0a588a2
1 #!/bin/sh
3 test_description='CRLF conversion'
5 . ./test-lib.sh
7 has_cr() {
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 &&
18 git add . &&
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) &&
26 echo happy.
29 test_expect_success 'default settings cause no changes' '
31 rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
32 git read-tree --reset -u HEAD &&
34 ! has_cr LFonly &&
35 has_cr CRLFonly &&
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
50 has_cr CRLFonly &&
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
62 has_cr CRLFonly &&
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 &&
74 has_cr LFonly &&
75 LFonlydiff=$(git diff LFonly) &&
76 test -z "$LFonlydiff"
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 &&
86 has_cr LFonly &&
87 LFonlydiff=$(git diff LFonly) &&
88 test -z "$LFonlydiff"
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 &&
98 ! has_cr LFonly &&
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 &&
109 has_cr LFonly &&
110 has_cr CRLFonly &&
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_ 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 &&
124 has_cr LFonly &&
125 has_cr CRLFonly &&
126 LFonlydiff=$(git diff LFonly) &&
127 CRLFonlydiff=$(git diff CRLFonly) &&
128 LFwithNULdiff=$(git diff LFwithNUL) &&
129 test -z "$LFonlydiff" -a -n "$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 &&
150 has_cr LFwithNUL &&
151 LFwithNULdiff=$(git diff LFwithNUL) &&
152 test -z "$LFwithNULdiff"
155 test_done