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
20 test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
23 tr '\015\000' QN <"$1" >"$1".expect &&
24 tr '\015\000' QN <"$2" >"$2".actual &&
25 test_cmp "$1".expect "$2".actual &&
26 rm "$1".expect "$2".actual
29 test_expect_success setup '
30 git config core.autocrlf false &&
32 echo first line | append_cr >file &&
33 echo first line >control_file &&
34 echo only line >inert_file &&
36 git add file control_file inert_file &&
38 git commit -m "Initial" &&
42 echo "* text=auto" >.gitattributes &&
43 echo first line >file &&
44 git add .gitattributes file &&
46 git commit -m "normalize file" &&
48 echo same line | append_cr >>file &&
49 echo same line >>control_file &&
50 git add file control_file &&
52 git commit -m "add line from a" &&
55 git rm .gitattributes &&
59 git commit -m "remove .gitattributes" &&
63 echo same line | append_cr >>file &&
64 echo same line >>control_file &&
65 git add file control_file &&
67 git commit -m "add line from b" &&
73 test_expect_success 'set up fuzz_conflict() helper' '
75 sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
79 test_expect_success 'Merge after setting text=auto' '
80 cat <<-\EOF >expected &&
85 if test_have_prereq NATIVE_CRLF; then
86 append_cr <expected >expected.temp &&
87 mv expected.temp expected
89 git config merge.renormalize true &&
91 rm -f .gitattributes &&
94 compare_files expected file
97 test_expect_success 'Merge addition of text=auto eol=LF' '
98 git config core.eol lf &&
99 cat <<-\EOF >expected &&
104 git config merge.renormalize true &&
106 rm -f .gitattributes &&
107 git reset --hard b &&
109 compare_files expected file
112 test_expect_success 'Merge addition of text=auto eol=CRLF' '
113 git config core.eol crlf &&
114 cat <<-\EOF >expected &&
119 append_cr <expected >expected.temp &&
120 mv expected.temp expected &&
121 git config merge.renormalize true &&
123 rm -f .gitattributes &&
124 git reset --hard b &&
125 echo >&2 "After git reset --hard b" &&
126 git ls-files -s --eol >&2 &&
128 compare_files expected file
131 test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
132 git config core.eol native &&
133 echo "<<<<<<<" >expected &&
134 echo first line >>expected &&
135 echo same line >>expected &&
136 echo ======= >>expected &&
137 echo first line | append_cr >>expected &&
138 echo same line | append_cr >>expected &&
139 echo ">>>>>>>" >>expected &&
140 git config merge.renormalize false &&
141 rm -f .gitattributes &&
142 git reset --hard a &&
143 test_must_fail git merge b &&
144 fuzz_conflict file >file.fuzzy &&
145 compare_files expected file.fuzzy
148 test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
149 echo "<<<<<<<" >expected &&
150 echo first line | append_cr >>expected &&
151 echo same line | append_cr >>expected &&
152 echo ======= >>expected &&
153 echo first line >>expected &&
154 echo same line >>expected &&
155 echo ">>>>>>>" >>expected &&
156 git config merge.renormalize false &&
157 rm -f .gitattributes &&
158 git reset --hard b &&
159 test_must_fail git merge a &&
160 fuzz_conflict file >file.fuzzy &&
161 compare_files expected file.fuzzy
164 test_expect_success 'checkout -m after setting text=auto' '
165 cat <<-\EOF >expected &&
170 git config merge.renormalize true &&
172 rm -f .gitattributes &&
173 git reset --hard initial &&
174 git restore --source=a -- . &&
176 git diff --no-index --ignore-cr-at-eol expected file
179 test_expect_success 'checkout -m addition of text=auto' '
180 cat <<-\EOF >expected &&
185 git config merge.renormalize true &&
187 rm -f .gitattributes file &&
188 git reset --hard initial &&
189 git restore --source=b -- . &&
191 git diff --no-index --ignore-cr-at-eol expected file
194 test_expect_success 'Test delete/normalize conflict' '
195 git checkout -f side &&
197 rm -f .gitattributes &&
198 git reset --hard initial &&
200 git commit -m "remove file" &&
202 git reset --hard a^ &&
204 test_path_is_missing file