33b77ee47ae4e35d9da221dddae53182571411eb
1#!/bin/sh
2
3test_description='CRLF merge conflict across text=auto change
4
5* [master] remove .gitattributes
6 ! [side] add line from b
7--
8 + [side] add line from b
9* [master] remove .gitattributes
10* [master^] add line from a
11* [master~2] normalize file
12*+ [side^] Initial
13'
14
15. ./test-lib.sh
16
17test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
18
19compare_files () {
20 tr '\015\000' QN <"$1" >"$1".expect &&
21 tr '\015\000' QN <"$2" >"$2".actual &&
22 test_cmp "$1".expect "$2".actual &&
23 rm "$1".expect "$2".actual
24}
25
26test_expect_success setup '
27 git config core.autocrlf false &&
28
29 echo first line | append_cr >file &&
30 echo first line >control_file &&
31 echo only line >inert_file &&
32
33 git add file control_file inert_file &&
34 test_tick &&
35 git commit -m "Initial" &&
36 git tag initial &&
37 git branch side &&
38
39 echo "* text=auto" >.gitattributes &&
40 echo first line >file &&
41 git add .gitattributes file &&
42 test_tick &&
43 git commit -m "normalize file" &&
44
45 echo same line | append_cr >>file &&
46 echo same line >>control_file &&
47 git add file control_file &&
48 test_tick &&
49 git commit -m "add line from a" &&
50 git tag a &&
51
52 git rm .gitattributes &&
53 rm file &&
54 git checkout file &&
55 test_tick &&
56 git commit -m "remove .gitattributes" &&
57 git tag c &&
58
59 git checkout side &&
60 echo same line | append_cr >>file &&
61 echo same line >>control_file &&
62 git add file control_file &&
63 test_tick &&
64 git commit -m "add line from b" &&
65 git tag b &&
66
67 git checkout master
68'
69
70test_expect_success 'set up fuzz_conflict() helper' '
71 fuzz_conflict() {
72 sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
73 }
74'
75
76test_expect_success 'Merge after setting text=auto' '
77 cat <<-\EOF >expected &&
78 first line
79 same line
80 EOF
81
82 if test_have_prereq NATIVE_CRLF; then
83 append_cr <expected >expected.temp &&
84 mv expected.temp expected
85 fi &&
86 git config merge.renormalize true &&
87 git rm -fr . &&
88 rm -f .gitattributes &&
89 git reset --hard a &&
90 git merge b &&
91 compare_files expected file
92'
93
94test_expect_success 'Merge addition of text=auto' '
95 cat <<-\EOF >expected &&
96 first line
97 same line
98 EOF
99
100 if test_have_prereq NATIVE_CRLF; then
101 append_cr <expected >expected.temp &&
102 mv expected.temp expected
103 fi &&
104 git config merge.renormalize true &&
105 git rm -fr . &&
106 rm -f .gitattributes &&
107 git reset --hard b &&
108 git merge a &&
109 compare_files expected file
110'
111
112test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
113 echo "<<<<<<<" >expected &&
114 if test_have_prereq NATIVE_CRLF; then
115 echo first line | append_cr >>expected &&
116 echo same line | append_cr >>expected &&
117 echo ======= | append_cr >>expected
118 else
119 echo first line >>expected &&
120 echo same line >>expected &&
121 echo ======= >>expected
122 fi &&
123 echo first line | append_cr >>expected &&
124 echo same line | append_cr >>expected &&
125 echo ">>>>>>>" >>expected &&
126 git config merge.renormalize false &&
127 rm -f .gitattributes &&
128 git reset --hard a &&
129 test_must_fail git merge b &&
130 fuzz_conflict file >file.fuzzy &&
131 compare_files expected file.fuzzy
132'
133
134test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
135 echo "<<<<<<<" >expected &&
136 echo first line | append_cr >>expected &&
137 echo same line | append_cr >>expected &&
138 if test_have_prereq NATIVE_CRLF; then
139 echo ======= | append_cr >>expected &&
140 echo first line | append_cr >>expected &&
141 echo same line | append_cr >>expected
142 else
143 echo ======= >>expected &&
144 echo first line >>expected &&
145 echo same line >>expected
146 fi &&
147 echo ">>>>>>>" >>expected &&
148 git config merge.renormalize false &&
149 rm -f .gitattributes &&
150 git reset --hard b &&
151 test_must_fail git merge a &&
152 fuzz_conflict file >file.fuzzy &&
153 compare_files expected file.fuzzy
154'
155
156test_expect_failure 'checkout -m after setting text=auto' '
157 cat <<-\EOF >expected &&
158 first line
159 same line
160 EOF
161
162 git config merge.renormalize true &&
163 git rm -fr . &&
164 rm -f .gitattributes &&
165 git reset --hard initial &&
166 git checkout a -- . &&
167 git checkout -m b &&
168 compare_files expected file
169'
170
171test_expect_failure 'checkout -m addition of text=auto' '
172 cat <<-\EOF >expected &&
173 first line
174 same line
175 EOF
176
177 git config merge.renormalize true &&
178 git rm -fr . &&
179 rm -f .gitattributes file &&
180 git reset --hard initial &&
181 git checkout b -- . &&
182 git checkout -m a &&
183 compare_files expected file
184'
185
186test_expect_failure 'cherry-pick patch from after text=auto was added' '
187 append_cr <<-\EOF >expected &&
188 first line
189 same line
190 EOF
191
192 git config merge.renormalize true &&
193 git rm -fr . &&
194 git reset --hard b &&
195 test_must_fail git cherry-pick a >err 2>&1 &&
196 grep "[Nn]othing added" err &&
197 compare_files expected file
198'
199
200test_expect_success 'Test delete/normalize conflict' '
201 git checkout -f side &&
202 git rm -fr . &&
203 rm -f .gitattributes &&
204 git reset --hard initial &&
205 git rm file &&
206 git commit -m "remove file" &&
207 git checkout master &&
208 git reset --hard a^ &&
209 git merge side
210'
211
212test_done