Git 2.45
[git/gitster.git] / t / t6418-merge-text-auto.sh
blob48a62cb85568bfb7f77a8c597096617dfa5fcf4c
1 #!/bin/sh
3 test_description='CRLF merge conflict across text=auto change
5 * [main] remove .gitattributes
6 ! [side] add line from b
7 --
8 + [side] add line from b
9 * [main] remove .gitattributes
10 * [main^] add line from a
11 * [main~2] normalize file
12 *+ [side^] Initial
15 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
16 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18 TEST_PASSES_SANITIZE_LEAK=true
19 . ./test-lib.sh
21 test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
23 compare_files () {
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 &&
38 test_tick &&
39 git commit -m "Initial" &&
40 git tag initial &&
41 git branch side &&
43 echo "* text=auto" >.gitattributes &&
44 echo first line >file &&
45 git add .gitattributes file &&
46 test_tick &&
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 &&
52 test_tick &&
53 git commit -m "add line from a" &&
54 git tag a &&
56 git rm .gitattributes &&
57 rm file &&
58 git checkout file &&
59 test_tick &&
60 git commit -m "remove .gitattributes" &&
61 git tag c &&
63 git checkout side &&
64 echo same line | append_cr >>file &&
65 echo same line >>control_file &&
66 git add file control_file &&
67 test_tick &&
68 git commit -m "add line from b" &&
69 git tag b &&
71 git checkout main
74 test_expect_success 'set up fuzz_conflict() helper' '
75 fuzz_conflict() {
76 sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
80 test_expect_success 'Merge after setting text=auto' '
81 cat <<-\EOF >expected &&
82 first line
83 same line
84 EOF
86 if test_have_prereq NATIVE_CRLF; then
87 append_cr <expected >expected.temp &&
88 mv expected.temp expected
89 fi &&
90 git config merge.renormalize true &&
91 git rm -fr . &&
92 rm -f .gitattributes &&
93 git reset --hard a &&
94 git merge b &&
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 &&
101 first line
102 same line
105 git config merge.renormalize true &&
106 git rm -fr . &&
107 rm -f .gitattributes &&
108 git reset --hard b &&
109 git merge a &&
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 &&
116 first line
117 same line
120 append_cr <expected >expected.temp &&
121 mv expected.temp expected &&
122 git config merge.renormalize true &&
123 git rm -fr . &&
124 rm -f .gitattributes &&
125 git reset --hard b &&
126 echo >&2 "After git reset --hard b" &&
127 git ls-files -s --eol >&2 &&
128 git merge a &&
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 &&
167 first line
168 same line
171 git config merge.renormalize true &&
172 git rm -fr . &&
173 rm -f .gitattributes &&
174 git reset --hard initial &&
175 git restore --source=a -- . &&
176 git checkout -m b &&
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 &&
182 first line
183 same line
186 git config merge.renormalize true &&
187 git rm -fr . &&
188 rm -f .gitattributes file &&
189 git reset --hard initial &&
190 git restore --source=b -- . &&
191 git checkout -m a &&
192 git diff --no-index --ignore-cr-at-eol expected file
195 test_expect_success 'Test delete/normalize conflict' '
196 git checkout -f side &&
197 git rm -fr . &&
198 rm -f .gitattributes &&
199 git reset --hard initial &&
200 git rm file &&
201 git commit -m "remove file" &&
202 git checkout main &&
203 git reset --hard a^ &&
204 git merge side &&
205 test_path_is_missing file
208 test_expect_success 'rename/delete vs. renormalization' '
209 git init subrepo &&
211 cd subrepo &&
212 echo foo >oldfile &&
213 git add oldfile &&
214 git commit -m original &&
216 git branch rename &&
217 git branch nuke &&
219 git checkout rename &&
220 git mv oldfile newfile &&
221 git commit -m renamed &&
223 git checkout nuke &&
224 git rm oldfile &&
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
234 test_done