]>
Commit | Line | Data |
---|---|---|
f32e9852 WP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010 Will Palmer | |
4 | # | |
5 | ||
6 | test_description='git merge-tree' | |
7ff24785 ÆAB |
7 | |
8 | TEST_PASSES_SANITIZE_LEAK=true | |
f32e9852 WP |
9 | . ./test-lib.sh |
10 | ||
11 | test_expect_success setup ' | |
12 | test_commit "initial" "initial-file" "initial" | |
13 | ' | |
14 | ||
15 | test_expect_success 'file add A, !B' ' | |
525a7f17 | 16 | git reset --hard initial && |
17 | test_commit "add-a-not-b" "ONE" "AAA" && | |
18 | git merge-tree initial initial add-a-not-b >actual && | |
19 | cat >expected <<EXPECTED && | |
f32e9852 | 20 | added in remote |
525a7f17 | 21 | their 100644 $(git rev-parse HEAD:ONE) ONE |
f32e9852 WP |
22 | @@ -0,0 +1 @@ |
23 | +AAA | |
24 | EXPECTED | |
25 | ||
f32e9852 WP |
26 | test_cmp expected actual |
27 | ' | |
28 | ||
21baa6e0 | 29 | test_expect_success 'file add !A, B' ' |
f32e9852 WP |
30 | git reset --hard initial && |
31 | test_commit "add-not-a-b" "ONE" "AAA" && | |
32 | git merge-tree initial add-not-a-b initial >actual && | |
1c5e94f4 | 33 | test_must_be_empty actual |
f32e9852 WP |
34 | ' |
35 | ||
36 | test_expect_success 'file add A, B (same)' ' | |
f32e9852 WP |
37 | git reset --hard initial && |
38 | test_commit "add-a-b-same-A" "ONE" "AAA" && | |
39 | git reset --hard initial && | |
40 | test_commit "add-a-b-same-B" "ONE" "AAA" && | |
41 | git merge-tree initial add-a-b-same-A add-a-b-same-B >actual && | |
1c5e94f4 | 42 | test_must_be_empty actual |
f32e9852 WP |
43 | ' |
44 | ||
45 | test_expect_success 'file add A, B (different)' ' | |
525a7f17 | 46 | git reset --hard initial && |
47 | test_commit "add-a-b-diff-A" "ONE" "AAA" && | |
48 | git reset --hard initial && | |
49 | test_commit "add-a-b-diff-B" "ONE" "BBB" && | |
50 | git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual && | |
51 | cat >expected <<EXPECTED && | |
f32e9852 | 52 | added in both |
525a7f17 | 53 | our 100644 $(git rev-parse add-a-b-diff-A:ONE) ONE |
54 | their 100644 $(git rev-parse add-a-b-diff-B:ONE) ONE | |
f32e9852 WP |
55 | @@ -1 +1,5 @@ |
56 | +<<<<<<< .our | |
57 | AAA | |
58 | +======= | |
59 | +BBB | |
60 | +>>>>>>> .their | |
61 | EXPECTED | |
62 | ||
f32e9852 WP |
63 | test_cmp expected actual |
64 | ' | |
65 | ||
66 | test_expect_success 'file change A, !B' ' | |
f32e9852 WP |
67 | git reset --hard initial && |
68 | test_commit "change-a-not-b" "initial-file" "BBB" && | |
69 | git merge-tree initial change-a-not-b initial >actual && | |
1c5e94f4 | 70 | test_must_be_empty actual |
f32e9852 WP |
71 | ' |
72 | ||
73 | test_expect_success 'file change !A, B' ' | |
525a7f17 | 74 | git reset --hard initial && |
75 | test_commit "change-not-a-b" "initial-file" "BBB" && | |
76 | git merge-tree initial initial change-not-a-b >actual && | |
77 | cat >expected <<EXPECTED && | |
f32e9852 | 78 | merged |
525a7f17 | 79 | result 100644 $(git rev-parse change-a-not-b:initial-file) initial-file |
80 | our 100644 $(git rev-parse initial:initial-file ) initial-file | |
f32e9852 WP |
81 | @@ -1 +1 @@ |
82 | -initial | |
83 | +BBB | |
84 | EXPECTED | |
85 | ||
f32e9852 WP |
86 | test_cmp expected actual |
87 | ' | |
88 | ||
e95bafc5 JC |
89 | test_expect_success '3-way merge with --attr-source' ' |
90 | test_when_finished rm -rf 3-way && | |
91 | git init 3-way && | |
92 | ( | |
93 | cd 3-way && | |
94 | test_commit initial file1 foo && | |
95 | base=$(git rev-parse HEAD) && | |
96 | git checkout -b brancha && | |
97 | echo bar >>file1 && | |
98 | git commit -am "adding bar" && | |
99 | source=$(git rev-parse HEAD) && | |
100 | git checkout @{-1} && | |
101 | git checkout -b branchb && | |
102 | echo baz >>file1 && | |
103 | git commit -am "adding baz" && | |
104 | merge=$(git rev-parse HEAD) && | |
105 | git checkout -b gitattributes && | |
106 | test_commit "gitattributes" .gitattributes "file1 merge=union" && | |
107 | git checkout @{-1} && | |
108 | tree=$(git --attr-source=gitattributes merge-tree --write-tree \ | |
109 | --merge-base "$base" --end-of-options "$source" "$merge") && | |
110 | test_write_lines foo bar baz >expect && | |
111 | git cat-file -p "$tree:file1" >actual && | |
112 | test_cmp expect actual | |
113 | ) | |
114 | ' | |
115 | ||
f32e9852 | 116 | test_expect_success 'file change A, B (same)' ' |
f32e9852 WP |
117 | git reset --hard initial && |
118 | test_commit "change-a-b-same-A" "initial-file" "AAA" && | |
119 | git reset --hard initial && | |
120 | test_commit "change-a-b-same-B" "initial-file" "AAA" && | |
121 | git merge-tree initial change-a-b-same-A change-a-b-same-B >actual && | |
1c5e94f4 | 122 | test_must_be_empty actual |
f32e9852 WP |
123 | ' |
124 | ||
125 | test_expect_success 'file change A, B (different)' ' | |
525a7f17 | 126 | git reset --hard initial && |
127 | test_commit "change-a-b-diff-A" "initial-file" "AAA" && | |
128 | git reset --hard initial && | |
129 | test_commit "change-a-b-diff-B" "initial-file" "BBB" && | |
130 | git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual && | |
131 | cat >expected <<EXPECTED && | |
f32e9852 | 132 | changed in both |
525a7f17 | 133 | base 100644 $(git rev-parse initial:initial-file ) initial-file |
134 | our 100644 $(git rev-parse change-a-b-diff-A:initial-file) initial-file | |
135 | their 100644 $(git rev-parse change-a-b-diff-B:initial-file) initial-file | |
f32e9852 WP |
136 | @@ -1 +1,5 @@ |
137 | +<<<<<<< .our | |
138 | AAA | |
139 | +======= | |
140 | +BBB | |
141 | +>>>>>>> .their | |
142 | EXPECTED | |
143 | ||
f32e9852 WP |
144 | test_cmp expected actual |
145 | ' | |
146 | ||
147 | test_expect_success 'file change A, B (mixed)' ' | |
f32e9852 WP |
148 | git reset --hard initial && |
149 | test_commit "change-a-b-mix-base" "ONE" " | |
150 | AAA | |
151 | AAA | |
152 | AAA | |
153 | AAA | |
154 | AAA | |
155 | AAA | |
156 | AAA | |
157 | AAA | |
158 | AAA | |
159 | AAA | |
160 | AAA | |
161 | AAA | |
162 | AAA | |
163 | AAA | |
164 | AAA" && | |
165 | test_commit "change-a-b-mix-A" "ONE" \ | |
166 | "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" && | |
167 | git reset --hard change-a-b-mix-base && | |
168 | test_commit "change-a-b-mix-B" "ONE" \ | |
169 | "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" && | |
170 | git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \ | |
171 | >actual && | |
525a7f17 | 172 | |
173 | cat >expected <<EXPECTED && | |
174 | changed in both | |
175 | base 100644 $(git rev-parse change-a-b-mix-base:ONE) ONE | |
176 | our 100644 $(git rev-parse change-a-b-mix-A:ONE ) ONE | |
177 | their 100644 $(git rev-parse change-a-b-mix-B:ONE ) ONE | |
178 | @@ -7,7 +7,11 @@ | |
179 | AAA | |
180 | AAA | |
181 | AAA | |
182 | +<<<<<<< .our | |
183 | BBB | |
184 | +======= | |
185 | +CCC | |
186 | +>>>>>>> .their | |
187 | AAA | |
188 | AAA | |
189 | AAA | |
190 | EXPECTED | |
191 | ||
f32e9852 WP |
192 | test_cmp expected actual |
193 | ' | |
194 | ||
195 | test_expect_success 'file remove A, !B' ' | |
f32e9852 WP |
196 | git reset --hard initial && |
197 | test_commit "rm-a-not-b-base" "ONE" "AAA" && | |
198 | git rm ONE && | |
199 | git commit -m "rm-a-not-b" && | |
200 | git tag "rm-a-not-b" && | |
201 | git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual && | |
1c5e94f4 | 202 | test_must_be_empty actual |
f32e9852 WP |
203 | ' |
204 | ||
21baa6e0 | 205 | test_expect_success 'file remove !A, B' ' |
f32e9852 WP |
206 | git reset --hard initial && |
207 | test_commit "rm-not-a-b-base" "ONE" "AAA" && | |
208 | git rm ONE && | |
209 | git commit -m "rm-not-a-b" && | |
210 | git tag "rm-not-a-b" && | |
211 | git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual && | |
525a7f17 | 212 | cat >expected <<EXPECTED && |
213 | removed in remote | |
214 | base 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE | |
215 | our 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE | |
216 | @@ -1 +0,0 @@ | |
217 | -AAA | |
218 | EXPECTED | |
219 | ||
f32e9852 WP |
220 | test_cmp expected actual |
221 | ' | |
222 | ||
ab5f4242 | 223 | test_expect_success 'file remove A, B (same)' ' |
ab5f4242 JK |
224 | git reset --hard initial && |
225 | test_commit "rm-a-b-base" "ONE" "AAA" && | |
226 | git rm ONE && | |
227 | git commit -m "rm-a-b" && | |
228 | git tag "rm-a-b" && | |
229 | git merge-tree rm-a-b-base rm-a-b rm-a-b >actual && | |
1c5e94f4 | 230 | test_must_be_empty actual |
ab5f4242 JK |
231 | ' |
232 | ||
21baa6e0 | 233 | test_expect_success 'file change A, remove B' ' |
f32e9852 WP |
234 | git reset --hard initial && |
235 | test_commit "change-a-rm-b-base" "ONE" "AAA" && | |
236 | test_commit "change-a-rm-b-A" "ONE" "BBB" && | |
237 | git reset --hard change-a-rm-b-base && | |
238 | git rm ONE && | |
239 | git commit -m "change-a-rm-b-B" && | |
240 | git tag "change-a-rm-b-B" && | |
241 | git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \ | |
242 | >actual && | |
525a7f17 | 243 | cat >expected <<EXPECTED && |
244 | removed in remote | |
245 | base 100644 $(git rev-parse change-a-rm-b-base:ONE) ONE | |
246 | our 100644 $(git rev-parse change-a-rm-b-A:ONE ) ONE | |
247 | @@ -1 +0,0 @@ | |
248 | -BBB | |
249 | EXPECTED | |
250 | ||
f32e9852 WP |
251 | test_cmp expected actual |
252 | ' | |
253 | ||
254 | test_expect_success 'file remove A, change B' ' | |
f32e9852 WP |
255 | git reset --hard initial && |
256 | test_commit "rm-a-change-b-base" "ONE" "AAA" && | |
257 | ||
258 | git rm ONE && | |
259 | git commit -m "rm-a-change-b-A" && | |
260 | git tag "rm-a-change-b-A" && | |
261 | git reset --hard rm-a-change-b-base && | |
262 | test_commit "rm-a-change-b-B" "ONE" "BBB" && | |
263 | git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \ | |
264 | >actual && | |
525a7f17 | 265 | cat >expected <<EXPECTED && |
266 | removed in local | |
267 | base 100644 $(git rev-parse rm-a-change-b-base:ONE) ONE | |
268 | their 100644 $(git rev-parse rm-a-change-b-B:ONE ) ONE | |
269 | EXPECTED | |
f32e9852 WP |
270 | test_cmp expected actual |
271 | ' | |
272 | ||
94883b43 | 273 | test_expect_success 'tree add A, B (same)' ' |
94883b43 JK |
274 | git reset --hard initial && |
275 | mkdir sub && | |
276 | test_commit "add sub/file" "sub/file" "file" add-tree-A && | |
277 | git merge-tree initial add-tree-A add-tree-A >actual && | |
1c5e94f4 | 278 | test_must_be_empty actual |
94883b43 JK |
279 | ' |
280 | ||
281 | test_expect_success 'tree add A, B (different)' ' | |
525a7f17 | 282 | git reset --hard initial && |
283 | mkdir sub && | |
284 | test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A && | |
285 | git reset --hard initial && | |
286 | mkdir sub && | |
287 | test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B && | |
288 | git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual && | |
289 | cat >expect <<-EOF && | |
94883b43 | 290 | added in both |
525a7f17 | 291 | our 100644 $(git rev-parse add-tree-a-b-A:sub/file) sub/file |
292 | their 100644 $(git rev-parse add-tree-a-b-B:sub/file) sub/file | |
94883b43 JK |
293 | @@ -1 +1,5 @@ |
294 | +<<<<<<< .our | |
295 | AAA | |
296 | +======= | |
297 | +BBB | |
298 | +>>>>>>> .their | |
299 | EOF | |
94883b43 JK |
300 | test_cmp expect actual |
301 | ' | |
302 | ||
303 | test_expect_success 'tree unchanged A, removed B' ' | |
94883b43 JK |
304 | git reset --hard initial && |
305 | mkdir sub && | |
306 | test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial && | |
307 | git rm sub/file && | |
308 | test_tick && | |
309 | git commit -m "remove sub/file" && | |
310 | git tag tree-remove-b-B && | |
311 | git merge-tree tree-remove-b-initial tree-remove-b-initial tree-remove-b-B >actual && | |
525a7f17 | 312 | cat >expect <<-EOF && |
313 | removed in remote | |
314 | base 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file | |
315 | our 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file | |
316 | @@ -1 +0,0 @@ | |
317 | -AAA | |
318 | EOF | |
94883b43 JK |
319 | test_cmp expect actual |
320 | ' | |
321 | ||
35ffe758 | 322 | test_expect_success 'turn file to tree' ' |
8dd15c6a JH |
323 | git reset --hard initial && |
324 | rm initial-file && | |
325 | mkdir initial-file && | |
326 | test_commit "turn-file-to-tree" "initial-file/ONE" "CCC" && | |
327 | git merge-tree initial initial turn-file-to-tree >actual && | |
525a7f17 | 328 | cat >expect <<-EOF && |
8dd15c6a | 329 | added in remote |
525a7f17 | 330 | their 100644 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE |
8dd15c6a JH |
331 | @@ -0,0 +1 @@ |
332 | +CCC | |
333 | removed in remote | |
525a7f17 | 334 | base 100644 $(git rev-parse initial:initial-file) initial-file |
335 | our 100644 $(git rev-parse initial:initial-file) initial-file | |
8dd15c6a JH |
336 | @@ -1 +0,0 @@ |
337 | -initial | |
338 | EOF | |
339 | test_cmp expect actual | |
340 | ' | |
341 | ||
35ffe758 | 342 | test_expect_success 'turn tree to file' ' |
8dd15c6a JH |
343 | git reset --hard initial && |
344 | mkdir dir && | |
345 | test_commit "add-tree" "dir/path" "AAA" && | |
346 | test_commit "add-another-tree" "dir/another" "BBB" && | |
347 | rm -fr dir && | |
348 | test_commit "make-file" "dir" "CCC" && | |
349 | git merge-tree add-tree add-another-tree make-file >actual && | |
525a7f17 | 350 | cat >expect <<-EOF && |
8dd15c6a | 351 | removed in remote |
525a7f17 | 352 | base 100644 $(git rev-parse add-tree:dir/path) dir/path |
353 | our 100644 $(git rev-parse add-tree:dir/path) dir/path | |
8dd15c6a JH |
354 | @@ -1 +0,0 @@ |
355 | -AAA | |
356 | added in remote | |
525a7f17 | 357 | their 100644 $(git rev-parse make-file:dir) dir |
8dd15c6a JH |
358 | @@ -0,0 +1 @@ |
359 | +CCC | |
360 | EOF | |
361 | test_cmp expect actual | |
362 | ' | |
363 | ||
b6551fea DS |
364 | test_expect_success 'merge-tree respects core.useReplaceRefs=false' ' |
365 | test_commit merge-to && | |
366 | test_commit valid base && | |
367 | git reset --hard HEAD^ && | |
368 | test_commit malicious base && | |
369 | ||
370 | test_when_finished "git replace -d $(git rev-parse valid^0)" && | |
371 | git replace valid^0 malicious^0 && | |
372 | ||
373 | tree=$(git -c core.useReplaceRefs=true merge-tree --write-tree merge-to valid) && | |
374 | merged=$(git cat-file -p $tree:base) && | |
375 | test malicious = $merged && | |
376 | ||
377 | tree=$(git -c core.useReplaceRefs=false merge-tree --write-tree merge-to valid) && | |
378 | merged=$(git cat-file -p $tree:base) && | |
379 | test valid = $merged | |
380 | ' | |
381 | ||
f32e9852 | 382 | test_done |