3 # Copyright (c) 2010 Will Palmer
6 test_description
='git merge-tree'
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success setup
'
12 test_commit "initial" "initial-file" "initial"
15 test_expect_success
'file add A, !B' '
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 &&
21 their 100644 $(git rev-parse HEAD:ONE) ONE
26 test_cmp expected actual
29 test_expect_success
'file add !A, B' '
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 &&
33 test_must_be_empty actual
36 test_expect_success
'file add A, B (same)' '
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 &&
42 test_must_be_empty actual
45 test_expect_success
'file add A, B (different)' '
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 &&
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
63 test_cmp expected actual
66 test_expect_success
'file change A, !B' '
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 &&
70 test_must_be_empty actual
73 test_expect_success
'file change !A, B' '
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 &&
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
86 test_cmp expected actual
89 test_expect_success
'file change A, B (same)' '
90 git reset --hard initial &&
91 test_commit "change-a-b-same-A" "initial-file" "AAA" &&
92 git reset --hard initial &&
93 test_commit "change-a-b-same-B" "initial-file" "AAA" &&
94 git merge-tree initial change-a-b-same-A change-a-b-same-B >actual &&
95 test_must_be_empty actual
98 test_expect_success
'file change A, B (different)' '
99 git reset --hard initial &&
100 test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
101 git reset --hard initial &&
102 test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
103 git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
104 cat >expected <<EXPECTED &&
106 base 100644 $(git rev-parse initial:initial-file ) initial-file
107 our 100644 $(git rev-parse change-a-b-diff-A:initial-file) initial-file
108 their 100644 $(git rev-parse change-a-b-diff-B:initial-file) initial-file
117 test_cmp expected actual
120 test_expect_success
'file change A, B (mixed)' '
121 git reset --hard initial &&
122 test_commit "change-a-b-mix-base" "ONE" "
138 test_commit "change-a-b-mix-A" "ONE" \
139 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" &&
140 git reset --hard change-a-b-mix-base &&
141 test_commit "change-a-b-mix-B" "ONE" \
142 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" &&
143 git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \
146 cat >expected <<EXPECTED &&
148 base 100644 $(git rev-parse change-a-b-mix-base:ONE) ONE
149 our 100644 $(git rev-parse change-a-b-mix-A:ONE ) ONE
150 their 100644 $(git rev-parse change-a-b-mix-B:ONE ) ONE
165 test_cmp expected actual
168 test_expect_success
'file remove A, !B' '
169 git reset --hard initial &&
170 test_commit "rm-a-not-b-base" "ONE" "AAA" &&
172 git commit -m "rm-a-not-b" &&
173 git tag "rm-a-not-b" &&
174 git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual &&
175 test_must_be_empty actual
178 test_expect_success
'file remove !A, B' '
179 git reset --hard initial &&
180 test_commit "rm-not-a-b-base" "ONE" "AAA" &&
182 git commit -m "rm-not-a-b" &&
183 git tag "rm-not-a-b" &&
184 git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual &&
185 cat >expected <<EXPECTED &&
187 base 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE
188 our 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE
193 test_cmp expected actual
196 test_expect_success
'file remove A, B (same)' '
197 git reset --hard initial &&
198 test_commit "rm-a-b-base" "ONE" "AAA" &&
200 git commit -m "rm-a-b" &&
202 git merge-tree rm-a-b-base rm-a-b rm-a-b >actual &&
203 test_must_be_empty actual
206 test_expect_success
'file change A, remove B' '
207 git reset --hard initial &&
208 test_commit "change-a-rm-b-base" "ONE" "AAA" &&
209 test_commit "change-a-rm-b-A" "ONE" "BBB" &&
210 git reset --hard change-a-rm-b-base &&
212 git commit -m "change-a-rm-b-B" &&
213 git tag "change-a-rm-b-B" &&
214 git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \
216 cat >expected <<EXPECTED &&
218 base 100644 $(git rev-parse change-a-rm-b-base:ONE) ONE
219 our 100644 $(git rev-parse change-a-rm-b-A:ONE ) ONE
224 test_cmp expected actual
227 test_expect_success
'file remove A, change B' '
228 git reset --hard initial &&
229 test_commit "rm-a-change-b-base" "ONE" "AAA" &&
232 git commit -m "rm-a-change-b-A" &&
233 git tag "rm-a-change-b-A" &&
234 git reset --hard rm-a-change-b-base &&
235 test_commit "rm-a-change-b-B" "ONE" "BBB" &&
236 git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \
238 cat >expected <<EXPECTED &&
240 base 100644 $(git rev-parse rm-a-change-b-base:ONE) ONE
241 their 100644 $(git rev-parse rm-a-change-b-B:ONE ) ONE
243 test_cmp expected actual
246 test_expect_success
'tree add A, B (same)' '
247 git reset --hard initial &&
249 test_commit "add sub/file" "sub/file" "file" add-tree-A &&
250 git merge-tree initial add-tree-A add-tree-A >actual &&
251 test_must_be_empty actual
254 test_expect_success
'tree add A, B (different)' '
255 git reset --hard initial &&
257 test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
258 git reset --hard initial &&
260 test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B &&
261 git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual &&
262 cat >expect <<-EOF &&
264 our 100644 $(git rev-parse add-tree-a-b-A:sub/file) sub/file
265 their 100644 $(git rev-parse add-tree-a-b-B:sub/file) sub/file
273 test_cmp expect actual
276 test_expect_success
'tree unchanged A, removed B' '
277 git reset --hard initial &&
279 test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
282 git commit -m "remove sub/file" &&
283 git tag tree-remove-b-B &&
284 git merge-tree tree-remove-b-initial tree-remove-b-initial tree-remove-b-B >actual &&
285 cat >expect <<-EOF &&
287 base 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file
288 our 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file
292 test_cmp expect actual
295 test_expect_success
'turn file to tree' '
296 git reset --hard initial &&
298 mkdir initial-file &&
299 test_commit "turn-file-to-tree" "initial-file/ONE" "CCC" &&
300 git merge-tree initial initial turn-file-to-tree >actual &&
301 cat >expect <<-EOF &&
303 their 100644 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE
307 base 100644 $(git rev-parse initial:initial-file) initial-file
308 our 100644 $(git rev-parse initial:initial-file) initial-file
312 test_cmp expect actual
315 test_expect_success
'turn tree to file' '
316 git reset --hard initial &&
318 test_commit "add-tree" "dir/path" "AAA" &&
319 test_commit "add-another-tree" "dir/another" "BBB" &&
321 test_commit "make-file" "dir" "CCC" &&
322 git merge-tree add-tree add-another-tree make-file >actual &&
323 cat >expect <<-EOF &&
325 base 100644 $(git rev-parse add-tree:dir/path) dir/path
326 our 100644 $(git rev-parse add-tree:dir/path) dir/path
330 their 100644 $(git rev-parse make-file:dir) dir
334 test_cmp expect actual