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 git reset --hard initial &&
15 test_commit "add-a-not-b" "ONE" "AAA" &&
16 git merge-tree initial initial add-a-not-b >actual &&
17 cat >expected <<EXPECTED &&
19 their 100644 $(git rev-parse HEAD:ONE) ONE
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 git reset --hard initial &&
45 test_commit "add-a-b-diff-A" "ONE" "AAA" &&
46 git reset --hard initial &&
47 test_commit "add-a-b-diff-B" "ONE" "BBB" &&
48 git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual &&
49 cat >expected <<EXPECTED &&
51 our 100644 $(git rev-parse add-a-b-diff-A:ONE) ONE
52 their 100644 $(git rev-parse add-a-b-diff-B:ONE) ONE
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 git reset --hard initial &&
73 test_commit "change-not-a-b" "initial-file" "BBB" &&
74 git merge-tree initial initial change-not-a-b >actual &&
75 cat >expected <<EXPECTED &&
77 result 100644 $(git rev-parse change-a-not-b:initial-file) initial-file
78 our 100644 $(git rev-parse initial:initial-file ) initial-file
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 git reset --hard initial &&
98 test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
99 git reset --hard initial &&
100 test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
101 git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
102 cat >expected <<EXPECTED &&
104 base 100644 $(git rev-parse initial:initial-file ) initial-file
105 our 100644 $(git rev-parse change-a-b-diff-A:initial-file) initial-file
106 their 100644 $(git rev-parse change-a-b-diff-B:initial-file) initial-file
115 test_cmp expected actual
118 test_expect_success 'file change A, B (mixed)' '
119 git reset --hard initial &&
120 test_commit "change-a-b-mix-base" "ONE" "
136 test_commit "change-a-b-mix-A" "ONE" \
137 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" &&
138 git reset --hard change-a-b-mix-base &&
139 test_commit "change-a-b-mix-B" "ONE" \
140 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" &&
141 git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \
144 cat >expected <<EXPECTED &&
146 base 100644 $(git rev-parse change-a-b-mix-base:ONE) ONE
147 our 100644 $(git rev-parse change-a-b-mix-A:ONE ) ONE
148 their 100644 $(git rev-parse change-a-b-mix-B:ONE ) ONE
163 test_cmp expected actual
166 test_expect_success 'file remove A, !B' '
167 git reset --hard initial &&
168 test_commit "rm-a-not-b-base" "ONE" "AAA" &&
170 git commit -m "rm-a-not-b" &&
171 git tag "rm-a-not-b" &&
172 git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual &&
173 test_must_be_empty actual
176 test_expect_success 'file remove !A, B' '
177 git reset --hard initial &&
178 test_commit "rm-not-a-b-base" "ONE" "AAA" &&
180 git commit -m "rm-not-a-b" &&
181 git tag "rm-not-a-b" &&
182 git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual &&
183 cat >expected <<EXPECTED &&
185 base 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE
186 our 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE
191 test_cmp expected actual
194 test_expect_success 'file remove A, B (same)' '
195 git reset --hard initial &&
196 test_commit "rm-a-b-base" "ONE" "AAA" &&
198 git commit -m "rm-a-b" &&
200 git merge-tree rm-a-b-base rm-a-b rm-a-b >actual &&
201 test_must_be_empty actual
204 test_expect_success 'file change A, remove B' '
205 git reset --hard initial &&
206 test_commit "change-a-rm-b-base" "ONE" "AAA" &&
207 test_commit "change-a-rm-b-A" "ONE" "BBB" &&
208 git reset --hard change-a-rm-b-base &&
210 git commit -m "change-a-rm-b-B" &&
211 git tag "change-a-rm-b-B" &&
212 git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \
214 cat >expected <<EXPECTED &&
216 base 100644 $(git rev-parse change-a-rm-b-base:ONE) ONE
217 our 100644 $(git rev-parse change-a-rm-b-A:ONE ) ONE
222 test_cmp expected actual
225 test_expect_success 'file remove A, change B' '
226 git reset --hard initial &&
227 test_commit "rm-a-change-b-base" "ONE" "AAA" &&
230 git commit -m "rm-a-change-b-A" &&
231 git tag "rm-a-change-b-A" &&
232 git reset --hard rm-a-change-b-base &&
233 test_commit "rm-a-change-b-B" "ONE" "BBB" &&
234 git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \
236 cat >expected <<EXPECTED &&
238 base 100644 $(git rev-parse rm-a-change-b-base:ONE) ONE
239 their 100644 $(git rev-parse rm-a-change-b-B:ONE ) ONE
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 git reset --hard initial &&
255 test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
256 git reset --hard initial &&
258 test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B &&
259 git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual &&
260 cat >expect <<-EOF &&
262 our 100644 $(git rev-parse add-tree-a-b-A:sub/file) sub/file
263 their 100644 $(git rev-parse add-tree-a-b-B:sub/file) sub/file
271 test_cmp expect actual
274 test_expect_success 'tree unchanged A, removed B' '
275 git reset --hard initial &&
277 test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
280 git commit -m "remove sub/file" &&
281 git tag tree-remove-b-B &&
282 git merge-tree tree-remove-b-initial tree-remove-b-initial tree-remove-b-B >actual &&
283 cat >expect <<-EOF &&
285 base 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file
286 our 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file
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 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE
305 base 100644 $(git rev-parse initial:initial-file) initial-file
306 our 100644 $(git rev-parse initial:initial-file) 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 $(git rev-parse add-tree:dir/path) dir/path
324 our 100644 $(git rev-parse add-tree:dir/path) dir/path
328 their 100644 $(git rev-parse make-file:dir) dir
332 test_cmp expect actual