test: fix for COLUMNS and bash 5
[git/debian.git] / t / t4300-merge-tree.sh
blobe59601e5fe9b75eda9f4daaa801c1ed6c40d6fc6
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 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 &&
18 added in remote
19 their 100644 $(git rev-parse HEAD:ONE) ONE
20 @@ -0,0 +1 @@
21 +AAA
22 EXPECTED
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 &&
50 added in both
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
53 @@ -1 +1,5 @@
54 +<<<<<<< .our
55 AAA
56 +=======
57 +BBB
58 +>>>>>>> .their
59 EXPECTED
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 &&
76 merged
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
79 @@ -1 +1 @@
80 -initial
81 +BBB
82 EXPECTED
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 &&
103 changed in both
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
107 @@ -1 +1,5 @@
108 +<<<<<<< .our
110 +=======
111 +BBB
112 +>>>>>>> .their
113 EXPECTED
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" "
135 AAA" &&
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 \
142 >actual &&
144 cat >expected <<EXPECTED &&
145 changed in both
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
149 @@ -7,7 +7,11 @@
153 +<<<<<<< .our
155 +=======
156 +CCC
157 +>>>>>>> .their
161 EXPECTED
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" &&
169 git rm ONE &&
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" &&
179 git rm ONE &&
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 &&
184 removed in remote
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
187 @@ -1 +0,0 @@
188 -AAA
189 EXPECTED
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" &&
197 git rm ONE &&
198 git commit -m "rm-a-b" &&
199 git tag "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 &&
209 git rm ONE &&
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 \
213 >actual &&
214 cat >expected <<EXPECTED &&
215 removed in remote
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
218 @@ -1 +0,0 @@
219 -BBB
220 EXPECTED
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" &&
229 git rm ONE &&
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 \
235 >actual &&
236 cat >expected <<EXPECTED &&
237 removed in local
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
240 EXPECTED
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 git reset --hard initial &&
254 mkdir sub &&
255 test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
256 git reset --hard initial &&
257 mkdir sub &&
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 &&
261 added in both
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
264 @@ -1 +1,5 @@
265 +<<<<<<< .our
267 +=======
268 +BBB
269 +>>>>>>> .their
271 test_cmp expect actual
274 test_expect_success 'tree unchanged A, removed B' '
275 git reset --hard initial &&
276 mkdir sub &&
277 test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
278 git rm sub/file &&
279 test_tick &&
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 &&
284 removed in remote
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
287 @@ -1 +0,0 @@
288 -AAA
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 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE
302 @@ -0,0 +1 @@
303 +CCC
304 removed in remote
305 base 100644 $(git rev-parse initial:initial-file) initial-file
306 our 100644 $(git rev-parse initial:initial-file) 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 $(git rev-parse add-tree:dir/path) dir/path
324 our 100644 $(git rev-parse add-tree:dir/path) dir/path
325 @@ -1 +0,0 @@
326 -AAA
327 added in remote
328 their 100644 $(git rev-parse make-file:dir) dir
329 @@ -0,0 +1 @@
330 +CCC
332 test_cmp expect actual
335 test_done