Update draft release notes to 1.8.2
[git/jrn.git] / t / t0025-crlf-auto.sh
blobf5f67a6337320c11a285b78be299fa955663991d
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 >one &&
16 for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >two &&
17 for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >three &&
18 git add . &&
20 git commit -m initial &&
22 one=`git rev-parse HEAD:one` &&
23 two=`git rev-parse HEAD:two` &&
24 three=`git rev-parse HEAD:three` &&
26 echo happy.
29 test_expect_success 'default settings cause no changes' '
31 rm -f .gitattributes tmp one two three &&
32 git read-tree --reset -u HEAD &&
34 ! has_cr one &&
35 has_cr two &&
36 onediff=`git diff one` &&
37 twodiff=`git diff two` &&
38 threediff=`git diff three` &&
39 test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
42 test_expect_success 'crlf=true causes a CRLF file to be normalized' '
44 # Backwards compatibility check
45 rm -f .gitattributes tmp one two three &&
46 echo "two crlf" > .gitattributes &&
47 git read-tree --reset -u HEAD &&
49 # Note, "normalized" means that git will normalize it if added
50 has_cr two &&
51 twodiff=`git diff two` &&
52 test -n "$twodiff"
55 test_expect_success 'text=true causes a CRLF file to be normalized' '
57 rm -f .gitattributes tmp one two three &&
58 echo "two text" > .gitattributes &&
59 git read-tree --reset -u HEAD &&
61 # Note, "normalized" means that git will normalize it if added
62 has_cr two &&
63 twodiff=`git diff two` &&
64 test -n "$twodiff"
67 test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
69 rm -f .gitattributes tmp one two three &&
70 git config core.autocrlf false &&
71 echo "one eol=crlf" > .gitattributes &&
72 git read-tree --reset -u HEAD &&
74 has_cr one &&
75 onediff=`git diff one` &&
76 test -z "$onediff"
79 test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
81 rm -f .gitattributes tmp one two three &&
82 git config core.autocrlf input &&
83 echo "one eol=crlf" > .gitattributes &&
84 git read-tree --reset -u HEAD &&
86 has_cr one &&
87 onediff=`git diff one` &&
88 test -z "$onediff"
91 test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '
93 rm -f .gitattributes tmp one two three &&
94 git config core.autocrlf true &&
95 echo "one eol=lf" > .gitattributes &&
96 git read-tree --reset -u HEAD &&
98 ! has_cr one &&
99 onediff=`git diff one` &&
100 test -z "$onediff"
103 test_expect_success 'autocrlf=true does not normalize CRLF files' '
105 rm -f .gitattributes tmp one two three &&
106 git config core.autocrlf true &&
107 git read-tree --reset -u HEAD &&
109 has_cr one &&
110 has_cr two &&
111 onediff=`git diff one` &&
112 twodiff=`git diff two` &&
113 threediff=`git diff three` &&
114 test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
117 test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
119 rm -f .gitattributes tmp one two three &&
120 git config core.autocrlf true &&
121 echo "* text=auto" > .gitattributes &&
122 git read-tree --reset -u HEAD &&
124 has_cr one &&
125 has_cr two &&
126 onediff=`git diff one` &&
127 twodiff=`git diff two` &&
128 threediff=`git diff three` &&
129 test -z "$onediff" -a -n "$twodiff" -a -z "$threediff"
132 test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
134 rm -f .gitattributes tmp one two three &&
135 git config core.autocrlf true &&
136 echo "* text=auto" > .gitattributes &&
137 git read-tree --reset -u HEAD &&
139 ! has_cr three &&
140 threediff=`git diff three` &&
141 test -z "$threediff"
144 test_expect_success 'eol=crlf _does_ normalize binary files' '
146 rm -f .gitattributes tmp one two three &&
147 echo "three eol=crlf" > .gitattributes &&
148 git read-tree --reset -u HEAD &&
150 has_cr three &&
151 threediff=`git diff three` &&
152 test -z "$threediff"
155 test_done