Merge branch 'main' of github.com:git/git
[alt-git.git] / t / t4300-merge-tree.sh
blobc52c8a21fae6d0593cc120485e8d6eaa8a95ccbc
1 #!/bin/sh
3 # Copyright (c) 2010 Will Palmer
6 test_description='git merge-tree'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
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 &&
20 added in remote
21 their 100644 $(git rev-parse HEAD:ONE) ONE
22 @@ -0,0 +1 @@
23 +AAA
24 EXPECTED
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 &&
52 added in both
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
55 @@ -1 +1,5 @@
56 +<<<<<<< .our
57 AAA
58 +=======
59 +BBB
60 +>>>>>>> .their
61 EXPECTED
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 &&
78 merged
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
81 @@ -1 +1 @@
82 -initial
83 +BBB
84 EXPECTED
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 &&
105 changed in both
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
109 @@ -1 +1,5 @@
110 +<<<<<<< .our
112 +=======
113 +BBB
114 +>>>>>>> .their
115 EXPECTED
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" "
137 AAA" &&
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 \
144 >actual &&
146 cat >expected <<EXPECTED &&
147 changed in both
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
151 @@ -7,7 +7,11 @@
155 +<<<<<<< .our
157 +=======
158 +CCC
159 +>>>>>>> .their
163 EXPECTED
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" &&
171 git rm ONE &&
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" &&
181 git rm ONE &&
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 &&
186 removed in remote
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
189 @@ -1 +0,0 @@
190 -AAA
191 EXPECTED
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" &&
199 git rm ONE &&
200 git commit -m "rm-a-b" &&
201 git tag "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 &&
211 git rm ONE &&
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 \
215 >actual &&
216 cat >expected <<EXPECTED &&
217 removed in remote
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
220 @@ -1 +0,0 @@
221 -BBB
222 EXPECTED
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" &&
231 git rm ONE &&
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 \
237 >actual &&
238 cat >expected <<EXPECTED &&
239 removed in local
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
242 EXPECTED
243 test_cmp expected actual
246 test_expect_success 'tree add A, B (same)' '
247 git reset --hard initial &&
248 mkdir sub &&
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 &&
256 mkdir sub &&
257 test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
258 git reset --hard initial &&
259 mkdir sub &&
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 &&
263 added in both
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
266 @@ -1 +1,5 @@
267 +<<<<<<< .our
269 +=======
270 +BBB
271 +>>>>>>> .their
273 test_cmp expect actual
276 test_expect_success 'tree unchanged A, removed B' '
277 git reset --hard initial &&
278 mkdir sub &&
279 test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
280 git rm sub/file &&
281 test_tick &&
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 &&
286 removed in remote
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
289 @@ -1 +0,0 @@
290 -AAA
292 test_cmp expect actual
295 test_expect_success 'turn file to tree' '
296 git reset --hard initial &&
297 rm initial-file &&
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 &&
302 added in remote
303 their 100644 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE
304 @@ -0,0 +1 @@
305 +CCC
306 removed in remote
307 base 100644 $(git rev-parse initial:initial-file) initial-file
308 our 100644 $(git rev-parse initial:initial-file) initial-file
309 @@ -1 +0,0 @@
310 -initial
312 test_cmp expect actual
315 test_expect_success 'turn tree to file' '
316 git reset --hard initial &&
317 mkdir dir &&
318 test_commit "add-tree" "dir/path" "AAA" &&
319 test_commit "add-another-tree" "dir/another" "BBB" &&
320 rm -fr dir &&
321 test_commit "make-file" "dir" "CCC" &&
322 git merge-tree add-tree add-another-tree make-file >actual &&
323 cat >expect <<-EOF &&
324 removed in remote
325 base 100644 $(git rev-parse add-tree:dir/path) dir/path
326 our 100644 $(git rev-parse add-tree:dir/path) dir/path
327 @@ -1 +0,0 @@
328 -AAA
329 added in remote
330 their 100644 $(git rev-parse make-file:dir) dir
331 @@ -0,0 +1 @@
332 +CCC
334 test_cmp expect actual
337 test_done