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 git reset --hard initial &&
29 test_commit "add-not-a-b" "ONE" "AAA" &&
30 git merge-tree initial add-not-a-b initial >actual &&
31 test_must_be_empty actual
34 test_expect_success
'file add A, B (same)' '
35 git reset --hard initial &&
36 test_commit "add-a-b-same-A" "ONE" "AAA" &&
37 git reset --hard initial &&
38 test_commit "add-a-b-same-B" "ONE" "AAA" &&
39 git merge-tree initial add-a-b-same-A add-a-b-same-B >actual &&
40 test_must_be_empty actual
43 test_expect_success
'file add A, B (different)' '
44 cat >expected <<\EXPECTED &&
46 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
47 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
56 git reset --hard initial &&
57 test_commit "add-a-b-diff-A" "ONE" "AAA" &&
58 git reset --hard initial &&
59 test_commit "add-a-b-diff-B" "ONE" "BBB" &&
60 git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual &&
61 test_cmp expected actual
64 test_expect_success
'file change A, !B' '
65 git reset --hard initial &&
66 test_commit "change-a-not-b" "initial-file" "BBB" &&
67 git merge-tree initial change-a-not-b initial >actual &&
68 test_must_be_empty actual
71 test_expect_success
'file change !A, B' '
72 cat >expected <<\EXPECTED &&
74 result 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
75 our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
81 git reset --hard initial &&
82 test_commit "change-not-a-b" "initial-file" "BBB" &&
83 git merge-tree initial initial change-not-a-b >actual &&
84 test_cmp expected actual
87 test_expect_success
'file change A, B (same)' '
88 git reset --hard initial &&
89 test_commit "change-a-b-same-A" "initial-file" "AAA" &&
90 git reset --hard initial &&
91 test_commit "change-a-b-same-B" "initial-file" "AAA" &&
92 git merge-tree initial change-a-b-same-A change-a-b-same-B >actual &&
93 test_must_be_empty actual
96 test_expect_success
'file change A, B (different)' '
97 cat >expected <<\EXPECTED &&
99 base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
100 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d initial-file
101 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
110 git reset --hard initial &&
111 test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
112 git reset --hard initial &&
113 test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
114 git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
115 test_cmp expected actual
118 test_expect_success
'file change A, B (mixed)' '
119 cat >expected <<\EXPECTED &&
121 base 100644 f4f1f998c7776568c4ff38f516d77fef9399b5a7 ONE
122 our 100644 af14c2c3475337c73759d561ef70b59e5c731176 ONE
123 their 100644 372d761493f524d44d59bd24700c3bdf914c973c ONE
138 git reset --hard initial &&
139 test_commit "change-a-b-mix-base" "ONE" "
155 test_commit "change-a-b-mix-A" "ONE" \
156 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" &&
157 git reset --hard change-a-b-mix-base &&
158 test_commit "change-a-b-mix-B" "ONE" \
159 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" &&
160 git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \
162 test_cmp expected actual
165 test_expect_success
'file remove A, !B' '
166 git reset --hard initial &&
167 test_commit "rm-a-not-b-base" "ONE" "AAA" &&
169 git commit -m "rm-a-not-b" &&
170 git tag "rm-a-not-b" &&
171 git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual &&
172 test_must_be_empty actual
175 test_expect_success
'file remove !A, B' '
176 cat >expected <<\EXPECTED &&
178 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
179 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
184 git reset --hard initial &&
185 test_commit "rm-not-a-b-base" "ONE" "AAA" &&
187 git commit -m "rm-not-a-b" &&
188 git tag "rm-not-a-b" &&
189 git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual &&
190 test_cmp expected actual
193 test_expect_success
'file remove A, B (same)' '
194 git reset --hard initial &&
195 test_commit "rm-a-b-base" "ONE" "AAA" &&
197 git commit -m "rm-a-b" &&
199 git merge-tree rm-a-b-base rm-a-b rm-a-b >actual &&
200 test_must_be_empty actual
203 test_expect_success
'file change A, remove B' '
204 cat >expected <<\EXPECTED &&
206 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
207 our 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
212 git reset --hard initial &&
213 test_commit "change-a-rm-b-base" "ONE" "AAA" &&
214 test_commit "change-a-rm-b-A" "ONE" "BBB" &&
215 git reset --hard change-a-rm-b-base &&
217 git commit -m "change-a-rm-b-B" &&
218 git tag "change-a-rm-b-B" &&
219 git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \
221 test_cmp expected actual
224 test_expect_success
'file remove A, change B' '
225 cat >expected <<\EXPECTED &&
227 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
228 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
231 git reset --hard initial &&
232 test_commit "rm-a-change-b-base" "ONE" "AAA" &&
235 git commit -m "rm-a-change-b-A" &&
236 git tag "rm-a-change-b-A" &&
237 git reset --hard rm-a-change-b-base &&
238 test_commit "rm-a-change-b-B" "ONE" "BBB" &&
239 git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \
241 test_cmp expected actual
244 test_expect_success
'tree add A, B (same)' '
245 git reset --hard initial &&
247 test_commit "add sub/file" "sub/file" "file" add-tree-A &&
248 git merge-tree initial add-tree-A add-tree-A >actual &&
249 test_must_be_empty actual
252 test_expect_success
'tree add A, B (different)' '
253 cat >expect <<-\EOF &&
255 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
256 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 sub/file
264 git reset --hard initial &&
266 test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
267 git reset --hard initial &&
269 test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B &&
270 git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual &&
271 test_cmp expect actual
274 test_expect_success
'tree unchanged A, removed B' '
275 cat >expect <<-\EOF &&
277 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
278 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
282 git reset --hard initial &&
284 test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
287 git commit -m "remove sub/file" &&
288 git tag tree-remove-b-B &&
289 git merge-tree tree-remove-b-initial tree-remove-b-initial tree-remove-b-B >actual &&
290 test_cmp expect actual
293 test_expect_success
'turn file to tree' '
294 git reset --hard initial &&
296 mkdir initial-file &&
297 test_commit "turn-file-to-tree" "initial-file/ONE" "CCC" &&
298 git merge-tree initial initial turn-file-to-tree >actual &&
299 cat >expect <<-\EOF &&
301 their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 initial-file/ONE
305 base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
306 our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
310 test_cmp expect actual
313 test_expect_success
'turn tree to file' '
314 git reset --hard initial &&
316 test_commit "add-tree" "dir/path" "AAA" &&
317 test_commit "add-another-tree" "dir/another" "BBB" &&
319 test_commit "make-file" "dir" "CCC" &&
320 git merge-tree add-tree add-another-tree make-file >actual &&
321 cat >expect <<-\EOF &&
323 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
324 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
328 their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 dir
332 test_cmp expect actual