Merge branch 'ph/rebase-original'
[git.git] / t / t4300-merge-tree.sh
blobbd43b3d8ef8b3e71f6985cfa96a940dccb4a0a54
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 cat >expected <<\EXPECTED &&
29 EXPECTED
31 git reset --hard initial &&
32 test_commit "add-not-a-b" "ONE" "AAA" &&
33 git merge-tree initial add-not-a-b initial >actual &&
34 test_cmp expected actual
37 test_expect_success 'file add A, B (same)' '
38 cat >expected <<\EXPECTED &&
39 EXPECTED
41 git reset --hard initial &&
42 test_commit "add-a-b-same-A" "ONE" "AAA" &&
43 git reset --hard initial &&
44 test_commit "add-a-b-same-B" "ONE" "AAA" &&
45 git merge-tree initial add-a-b-same-A add-a-b-same-B >actual &&
46 test_cmp expected actual
49 test_expect_success 'file add A, B (different)' '
50 cat >expected <<\EXPECTED &&
51 added in both
52 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
53 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
54 @@ -1 +1,5 @@
55 +<<<<<<< .our
56 AAA
57 +=======
58 +BBB
59 +>>>>>>> .their
60 EXPECTED
62 git reset --hard initial &&
63 test_commit "add-a-b-diff-A" "ONE" "AAA" &&
64 git reset --hard initial &&
65 test_commit "add-a-b-diff-B" "ONE" "BBB" &&
66 git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual &&
67 test_cmp expected actual
70 test_expect_success 'file change A, !B' '
71 cat >expected <<\EXPECTED &&
72 EXPECTED
74 git reset --hard initial &&
75 test_commit "change-a-not-b" "initial-file" "BBB" &&
76 git merge-tree initial change-a-not-b initial >actual &&
77 test_cmp expected actual
80 test_expect_success 'file change !A, B' '
81 cat >expected <<\EXPECTED &&
82 merged
83 result 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
84 our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
85 @@ -1 +1 @@
86 -initial
87 +BBB
88 EXPECTED
90 git reset --hard initial &&
91 test_commit "change-not-a-b" "initial-file" "BBB" &&
92 git merge-tree initial initial change-not-a-b >actual &&
93 test_cmp expected actual
96 test_expect_success 'file change A, B (same)' '
97 cat >expected <<\EXPECTED &&
98 EXPECTED
100 git reset --hard initial &&
101 test_commit "change-a-b-same-A" "initial-file" "AAA" &&
102 git reset --hard initial &&
103 test_commit "change-a-b-same-B" "initial-file" "AAA" &&
104 git merge-tree initial change-a-b-same-A change-a-b-same-B >actual &&
105 test_cmp expected actual
108 test_expect_success 'file change A, B (different)' '
109 cat >expected <<\EXPECTED &&
110 changed in both
111 base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
112 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d initial-file
113 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
114 @@ -1 +1,5 @@
115 +<<<<<<< .our
117 +=======
118 +BBB
119 +>>>>>>> .their
120 EXPECTED
122 git reset --hard initial &&
123 test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
124 git reset --hard initial &&
125 test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
126 git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
127 test_cmp expected actual
130 test_expect_success 'file change A, B (mixed)' '
131 cat >expected <<\EXPECTED &&
132 changed in both
133 base 100644 f4f1f998c7776568c4ff38f516d77fef9399b5a7 ONE
134 our 100644 af14c2c3475337c73759d561ef70b59e5c731176 ONE
135 their 100644 372d761493f524d44d59bd24700c3bdf914c973c ONE
136 @@ -7,7 +7,11 @@
140 +<<<<<<< .our
142 +=======
143 +CCC
144 +>>>>>>> .their
148 EXPECTED
150 git reset --hard initial &&
151 test_commit "change-a-b-mix-base" "ONE" "
166 AAA" &&
167 test_commit "change-a-b-mix-A" "ONE" \
168 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" &&
169 git reset --hard change-a-b-mix-base &&
170 test_commit "change-a-b-mix-B" "ONE" \
171 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" &&
172 git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \
173 >actual &&
174 test_cmp expected actual
177 test_expect_success 'file remove A, !B' '
178 cat >expected <<\EXPECTED &&
179 EXPECTED
181 git reset --hard initial &&
182 test_commit "rm-a-not-b-base" "ONE" "AAA" &&
183 git rm ONE &&
184 git commit -m "rm-a-not-b" &&
185 git tag "rm-a-not-b" &&
186 git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual &&
187 test_cmp expected actual
190 test_expect_success 'file remove !A, B' '
191 cat >expected <<\EXPECTED &&
192 removed in remote
193 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
194 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
195 @@ -1 +0,0 @@
196 -AAA
197 EXPECTED
199 git reset --hard initial &&
200 test_commit "rm-not-a-b-base" "ONE" "AAA" &&
201 git rm ONE &&
202 git commit -m "rm-not-a-b" &&
203 git tag "rm-not-a-b" &&
204 git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual &&
205 test_cmp expected actual
208 test_expect_success 'file change A, remove B' '
209 cat >expected <<\EXPECTED &&
210 removed in remote
211 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
212 our 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
213 @@ -1 +0,0 @@
214 -BBB
215 EXPECTED
217 git reset --hard initial &&
218 test_commit "change-a-rm-b-base" "ONE" "AAA" &&
219 test_commit "change-a-rm-b-A" "ONE" "BBB" &&
220 git reset --hard change-a-rm-b-base &&
221 git rm ONE &&
222 git commit -m "change-a-rm-b-B" &&
223 git tag "change-a-rm-b-B" &&
224 git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \
225 >actual &&
226 test_cmp expected actual
229 test_expect_success 'file remove A, change B' '
230 cat >expected <<\EXPECTED &&
231 removed in local
232 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
233 their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
234 EXPECTED
236 git reset --hard initial &&
237 test_commit "rm-a-change-b-base" "ONE" "AAA" &&
239 git rm ONE &&
240 git commit -m "rm-a-change-b-A" &&
241 git tag "rm-a-change-b-A" &&
242 git reset --hard rm-a-change-b-base &&
243 test_commit "rm-a-change-b-B" "ONE" "BBB" &&
244 git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \
245 >actual &&
246 test_cmp expected actual
249 test_expect_success 'turn file to tree' '
250 git reset --hard initial &&
251 rm initial-file &&
252 mkdir initial-file &&
253 test_commit "turn-file-to-tree" "initial-file/ONE" "CCC" &&
254 git merge-tree initial initial turn-file-to-tree >actual &&
255 cat >expect <<-\EOF &&
256 added in remote
257 their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 initial-file/ONE
258 @@ -0,0 +1 @@
259 +CCC
260 removed in remote
261 base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
262 our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
263 @@ -1 +0,0 @@
264 -initial
266 test_cmp expect actual
269 test_expect_success 'turn tree to file' '
270 git reset --hard initial &&
271 mkdir dir &&
272 test_commit "add-tree" "dir/path" "AAA" &&
273 test_commit "add-another-tree" "dir/another" "BBB" &&
274 rm -fr dir &&
275 test_commit "make-file" "dir" "CCC" &&
276 git merge-tree add-tree add-another-tree make-file >actual &&
277 cat >expect <<-\EOF &&
278 removed in remote
279 base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
280 our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
281 @@ -1 +0,0 @@
282 -AAA
283 added in remote
284 their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 dir
285 @@ -0,0 +1 @@
286 +CCC
288 test_cmp expect actual
291 test_done