3 test_description
='CRLF merge conflict across text=auto change
5 * [main] remove .gitattributes
6 ! [side] add line from b
8 + [side] add line from b
9 * [main] remove .gitattributes
10 * [main^] add line from a
11 * [main~2] normalize file
15 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
16 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18 TEST_PASSES_SANITIZE_LEAK
=true
21 test_have_prereq SED_STRIPS_CR
&& SED_OPTIONS
=-b
24 tr '\015\000' QN
<"$1" >"$1".expect
&&
25 tr '\015\000' QN
<"$2" >"$2".actual
&&
26 test_cmp
"$1".expect
"$2".actual
&&
27 rm "$1".expect
"$2".actual
30 test_expect_success setup
'
31 git config core.autocrlf false &&
33 echo first line | append_cr >file &&
34 echo first line >control_file &&
35 echo only line >inert_file &&
37 git add file control_file inert_file &&
39 git commit -m "Initial" &&
43 echo "* text=auto" >.gitattributes &&
44 echo first line >file &&
45 git add .gitattributes file &&
47 git commit -m "normalize file" &&
49 echo same line | append_cr >>file &&
50 echo same line >>control_file &&
51 git add file control_file &&
53 git commit -m "add line from a" &&
56 git rm .gitattributes &&
60 git commit -m "remove .gitattributes" &&
64 echo same line | append_cr >>file &&
65 echo same line >>control_file &&
66 git add file control_file &&
68 git commit -m "add line from b" &&
74 test_expect_success
'set up fuzz_conflict() helper' '
76 sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
80 test_expect_success
'Merge after setting text=auto' '
81 cat <<-\EOF >expected &&
86 if test_have_prereq NATIVE_CRLF; then
87 append_cr <expected >expected.temp &&
88 mv expected.temp expected
90 git config merge.renormalize true &&
92 rm -f .gitattributes &&
95 compare_files expected file
98 test_expect_success
'Merge addition of text=auto eol=LF' '
99 git config core.eol lf &&
100 cat <<-\EOF >expected &&
105 git config merge.renormalize true &&
107 rm -f .gitattributes &&
108 git reset --hard b &&
110 compare_files expected file
113 test_expect_success
'Merge addition of text=auto eol=CRLF' '
114 git config core.eol crlf &&
115 cat <<-\EOF >expected &&
120 append_cr <expected >expected.temp &&
121 mv expected.temp expected &&
122 git config merge.renormalize true &&
124 rm -f .gitattributes &&
125 git reset --hard b &&
126 echo >&2 "After git reset --hard b" &&
127 git ls-files -s --eol >&2 &&
129 compare_files expected file
132 test_expect_success
'Detect CRLF/LF conflict after setting text=auto' '
133 git config core.eol native &&
134 echo "<<<<<<<" >expected &&
135 echo first line >>expected &&
136 echo same line >>expected &&
137 echo ======= >>expected &&
138 echo first line | append_cr >>expected &&
139 echo same line | append_cr >>expected &&
140 echo ">>>>>>>" >>expected &&
141 git config merge.renormalize false &&
142 rm -f .gitattributes &&
143 git reset --hard a &&
144 test_must_fail git merge b &&
145 fuzz_conflict file >file.fuzzy &&
146 compare_files expected file.fuzzy
149 test_expect_success
'Detect LF/CRLF conflict from addition of text=auto' '
150 echo "<<<<<<<" >expected &&
151 echo first line | append_cr >>expected &&
152 echo same line | append_cr >>expected &&
153 echo ======= >>expected &&
154 echo first line >>expected &&
155 echo same line >>expected &&
156 echo ">>>>>>>" >>expected &&
157 git config merge.renormalize false &&
158 rm -f .gitattributes &&
159 git reset --hard b &&
160 test_must_fail git merge a &&
161 fuzz_conflict file >file.fuzzy &&
162 compare_files expected file.fuzzy
165 test_expect_success
'checkout -m after setting text=auto' '
166 cat <<-\EOF >expected &&
171 git config merge.renormalize true &&
173 rm -f .gitattributes &&
174 git reset --hard initial &&
175 git restore --source=a -- . &&
177 git diff --no-index --ignore-cr-at-eol expected file
180 test_expect_success
'checkout -m addition of text=auto' '
181 cat <<-\EOF >expected &&
186 git config merge.renormalize true &&
188 rm -f .gitattributes file &&
189 git reset --hard initial &&
190 git restore --source=b -- . &&
192 git diff --no-index --ignore-cr-at-eol expected file
195 test_expect_success
'Test delete/normalize conflict' '
196 git checkout -f side &&
198 rm -f .gitattributes &&
199 git reset --hard initial &&
201 git commit -m "remove file" &&
203 git reset --hard a^ &&
205 test_path_is_missing file
208 test_expect_success
'rename/delete vs. renormalization' '
214 git commit -m original &&
219 git checkout rename &&
220 git mv oldfile newfile &&
221 git commit -m renamed &&
225 git commit -m deleted &&
227 git checkout rename^0 &&
228 test_must_fail git -c merge.renormalize=true merge nuke >out &&
230 grep "rename/delete" out