]>
Commit | Line | Data |
---|---|---|
f217f0e8 EB |
1 | #!/bin/sh |
2 | ||
18acb30e JN |
3 | test_description='CRLF merge conflict across text=auto change |
4 | ||
5902f5f4 | 5 | * [main] remove .gitattributes |
18acb30e JN |
6 | ! [side] add line from b |
7 | -- | |
8 | + [side] add line from b | |
5902f5f4 JS |
9 | * [main] remove .gitattributes |
10 | * [main^] add line from a | |
11 | * [main~2] normalize file | |
18acb30e JN |
12 | *+ [side^] Initial |
13 | ' | |
f217f0e8 | 14 | |
5902f5f4 | 15 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
16 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
17 | ||
2f64da07 | 18 | TEST_PASSES_SANITIZE_LEAK=true |
f217f0e8 EB |
19 | . ./test-lib.sh |
20 | ||
a31d0665 | 21 | test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b |
ca02ad34 | 22 | |
65237284 TB |
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 | |
28 | } | |
29 | ||
f217f0e8 | 30 | test_expect_success setup ' |
f217f0e8 | 31 | git config core.autocrlf false && |
18acb30e | 32 | |
f217f0e8 EB |
33 | echo first line | append_cr >file && |
34 | echo first line >control_file && | |
35 | echo only line >inert_file && | |
18acb30e | 36 | |
f217f0e8 | 37 | git add file control_file inert_file && |
18acb30e | 38 | test_tick && |
f217f0e8 EB |
39 | git commit -m "Initial" && |
40 | git tag initial && | |
41 | git branch side && | |
18acb30e | 42 | |
f217f0e8 | 43 | echo "* text=auto" >.gitattributes && |
65237284 | 44 | echo first line >file && |
f217f0e8 | 45 | git add .gitattributes file && |
18acb30e | 46 | test_tick && |
f217f0e8 | 47 | git commit -m "normalize file" && |
18acb30e | 48 | |
f217f0e8 EB |
49 | echo same line | append_cr >>file && |
50 | echo same line >>control_file && | |
51 | git add file control_file && | |
18acb30e | 52 | test_tick && |
f217f0e8 EB |
53 | git commit -m "add line from a" && |
54 | git tag a && | |
18acb30e | 55 | |
f217f0e8 EB |
56 | git rm .gitattributes && |
57 | rm file && | |
58 | git checkout file && | |
18acb30e | 59 | test_tick && |
f217f0e8 EB |
60 | git commit -m "remove .gitattributes" && |
61 | git tag c && | |
18acb30e | 62 | |
f217f0e8 EB |
63 | git checkout side && |
64 | echo same line | append_cr >>file && | |
65 | echo same line >>control_file && | |
66 | git add file control_file && | |
18acb30e | 67 | test_tick && |
f217f0e8 EB |
68 | git commit -m "add line from b" && |
69 | git tag b && | |
18acb30e | 70 | |
5902f5f4 | 71 | git checkout main |
f217f0e8 EB |
72 | ' |
73 | ||
beeeb454 JN |
74 | test_expect_success 'set up fuzz_conflict() helper' ' |
75 | fuzz_conflict() { | |
ca02ad34 | 76 | sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@" |
beeeb454 JN |
77 | } |
78 | ' | |
79 | ||
18acb30e JN |
80 | test_expect_success 'Merge after setting text=auto' ' |
81 | cat <<-\EOF >expected && | |
82 | first line | |
83 | same line | |
84 | EOF | |
85 | ||
5f4e02e5 BL |
86 | if test_have_prereq NATIVE_CRLF; then |
87 | append_cr <expected >expected.temp && | |
88 | mv expected.temp expected | |
89 | fi && | |
beeeb454 | 90 | git config merge.renormalize true && |
18acb30e JN |
91 | git rm -fr . && |
92 | rm -f .gitattributes && | |
f217f0e8 EB |
93 | git reset --hard a && |
94 | git merge b && | |
65237284 | 95 | compare_files expected file |
f217f0e8 EB |
96 | ' |
97 | ||
1335d76e JH |
98 | test_expect_success 'Merge addition of text=auto eol=LF' ' |
99 | git config core.eol lf && | |
18acb30e JN |
100 | cat <<-\EOF >expected && |
101 | first line | |
102 | same line | |
103 | EOF | |
104 | ||
beeeb454 | 105 | git config merge.renormalize true && |
18acb30e JN |
106 | git rm -fr . && |
107 | rm -f .gitattributes && | |
f217f0e8 EB |
108 | git reset --hard b && |
109 | git merge a && | |
65237284 | 110 | compare_files expected file |
f217f0e8 EB |
111 | ' |
112 | ||
1335d76e JH |
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 | |
118 | EOF | |
119 | ||
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 | |
130 | ' | |
131 | ||
beeeb454 | 132 | test_expect_success 'Detect CRLF/LF conflict after setting text=auto' ' |
1335d76e | 133 | git config core.eol native && |
5f4e02e5 | 134 | echo "<<<<<<<" >expected && |
1335d76e JH |
135 | echo first line >>expected && |
136 | echo same line >>expected && | |
137 | echo ======= >>expected && | |
5f4e02e5 BL |
138 | echo first line | append_cr >>expected && |
139 | echo same line | append_cr >>expected && | |
140 | echo ">>>>>>>" >>expected && | |
beeeb454 JN |
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 && | |
65237284 | 146 | compare_files expected file.fuzzy |
beeeb454 JN |
147 | ' |
148 | ||
149 | test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' ' | |
5f4e02e5 BL |
150 | echo "<<<<<<<" >expected && |
151 | echo first line | append_cr >>expected && | |
152 | echo same line | append_cr >>expected && | |
1335d76e JH |
153 | echo ======= >>expected && |
154 | echo first line >>expected && | |
155 | echo same line >>expected && | |
5f4e02e5 | 156 | echo ">>>>>>>" >>expected && |
beeeb454 JN |
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 && | |
65237284 | 162 | compare_files expected file.fuzzy |
beeeb454 JN |
163 | ' |
164 | ||
8d552258 | 165 | test_expect_success 'checkout -m after setting text=auto' ' |
d347cee4 JN |
166 | cat <<-\EOF >expected && |
167 | first line | |
168 | same line | |
169 | EOF | |
170 | ||
beeeb454 | 171 | git config merge.renormalize true && |
d347cee4 JN |
172 | git rm -fr . && |
173 | rm -f .gitattributes && | |
174 | git reset --hard initial && | |
fe48efb5 | 175 | git restore --source=a -- . && |
d347cee4 | 176 | git checkout -m b && |
fe48efb5 | 177 | git diff --no-index --ignore-cr-at-eol expected file |
d347cee4 JN |
178 | ' |
179 | ||
8d552258 | 180 | test_expect_success 'checkout -m addition of text=auto' ' |
d347cee4 JN |
181 | cat <<-\EOF >expected && |
182 | first line | |
183 | same line | |
184 | EOF | |
185 | ||
beeeb454 | 186 | git config merge.renormalize true && |
d347cee4 JN |
187 | git rm -fr . && |
188 | rm -f .gitattributes file && | |
189 | git reset --hard initial && | |
fe48efb5 | 190 | git restore --source=b -- . && |
d347cee4 | 191 | git checkout -m a && |
fe48efb5 | 192 | git diff --no-index --ignore-cr-at-eol expected file |
d347cee4 JN |
193 | ' |
194 | ||
331a1838 | 195 | test_expect_success 'Test delete/normalize conflict' ' |
18acb30e JN |
196 | git checkout -f side && |
197 | git rm -fr . && | |
198 | rm -f .gitattributes && | |
f217f0e8 EB |
199 | git reset --hard initial && |
200 | git rm file && | |
201 | git commit -m "remove file" && | |
5902f5f4 | 202 | git checkout main && |
f217f0e8 | 203 | git reset --hard a^ && |
bc29dffe EN |
204 | git merge side && |
205 | test_path_is_missing file | |
f217f0e8 EB |
206 | ' |
207 | ||
d30126c2 EN |
208 | test_expect_success 'rename/delete vs. renormalization' ' |
209 | git init subrepo && | |
210 | ( | |
211 | cd subrepo && | |
212 | echo foo >oldfile && | |
213 | git add oldfile && | |
214 | git commit -m original && | |
215 | ||
216 | git branch rename && | |
217 | git branch nuke && | |
218 | ||
219 | git checkout rename && | |
220 | git mv oldfile newfile && | |
221 | git commit -m renamed && | |
222 | ||
223 | git checkout nuke && | |
224 | git rm oldfile && | |
225 | git commit -m deleted && | |
226 | ||
227 | git checkout rename^0 && | |
228 | test_must_fail git -c merge.renormalize=true merge nuke >out && | |
229 | ||
230 | grep "rename/delete" out | |
231 | ) | |
232 | ' | |
233 | ||
f217f0e8 | 234 | test_done |