t7800: improve test descriptions with empty arguments
[alt-git.git] / t / t4300-merge-tree.sh
blob9c197260d5bbf54d3ad578c27f54e278d88ab97b
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 '3-way merge with --attr-source' '
90 test_when_finished rm -rf 3-way &&
91 git init 3-way &&
93 cd 3-way &&
94 test_commit initial file1 foo &&
95 base=$(git rev-parse HEAD) &&
96 git checkout -b brancha &&
97 echo bar >>file1 &&
98 git commit -am "adding bar" &&
99 source=$(git rev-parse HEAD) &&
100 git checkout @{-1} &&
101 git checkout -b branchb &&
102 echo baz >>file1 &&
103 git commit -am "adding baz" &&
104 merge=$(git rev-parse HEAD) &&
105 git checkout -b gitattributes &&
106 test_commit "gitattributes" .gitattributes "file1 merge=union" &&
107 git checkout @{-1} &&
108 tree=$(git --attr-source=gitattributes merge-tree --write-tree \
109 --merge-base "$base" --end-of-options "$source" "$merge") &&
110 test_write_lines foo bar baz >expect &&
111 git cat-file -p "$tree:file1" >actual &&
112 test_cmp expect actual
116 test_expect_success 'file change A, B (same)' '
117 git reset --hard initial &&
118 test_commit "change-a-b-same-A" "initial-file" "AAA" &&
119 git reset --hard initial &&
120 test_commit "change-a-b-same-B" "initial-file" "AAA" &&
121 git merge-tree initial change-a-b-same-A change-a-b-same-B >actual &&
122 test_must_be_empty actual
125 test_expect_success 'file change A, B (different)' '
126 git reset --hard initial &&
127 test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
128 git reset --hard initial &&
129 test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
130 git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
131 cat >expected <<EXPECTED &&
132 changed in both
133 base 100644 $(git rev-parse initial:initial-file ) initial-file
134 our 100644 $(git rev-parse change-a-b-diff-A:initial-file) initial-file
135 their 100644 $(git rev-parse change-a-b-diff-B:initial-file) initial-file
136 @@ -1 +1,5 @@
137 +<<<<<<< .our
139 +=======
140 +BBB
141 +>>>>>>> .their
142 EXPECTED
144 test_cmp expected actual
147 test_expect_success 'file change A, B (mixed)' '
148 git reset --hard initial &&
149 test_commit "change-a-b-mix-base" "ONE" "
164 AAA" &&
165 test_commit "change-a-b-mix-A" "ONE" \
166 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/BBB/;}" <ONE)" &&
167 git reset --hard change-a-b-mix-base &&
168 test_commit "change-a-b-mix-B" "ONE" \
169 "$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" &&
170 git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \
171 >actual &&
173 cat >expected <<EXPECTED &&
174 changed in both
175 base 100644 $(git rev-parse change-a-b-mix-base:ONE) ONE
176 our 100644 $(git rev-parse change-a-b-mix-A:ONE ) ONE
177 their 100644 $(git rev-parse change-a-b-mix-B:ONE ) ONE
178 @@ -7,7 +7,11 @@
182 +<<<<<<< .our
184 +=======
185 +CCC
186 +>>>>>>> .their
190 EXPECTED
192 test_cmp expected actual
195 test_expect_success 'file remove A, !B' '
196 git reset --hard initial &&
197 test_commit "rm-a-not-b-base" "ONE" "AAA" &&
198 git rm ONE &&
199 git commit -m "rm-a-not-b" &&
200 git tag "rm-a-not-b" &&
201 git merge-tree rm-a-not-b-base rm-a-not-b rm-a-not-b-base >actual &&
202 test_must_be_empty actual
205 test_expect_success 'file remove !A, B' '
206 git reset --hard initial &&
207 test_commit "rm-not-a-b-base" "ONE" "AAA" &&
208 git rm ONE &&
209 git commit -m "rm-not-a-b" &&
210 git tag "rm-not-a-b" &&
211 git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual &&
212 cat >expected <<EXPECTED &&
213 removed in remote
214 base 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE
215 our 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE
216 @@ -1 +0,0 @@
217 -AAA
218 EXPECTED
220 test_cmp expected actual
223 test_expect_success 'file remove A, B (same)' '
224 git reset --hard initial &&
225 test_commit "rm-a-b-base" "ONE" "AAA" &&
226 git rm ONE &&
227 git commit -m "rm-a-b" &&
228 git tag "rm-a-b" &&
229 git merge-tree rm-a-b-base rm-a-b rm-a-b >actual &&
230 test_must_be_empty actual
233 test_expect_success 'file change A, remove B' '
234 git reset --hard initial &&
235 test_commit "change-a-rm-b-base" "ONE" "AAA" &&
236 test_commit "change-a-rm-b-A" "ONE" "BBB" &&
237 git reset --hard change-a-rm-b-base &&
238 git rm ONE &&
239 git commit -m "change-a-rm-b-B" &&
240 git tag "change-a-rm-b-B" &&
241 git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \
242 >actual &&
243 cat >expected <<EXPECTED &&
244 removed in remote
245 base 100644 $(git rev-parse change-a-rm-b-base:ONE) ONE
246 our 100644 $(git rev-parse change-a-rm-b-A:ONE ) ONE
247 @@ -1 +0,0 @@
248 -BBB
249 EXPECTED
251 test_cmp expected actual
254 test_expect_success 'file remove A, change B' '
255 git reset --hard initial &&
256 test_commit "rm-a-change-b-base" "ONE" "AAA" &&
258 git rm ONE &&
259 git commit -m "rm-a-change-b-A" &&
260 git tag "rm-a-change-b-A" &&
261 git reset --hard rm-a-change-b-base &&
262 test_commit "rm-a-change-b-B" "ONE" "BBB" &&
263 git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \
264 >actual &&
265 cat >expected <<EXPECTED &&
266 removed in local
267 base 100644 $(git rev-parse rm-a-change-b-base:ONE) ONE
268 their 100644 $(git rev-parse rm-a-change-b-B:ONE ) ONE
269 EXPECTED
270 test_cmp expected actual
273 test_expect_success 'tree add A, B (same)' '
274 git reset --hard initial &&
275 mkdir sub &&
276 test_commit "add sub/file" "sub/file" "file" add-tree-A &&
277 git merge-tree initial add-tree-A add-tree-A >actual &&
278 test_must_be_empty actual
281 test_expect_success 'tree add A, B (different)' '
282 git reset --hard initial &&
283 mkdir sub &&
284 test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
285 git reset --hard initial &&
286 mkdir sub &&
287 test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B &&
288 git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual &&
289 cat >expect <<-EOF &&
290 added in both
291 our 100644 $(git rev-parse add-tree-a-b-A:sub/file) sub/file
292 their 100644 $(git rev-parse add-tree-a-b-B:sub/file) sub/file
293 @@ -1 +1,5 @@
294 +<<<<<<< .our
296 +=======
297 +BBB
298 +>>>>>>> .their
300 test_cmp expect actual
303 test_expect_success 'tree unchanged A, removed B' '
304 git reset --hard initial &&
305 mkdir sub &&
306 test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
307 git rm sub/file &&
308 test_tick &&
309 git commit -m "remove sub/file" &&
310 git tag tree-remove-b-B &&
311 git merge-tree tree-remove-b-initial tree-remove-b-initial tree-remove-b-B >actual &&
312 cat >expect <<-EOF &&
313 removed in remote
314 base 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file
315 our 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file
316 @@ -1 +0,0 @@
317 -AAA
319 test_cmp expect actual
322 test_expect_success 'turn file to tree' '
323 git reset --hard initial &&
324 rm initial-file &&
325 mkdir initial-file &&
326 test_commit "turn-file-to-tree" "initial-file/ONE" "CCC" &&
327 git merge-tree initial initial turn-file-to-tree >actual &&
328 cat >expect <<-EOF &&
329 added in remote
330 their 100644 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE
331 @@ -0,0 +1 @@
332 +CCC
333 removed in remote
334 base 100644 $(git rev-parse initial:initial-file) initial-file
335 our 100644 $(git rev-parse initial:initial-file) initial-file
336 @@ -1 +0,0 @@
337 -initial
339 test_cmp expect actual
342 test_expect_success 'turn tree to file' '
343 git reset --hard initial &&
344 mkdir dir &&
345 test_commit "add-tree" "dir/path" "AAA" &&
346 test_commit "add-another-tree" "dir/another" "BBB" &&
347 rm -fr dir &&
348 test_commit "make-file" "dir" "CCC" &&
349 git merge-tree add-tree add-another-tree make-file >actual &&
350 cat >expect <<-EOF &&
351 removed in remote
352 base 100644 $(git rev-parse add-tree:dir/path) dir/path
353 our 100644 $(git rev-parse add-tree:dir/path) dir/path
354 @@ -1 +0,0 @@
355 -AAA
356 added in remote
357 their 100644 $(git rev-parse make-file:dir) dir
358 @@ -0,0 +1 @@
359 +CCC
361 test_cmp expect actual
364 test_expect_success 'merge-tree respects core.useReplaceRefs=false' '
365 test_commit merge-to &&
366 test_commit valid base &&
367 git reset --hard HEAD^ &&
368 test_commit malicious base &&
370 test_when_finished "git replace -d $(git rev-parse valid^0)" &&
371 git replace valid^0 malicious^0 &&
373 tree=$(git -c core.useReplaceRefs=true merge-tree --write-tree merge-to valid) &&
374 merged=$(git cat-file -p $tree:base) &&
375 test malicious = $merged &&
377 tree=$(git -c core.useReplaceRefs=false merge-tree --write-tree merge-to valid) &&
378 merged=$(git cat-file -p $tree:base) &&
379 test valid = $merged
382 test_done