3 # Copyright (c) 2010 Will Palmer
6 test_description='git merge-tree'
9 test_expect_success setup '
10 test_commit "initial" "initial-file" "initial"
13 test_expect_success 'file add A, !B' '
14 cat >expected <<\EXPECTED &&
16 their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
21 git reset --hard initial &&
22 test_commit "add-a-not-b" "ONE" "AAA" &&
23 git merge-tree initial initial add-a-not-b >actual &&
24 test_cmp expected actual
27 test_expect_success 'file add !A, B' '
28 cat >expected <<\EXPECTED &&
31 git reset --hard initial &&
32 test_commit "add-not-a-b" "ONE" "AAA" &&
33 git merge-tree initial add-not-a-b initial >actual &&
34 test_cmp expected actual
37 test_expect_success 'file add A, B (same)' '
38 cat >expected <<\EXPECTED &&
41 git reset --hard initial &&
42 test_commit "add-a-b-same-A" "ONE" "AAA" &&
43 git reset --hard initial &&
44 test_commit "add-a-b-same-B" "ONE" "AAA" &&
45 git merge-tree initial add-a-b-same-A add-a-b-same-B >actual &&
46 test_cmp expected actual
49 test_expect_success 'file add A, B (different)' '
50 cat >expected <<\EXPECTED &&
52 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
53 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
62 git reset --hard initial &&
63 test_commit "add-a-b-diff-A" "ONE" "AAA" &&
64 git reset --hard initial &&
65 test_commit "add-a-b-diff-B" "ONE" "BBB" &&
66 git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual &&
67 test_cmp expected actual
70 test_expect_success 'file change A, !B' '
71 cat >expected <<\EXPECTED &&
74 git reset --hard initial &&
75 test_commit "change-a-not-b" "initial-file" "BBB" &&
76 git merge-tree initial change-a-not-b initial >actual &&
77 test_cmp expected actual
80 test_expect_success 'file change !A, B' '
81 cat >expected <<\EXPECTED &&
83 result 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
84 our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
90 git reset --hard initial &&
91 test_commit "change-not-a-b" "initial-file" "BBB" &&
92 git merge-tree initial initial change-not-a-b >actual &&
93 test_cmp expected actual
96 test_expect_success 'file change A, B (same)' '
97 cat >expected <<\EXPECTED &&
100 git reset --hard initial &&
101 test_commit "change-a-b-same-A" "initial-file" "AAA" &&
102 git reset --hard initial &&
103 test_commit "change-a-b-same-B" "initial-file" "AAA" &&
104 git merge-tree initial change-a-b-same-A change-a-b-same-B >actual &&
105 test_cmp expected actual
108 test_expect_success 'file change A, B (different)' '
109 cat >expected <<\EXPECTED &&
111 base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
112 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d initial-file
113 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
122 git reset --hard initial &&
123 test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
124 git reset --hard initial &&
125 test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
126 git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
127 test_cmp expected actual
130 test_expect_success 'file change A, B (mixed)' '
131 cat >expected <<\EXPECTED &&
133 base 100644 f4f1f998c7776568c4ff38f516d77fef9399b5a7 ONE
134 our 100644 af14c2c3475337c73759d561ef70b59e5c731176 ONE
135 their 100644 372d761493f524d44d59bd24700c3bdf914c973c ONE
150 git reset --hard initial &&
151 test_commit "change-a-b-mix-base" "ONE" "
167 test_commit "change-a-b-mix-A" "ONE" \
168 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" &&
169 git reset --hard change-a-b-mix-base &&
170 test_commit "change-a-b-mix-B" "ONE" \
171 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" &&
172 git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \
174 test_cmp expected actual
177 test_expect_success 'file remove A, !B' '
178 cat >expected <<\EXPECTED &&
181 git reset --hard initial &&
182 test_commit "rm-a-not-b-base" "ONE" "AAA" &&
184 git commit -m "rm-a-not-b" &&
185 git tag "rm-a-not-b" &&
186 git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual &&
187 test_cmp expected actual
190 test_expect_success 'file remove !A, B' '
191 cat >expected <<\EXPECTED &&
193 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
194 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
199 git reset --hard initial &&
200 test_commit "rm-not-a-b-base" "ONE" "AAA" &&
202 git commit -m "rm-not-a-b" &&
203 git tag "rm-not-a-b" &&
204 git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual &&
205 test_cmp expected actual
208 test_expect_success 'file remove A, B (same)' '
209 cat >expected <<\EXPECTED &&
212 git reset --hard initial &&
213 test_commit "rm-a-b-base" "ONE" "AAA" &&
215 git commit -m "rm-a-b" &&
217 git merge-tree rm-a-b-base rm-a-b rm-a-b >actual &&
218 test_cmp expected actual
221 test_expect_success 'file change A, remove B' '
222 cat >expected <<\EXPECTED &&
224 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
225 our 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
230 git reset --hard initial &&
231 test_commit "change-a-rm-b-base" "ONE" "AAA" &&
232 test_commit "change-a-rm-b-A" "ONE" "BBB" &&
233 git reset --hard change-a-rm-b-base &&
235 git commit -m "change-a-rm-b-B" &&
236 git tag "change-a-rm-b-B" &&
237 git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \
239 test_cmp expected actual
242 test_expect_success 'file remove A, change B' '
243 cat >expected <<\EXPECTED &&
245 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
246 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
249 git reset --hard initial &&
250 test_commit "rm-a-change-b-base" "ONE" "AAA" &&
253 git commit -m "rm-a-change-b-A" &&
254 git tag "rm-a-change-b-A" &&
255 git reset --hard rm-a-change-b-base &&
256 test_commit "rm-a-change-b-B" "ONE" "BBB" &&
257 git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \
259 test_cmp expected actual
262 test_expect_success 'tree add A, B (same)' '
263 cat >expect <<-\EOF &&
265 git reset --hard initial &&
267 test_commit "add sub/file" "sub/file" "file" add-tree-A &&
268 git merge-tree initial add-tree-A add-tree-A >actual &&
269 test_cmp expect actual
272 test_expect_success 'tree add A, B (different)' '
273 cat >expect <<-\EOF &&
275 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
276 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 sub/file
284 git reset --hard initial &&
286 test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
287 git reset --hard initial &&
289 test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B &&
290 git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual &&
291 test_cmp expect actual
294 test_expect_success 'tree unchanged A, removed B' '
295 cat >expect <<-\EOF &&
297 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
298 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
302 git reset --hard initial &&
304 test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
307 git commit -m "remove sub/file" &&
308 git tag tree-remove-b-B &&
309 git merge-tree tree-remove-b-initial tree-remove-b-initial tree-remove-b-B >actual &&
310 test_cmp expect actual
313 test_expect_success 'turn file to tree' '
314 git reset --hard initial &&
316 mkdir initial-file &&
317 test_commit "turn-file-to-tree" "initial-file/ONE" "CCC" &&
318 git merge-tree initial initial turn-file-to-tree >actual &&
319 cat >expect <<-\EOF &&
321 their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 initial-file/ONE
325 base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
326 our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
330 test_cmp expect actual
333 test_expect_success 'turn tree to file' '
334 git reset --hard initial &&
336 test_commit "add-tree" "dir/path" "AAA" &&
337 test_commit "add-another-tree" "dir/another" "BBB" &&
339 test_commit "make-file" "dir" "CCC" &&
340 git merge-tree add-tree add-another-tree make-file >actual &&
341 cat >expect <<-\EOF &&
343 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
344 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
348 their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 dir
352 test_cmp expect actual