submodule--helper: advise on fatal alternate error
[git.git] / t / t4300-merge-tree.sh
blobd87cc7d9efde9d728825ae84b4a329b720b6d821
1 #!/bin/sh
3 # Copyright (c) 2010 Will Palmer
6 test_description='git merge-tree'
7 . ./test-lib.sh
9 test_expect_success setup '
10 test_commit "initial" "initial-file" "initial"
13 test_expect_success 'file add A, !B' '
14 cat >expected <<\EXPECTED &&
15 added in remote
16 their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
17 @@ -0,0 +1 @@
18 +AAA
19 EXPECTED
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 &&
45 added in both
46 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
47 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
48 @@ -1 +1,5 @@
49 +<<<<<<< .our
50 AAA
51 +=======
52 +BBB
53 +>>>>>>> .their
54 EXPECTED
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 &&
73 merged
74 result 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
75 our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
76 @@ -1 +1 @@
77 -initial
78 +BBB
79 EXPECTED
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 &&
98 changed in both
99 base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
100 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d initial-file
101 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
102 @@ -1 +1,5 @@
103 +<<<<<<< .our
105 +=======
106 +BBB
107 +>>>>>>> .their
108 EXPECTED
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 &&
120 changed in both
121 base 100644 f4f1f998c7776568c4ff38f516d77fef9399b5a7 ONE
122 our 100644 af14c2c3475337c73759d561ef70b59e5c731176 ONE
123 their 100644 372d761493f524d44d59bd24700c3bdf914c973c ONE
124 @@ -7,7 +7,11 @@
128 +<<<<<<< .our
130 +=======
131 +CCC
132 +>>>>>>> .their
136 EXPECTED
138 git reset --hard initial &&
139 test_commit "change-a-b-mix-base" "ONE" "
154 AAA" &&
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 \
161 >actual &&
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" &&
168 git rm ONE &&
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 &&
177 removed in remote
178 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
179 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
180 @@ -1 +0,0 @@
181 -AAA
182 EXPECTED
184 git reset --hard initial &&
185 test_commit "rm-not-a-b-base" "ONE" "AAA" &&
186 git rm ONE &&
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" &&
196 git rm ONE &&
197 git commit -m "rm-a-b" &&
198 git tag "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 &&
205 removed in remote
206 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
207 our 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
208 @@ -1 +0,0 @@
209 -BBB
210 EXPECTED
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 &&
216 git rm ONE &&
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 \
220 >actual &&
221 test_cmp expected actual
224 test_expect_success 'file remove A, change B' '
225 cat >expected <<\EXPECTED &&
226 removed in local
227 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
228 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
229 EXPECTED
231 git reset --hard initial &&
232 test_commit "rm-a-change-b-base" "ONE" "AAA" &&
234 git rm ONE &&
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 \
240 >actual &&
241 test_cmp expected actual
244 test_expect_success 'tree add A, B (same)' '
245 git reset --hard initial &&
246 mkdir sub &&
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 &&
254 added in both
255 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
256 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 sub/file
257 @@ -1 +1,5 @@
258 +<<<<<<< .our
260 +=======
261 +BBB
262 +>>>>>>> .their
264 git reset --hard initial &&
265 mkdir sub &&
266 test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
267 git reset --hard initial &&
268 mkdir sub &&
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 &&
276 removed in remote
277 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
278 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
279 @@ -1 +0,0 @@
280 -AAA
282 git reset --hard initial &&
283 mkdir sub &&
284 test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
285 git rm sub/file &&
286 test_tick &&
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 &&
295 rm initial-file &&
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 &&
300 added in remote
301 their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 initial-file/ONE
302 @@ -0,0 +1 @@
303 +CCC
304 removed in remote
305 base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
306 our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
307 @@ -1 +0,0 @@
308 -initial
310 test_cmp expect actual
313 test_expect_success 'turn tree to file' '
314 git reset --hard initial &&
315 mkdir dir &&
316 test_commit "add-tree" "dir/path" "AAA" &&
317 test_commit "add-another-tree" "dir/another" "BBB" &&
318 rm -fr dir &&
319 test_commit "make-file" "dir" "CCC" &&
320 git merge-tree add-tree add-another-tree make-file >actual &&
321 cat >expect <<-\EOF &&
322 removed in remote
323 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
324 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
325 @@ -1 +0,0 @@
326 -AAA
327 added in remote
328 their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 dir
329 @@ -0,0 +1 @@
330 +CCC
332 test_cmp expect actual
335 test_done