]>
Commit | Line | Data |
---|---|---|
f32e9852 WP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010 Will Palmer | |
4 | # | |
5 | ||
6 | test_description='git merge-tree' | |
7 | . ./test-lib.sh | |
8 | ||
9 | test_expect_success setup ' | |
10 | test_commit "initial" "initial-file" "initial" | |
11 | ' | |
12 | ||
13 | test_expect_success 'file add A, !B' ' | |
525a7f17 | 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 && | |
f32e9852 | 18 | added in remote |
525a7f17 | 19 | their 100644 $(git rev-parse HEAD:ONE) ONE |
f32e9852 WP |
20 | @@ -0,0 +1 @@ |
21 | +AAA | |
22 | EXPECTED | |
23 | ||
f32e9852 WP |
24 | test_cmp expected actual |
25 | ' | |
26 | ||
21baa6e0 | 27 | test_expect_success 'file add !A, B' ' |
f32e9852 WP |
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 && | |
1c5e94f4 | 31 | test_must_be_empty actual |
f32e9852 WP |
32 | ' |
33 | ||
34 | test_expect_success 'file add A, B (same)' ' | |
f32e9852 WP |
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 && | |
1c5e94f4 | 40 | test_must_be_empty actual |
f32e9852 WP |
41 | ' |
42 | ||
43 | test_expect_success 'file add A, B (different)' ' | |
525a7f17 | 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 && | |
f32e9852 | 50 | added in both |
525a7f17 | 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 | |
f32e9852 WP |
53 | @@ -1 +1,5 @@ |
54 | +<<<<<<< .our | |
55 | AAA | |
56 | +======= | |
57 | +BBB | |
58 | +>>>>>>> .their | |
59 | EXPECTED | |
60 | ||
f32e9852 WP |
61 | test_cmp expected actual |
62 | ' | |
63 | ||
64 | test_expect_success 'file change A, !B' ' | |
f32e9852 WP |
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 && | |
1c5e94f4 | 68 | test_must_be_empty actual |
f32e9852 WP |
69 | ' |
70 | ||
71 | test_expect_success 'file change !A, B' ' | |
525a7f17 | 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 && | |
f32e9852 | 76 | merged |
525a7f17 | 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 | |
f32e9852 WP |
79 | @@ -1 +1 @@ |
80 | -initial | |
81 | +BBB | |
82 | EXPECTED | |
83 | ||
f32e9852 WP |
84 | test_cmp expected actual |
85 | ' | |
86 | ||
87 | test_expect_success 'file change A, B (same)' ' | |
f32e9852 WP |
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 && | |
1c5e94f4 | 93 | test_must_be_empty actual |
f32e9852 WP |
94 | ' |
95 | ||
96 | test_expect_success 'file change A, B (different)' ' | |
525a7f17 | 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 && | |
f32e9852 | 103 | changed in both |
525a7f17 | 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 | |
f32e9852 WP |
107 | @@ -1 +1,5 @@ |
108 | +<<<<<<< .our | |
109 | AAA | |
110 | +======= | |
111 | +BBB | |
112 | +>>>>>>> .their | |
113 | EXPECTED | |
114 | ||
f32e9852 WP |
115 | test_cmp expected actual |
116 | ' | |
117 | ||
118 | test_expect_success 'file change A, B (mixed)' ' | |
f32e9852 WP |
119 | git reset --hard initial && |
120 | test_commit "change-a-b-mix-base" "ONE" " | |
121 | AAA | |
122 | AAA | |
123 | AAA | |
124 | AAA | |
125 | AAA | |
126 | AAA | |
127 | AAA | |
128 | AAA | |
129 | AAA | |
130 | AAA | |
131 | AAA | |
132 | AAA | |
133 | AAA | |
134 | AAA | |
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 && | |
525a7f17 | 143 | |
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 @@ | |
150 | AAA | |
151 | AAA | |
152 | AAA | |
153 | +<<<<<<< .our | |
154 | BBB | |
155 | +======= | |
156 | +CCC | |
157 | +>>>>>>> .their | |
158 | AAA | |
159 | AAA | |
160 | AAA | |
161 | EXPECTED | |
162 | ||
f32e9852 WP |
163 | test_cmp expected actual |
164 | ' | |
165 | ||
166 | test_expect_success 'file remove A, !B' ' | |
f32e9852 WP |
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 && | |
1c5e94f4 | 173 | test_must_be_empty actual |
f32e9852 WP |
174 | ' |
175 | ||
21baa6e0 | 176 | test_expect_success 'file remove !A, B' ' |
f32e9852 WP |
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 && | |
525a7f17 | 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 | |
190 | ||
f32e9852 WP |
191 | test_cmp expected actual |
192 | ' | |
193 | ||
ab5f4242 | 194 | test_expect_success 'file remove A, B (same)' ' |
ab5f4242 JK |
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 && | |
1c5e94f4 | 201 | test_must_be_empty actual |
ab5f4242 JK |
202 | ' |
203 | ||
21baa6e0 | 204 | test_expect_success 'file change A, remove B' ' |
f32e9852 WP |
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 && | |
525a7f17 | 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 | |
221 | ||
f32e9852 WP |
222 | test_cmp expected actual |
223 | ' | |
224 | ||
225 | test_expect_success 'file remove A, change B' ' | |
f32e9852 WP |
226 | git reset --hard initial && |
227 | test_commit "rm-a-change-b-base" "ONE" "AAA" && | |
228 | ||
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 && | |
525a7f17 | 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 | |
f32e9852 WP |
241 | test_cmp expected actual |
242 | ' | |
243 | ||
94883b43 | 244 | test_expect_success 'tree add A, B (same)' ' |
94883b43 JK |
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 && | |
1c5e94f4 | 249 | test_must_be_empty actual |
94883b43 JK |
250 | ' |
251 | ||
252 | test_expect_success 'tree add A, B (different)' ' | |
525a7f17 | 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 && | |
94883b43 | 261 | added in both |
525a7f17 | 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 | |
94883b43 JK |
264 | @@ -1 +1,5 @@ |
265 | +<<<<<<< .our | |
266 | AAA | |
267 | +======= | |
268 | +BBB | |
269 | +>>>>>>> .their | |
270 | EOF | |
94883b43 JK |
271 | test_cmp expect actual |
272 | ' | |
273 | ||
274 | test_expect_success 'tree unchanged A, removed B' ' | |
94883b43 JK |
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 && | |
525a7f17 | 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 | |
289 | EOF | |
94883b43 JK |
290 | test_cmp expect actual |
291 | ' | |
292 | ||
35ffe758 | 293 | test_expect_success 'turn file to tree' ' |
8dd15c6a JH |
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 && | |
525a7f17 | 299 | cat >expect <<-EOF && |
8dd15c6a | 300 | added in remote |
525a7f17 | 301 | their 100644 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE |
8dd15c6a JH |
302 | @@ -0,0 +1 @@ |
303 | +CCC | |
304 | removed in remote | |
525a7f17 | 305 | base 100644 $(git rev-parse initial:initial-file) initial-file |
306 | our 100644 $(git rev-parse initial:initial-file) initial-file | |
8dd15c6a JH |
307 | @@ -1 +0,0 @@ |
308 | -initial | |
309 | EOF | |
310 | test_cmp expect actual | |
311 | ' | |
312 | ||
35ffe758 | 313 | test_expect_success 'turn tree to file' ' |
8dd15c6a JH |
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 && | |
525a7f17 | 321 | cat >expect <<-EOF && |
8dd15c6a | 322 | removed in remote |
525a7f17 | 323 | base 100644 $(git rev-parse add-tree:dir/path) dir/path |
324 | our 100644 $(git rev-parse add-tree:dir/path) dir/path | |
8dd15c6a JH |
325 | @@ -1 +0,0 @@ |
326 | -AAA | |
327 | added in remote | |
525a7f17 | 328 | their 100644 $(git rev-parse make-file:dir) dir |
8dd15c6a JH |
329 | @@ -0,0 +1 @@ |
330 | +CCC | |
331 | EOF | |
332 | test_cmp expect actual | |
333 | ' | |
334 | ||
f32e9852 | 335 | test_done |