]>
Commit | Line | Data |
---|---|---|
809f38c8 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010 Johan Herland | |
4 | # | |
5 | ||
6 | test_description='Test notes merging with manual conflict resolution' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | # Set up a notes merge scenario with different kinds of conflicts | |
11 | test_expect_success 'setup commits' ' | |
12 | test_commit 1st && | |
13 | test_commit 2nd && | |
14 | test_commit 3rd && | |
15 | test_commit 4th && | |
07877f39 | 16 | test_commit 5th && |
17 | ||
18 | test_oid_cache <<-EOF | |
19 | hash04a sha1:6e8e3febca3c2bb896704335cc4d0c34cb2f8715 | |
20 | hash03a sha1:e5388c10860456ee60673025345fe2e153eb8cf8 | |
21 | hash02a sha1:ceefa674873670e7ecd131814d909723cce2b669 | |
22 | hash04b sha1:e2bfd06a37dd2031684a59a6e2b033e212239c78 | |
23 | hash03b sha1:5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 | |
24 | hash01b sha1:b0a6021ec006d07e80e9b20ec9b444cbd9d560d3 | |
25 | hash04c sha1:cff59c793c20bb49a4e01bc06fb06bad642e0d54 | |
26 | hash02c sha1:283b48219aee9a4105f6cab337e789065c82c2b9 | |
27 | hash01c sha1:0a81da8956346e19bcb27a906f04af327e03e31b | |
28 | hash04d sha1:00494adecf2d9635a02fa431308d67993f853968 | |
29 | hash01e sha1:f75d1df88cbfe4258d49852f26cfc83f2ad4494b | |
30 | hash04f sha1:021faa20e931fb48986ffc6282b4bb05553ac946 | |
31 | hash01f sha1:0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 | |
32 | hash05g sha1:304dfb4325cf243025b9957486eb605a9b51c199 | |
33 | ||
34 | hash04a sha256:f18a935e65866345098b3b754071dbf9f3aa3520eb27a7b036b278c5e2f1ed7e | |
35 | hash03a sha256:713035dc94067a64e5fa6e4e1821b7c3bde49a77c7cb3f80eaadefa1ca41b3d2 | |
36 | hash02a sha256:f160a67e048b6fa75bec3952184154045076692cf5dccd3da21e3fd34b7a3f0f | |
37 | hash04b sha256:c7fba0d6104917fbf35258f40b9fa4fc697cfa992deecd1570a3b08d0a5587a9 | |
38 | hash03b sha256:7287a2d78a3766c181b08df38951d784b08b72a44f571ed6d855bd0be22c70f6 | |
39 | hash01b sha256:da96cf778c15d0a2bb76f98b2a62f6c9c01730fa7030e8f08ef0191048e7d620 | |
40 | hash04c sha256:cb615d2def4b834d5f55b2351df97dc92bee4f5009d285201427f349081c8aca | |
41 | hash02c sha256:63bb527e0b4e1c8e1dd0d54dd778ca7c3718689fd6e37c473044cfbcf1cacfdb | |
42 | hash01c sha256:5b87237ac1fbae0246256fed9f9a1f077c4140fb7e6444925f8dbfa5ae406cd8 | |
43 | hash04d sha256:eeddc9f9f6cb3d6b39b861659853f10891dc373e0b6eecb09e03e39b6ce64714 | |
44 | hash01e sha256:108f521b1a74c2e6d0b52a4eda87e09162bf847f7d190cfce496ee1af0b29a5a | |
45 | hash04f sha256:901acda0454502b3bbd281f130c419e6c8de78afcf72a8def8d45ad31462bce4 | |
46 | hash01f sha256:a2d99d1b8bf23c8af7d9d91368454adc110dfd5cc068a4cebb486ee8f5a1e16c | |
47 | hash05g sha256:4fef015b01da8efe929a68e3bb9b8fbad81f53995f097befe8ebc93f12ab98ec | |
48 | EOF | |
809f38c8 JH |
49 | ' |
50 | ||
51 | commit_sha1=$(git rev-parse 1st^{commit}) | |
52 | commit_sha2=$(git rev-parse 2nd^{commit}) | |
53 | commit_sha3=$(git rev-parse 3rd^{commit}) | |
54 | commit_sha4=$(git rev-parse 4th^{commit}) | |
55 | commit_sha5=$(git rev-parse 5th^{commit}) | |
56 | ||
57 | verify_notes () { | |
58 | notes_ref="$1" | |
59 | git -c core.notesRef="refs/notes/$notes_ref" notes | | |
60 | sort >"output_notes_$notes_ref" && | |
61 | test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" && | |
62 | git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \ | |
63 | >"output_log_$notes_ref" && | |
64 | test_cmp "expect_log_$notes_ref" "output_log_$notes_ref" | |
65 | } | |
66 | ||
86ce6e0d DL |
67 | notes_merge_files_gone () { |
68 | # No .git/NOTES_MERGE_* files left | |
69 | { ls .git/NOTES_MERGE_* >output || :; } && | |
70 | test_must_be_empty output | |
71 | } | |
72 | ||
809f38c8 | 73 | cat <<EOF | sort >expect_notes_x |
07877f39 | 74 | $(test_oid hash04a) $commit_sha4 |
75 | $(test_oid hash03a) $commit_sha3 | |
76 | $(test_oid hash02a) $commit_sha2 | |
809f38c8 JH |
77 | EOF |
78 | ||
79 | cat >expect_log_x <<EOF | |
80 | $commit_sha5 5th | |
81 | ||
82 | $commit_sha4 4th | |
83 | x notes on 4th commit | |
84 | ||
85 | $commit_sha3 3rd | |
86 | x notes on 3rd commit | |
87 | ||
88 | $commit_sha2 2nd | |
89 | x notes on 2nd commit | |
90 | ||
91 | $commit_sha1 1st | |
92 | ||
93 | EOF | |
94 | ||
95 | test_expect_success 'setup merge base (x)' ' | |
96 | git config core.notesRef refs/notes/x && | |
97 | git notes add -m "x notes on 2nd commit" 2nd && | |
98 | git notes add -m "x notes on 3rd commit" 3rd && | |
99 | git notes add -m "x notes on 4th commit" 4th && | |
100 | verify_notes x | |
101 | ' | |
102 | ||
103 | cat <<EOF | sort >expect_notes_y | |
07877f39 | 104 | $(test_oid hash04b) $commit_sha4 |
105 | $(test_oid hash03b) $commit_sha3 | |
106 | $(test_oid hash01b) $commit_sha1 | |
809f38c8 JH |
107 | EOF |
108 | ||
109 | cat >expect_log_y <<EOF | |
110 | $commit_sha5 5th | |
111 | ||
112 | $commit_sha4 4th | |
113 | y notes on 4th commit | |
114 | ||
115 | $commit_sha3 3rd | |
116 | y notes on 3rd commit | |
117 | ||
118 | $commit_sha2 2nd | |
119 | ||
120 | $commit_sha1 1st | |
121 | y notes on 1st commit | |
122 | ||
123 | EOF | |
124 | ||
125 | test_expect_success 'setup local branch (y)' ' | |
126 | git update-ref refs/notes/y refs/notes/x && | |
127 | git config core.notesRef refs/notes/y && | |
128 | git notes add -f -m "y notes on 1st commit" 1st && | |
129 | git notes remove 2nd && | |
130 | git notes add -f -m "y notes on 3rd commit" 3rd && | |
131 | git notes add -f -m "y notes on 4th commit" 4th && | |
132 | verify_notes y | |
133 | ' | |
134 | ||
135 | cat <<EOF | sort >expect_notes_z | |
07877f39 | 136 | $(test_oid hash04c) $commit_sha4 |
137 | $(test_oid hash02c) $commit_sha2 | |
138 | $(test_oid hash01c) $commit_sha1 | |
809f38c8 JH |
139 | EOF |
140 | ||
141 | cat >expect_log_z <<EOF | |
142 | $commit_sha5 5th | |
143 | ||
144 | $commit_sha4 4th | |
145 | z notes on 4th commit | |
146 | ||
147 | $commit_sha3 3rd | |
148 | ||
149 | $commit_sha2 2nd | |
150 | z notes on 2nd commit | |
151 | ||
152 | $commit_sha1 1st | |
153 | z notes on 1st commit | |
154 | ||
155 | EOF | |
156 | ||
157 | test_expect_success 'setup remote branch (z)' ' | |
158 | git update-ref refs/notes/z refs/notes/x && | |
159 | git config core.notesRef refs/notes/z && | |
160 | git notes add -f -m "z notes on 1st commit" 1st && | |
161 | git notes add -f -m "z notes on 2nd commit" 2nd && | |
162 | git notes remove 3rd && | |
163 | git notes add -f -m "z notes on 4th commit" 4th && | |
164 | verify_notes z | |
165 | ' | |
166 | ||
167 | # At this point, before merging z into y, we have the following status: | |
168 | # | |
169 | # commit | base/x | local/y | remote/z | diff from x to y/z | |
170 | # -------|---------|---------|----------|--------------------------- | |
171 | # 1st | [none] | b0a6021 | 0a81da8 | added / added (diff) | |
172 | # 2nd | ceefa67 | [none] | 283b482 | removed / changed | |
173 | # 3rd | e5388c1 | 5772f42 | [none] | changed / removed | |
174 | # 4th | 6e8e3fe | e2bfd06 | cff59c7 | changed / changed (diff) | |
175 | # 5th | [none] | [none] | [none] | [none] | |
176 | ||
177 | cat <<EOF | sort >expect_conflicts | |
178 | $commit_sha1 | |
179 | $commit_sha2 | |
180 | $commit_sha3 | |
181 | $commit_sha4 | |
182 | EOF | |
183 | ||
184 | cat >expect_conflict_$commit_sha1 <<EOF | |
185 | <<<<<<< refs/notes/m | |
186 | y notes on 1st commit | |
187 | ======= | |
188 | z notes on 1st commit | |
189 | >>>>>>> refs/notes/z | |
190 | EOF | |
191 | ||
192 | cat >expect_conflict_$commit_sha2 <<EOF | |
193 | z notes on 2nd commit | |
194 | EOF | |
195 | ||
196 | cat >expect_conflict_$commit_sha3 <<EOF | |
197 | y notes on 3rd commit | |
198 | EOF | |
199 | ||
200 | cat >expect_conflict_$commit_sha4 <<EOF | |
201 | <<<<<<< refs/notes/m | |
202 | y notes on 4th commit | |
203 | ======= | |
204 | z notes on 4th commit | |
205 | >>>>>>> refs/notes/z | |
206 | EOF | |
207 | ||
208 | cp expect_notes_y expect_notes_m | |
209 | cp expect_log_y expect_log_m | |
210 | ||
211 | git rev-parse refs/notes/y > pre_merge_y | |
6abb3655 | 212 | git rev-parse refs/notes/z > pre_merge_z |
809f38c8 JH |
213 | |
214 | test_expect_success 'merge z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' | |
215 | git update-ref refs/notes/m refs/notes/y && | |
216 | git config core.notesRef refs/notes/m && | |
89b9e31d | 217 | test_must_fail git notes merge z >output 2>&1 && |
809f38c8 | 218 | # Output should point to where to resolve conflicts |
6789275d | 219 | test_grep "\\.git/NOTES_MERGE_WORKTREE" output && |
809f38c8 JH |
220 | # Inspect merge conflicts |
221 | ls .git/NOTES_MERGE_WORKTREE >output_conflicts && | |
222 | test_cmp expect_conflicts output_conflicts && | |
223 | ( for f in $(cat expect_conflicts); do | |
224 | test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || | |
225 | exit 1 | |
226 | done ) && | |
227 | # Verify that current notes tree (pre-merge) has not changed (m == y) | |
228 | verify_notes y && | |
229 | verify_notes m && | |
230 | test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" | |
231 | ' | |
232 | ||
233 | cat <<EOF | sort >expect_notes_z | |
07877f39 | 234 | $(test_oid hash04d) $commit_sha4 |
235 | $(test_oid hash02c) $commit_sha2 | |
236 | $(test_oid hash01c) $commit_sha1 | |
809f38c8 JH |
237 | EOF |
238 | ||
239 | cat >expect_log_z <<EOF | |
240 | $commit_sha5 5th | |
241 | ||
242 | $commit_sha4 4th | |
243 | z notes on 4th commit | |
244 | ||
245 | More z notes on 4th commit | |
246 | ||
247 | $commit_sha3 3rd | |
248 | ||
249 | $commit_sha2 2nd | |
250 | z notes on 2nd commit | |
251 | ||
252 | $commit_sha1 1st | |
253 | z notes on 1st commit | |
254 | ||
255 | EOF | |
256 | ||
257 | test_expect_success 'change notes in z' ' | |
258 | git notes --ref z append -m "More z notes on 4th commit" 4th && | |
259 | verify_notes z | |
260 | ' | |
261 | ||
262 | test_expect_success 'cannot do merge w/conflicts when previous merge is unfinished' ' | |
263 | test -d .git/NOTES_MERGE_WORKTREE && | |
264 | test_must_fail git notes merge z >output 2>&1 && | |
265 | # Output should indicate what is wrong | |
6789275d | 266 | test_grep -q "\\.git/NOTES_MERGE_\\* exists" output |
809f38c8 JH |
267 | ' |
268 | ||
269 | # Setup non-conflicting merge between x and new notes ref w | |
270 | ||
271 | cat <<EOF | sort >expect_notes_w | |
07877f39 | 272 | $(test_oid hash02a) $commit_sha2 |
273 | $(test_oid hash01e) $commit_sha1 | |
809f38c8 JH |
274 | EOF |
275 | ||
276 | cat >expect_log_w <<EOF | |
277 | $commit_sha5 5th | |
278 | ||
279 | $commit_sha4 4th | |
280 | ||
281 | $commit_sha3 3rd | |
282 | ||
283 | $commit_sha2 2nd | |
284 | x notes on 2nd commit | |
285 | ||
286 | $commit_sha1 1st | |
287 | w notes on 1st commit | |
288 | ||
289 | EOF | |
290 | ||
291 | test_expect_success 'setup unrelated notes ref (w)' ' | |
292 | git config core.notesRef refs/notes/w && | |
293 | git notes add -m "w notes on 1st commit" 1st && | |
294 | git notes add -m "x notes on 2nd commit" 2nd && | |
295 | verify_notes w | |
296 | ' | |
297 | ||
298 | cat <<EOF | sort >expect_notes_w | |
07877f39 | 299 | $(test_oid hash04a) $commit_sha4 |
300 | $(test_oid hash03a) $commit_sha3 | |
301 | $(test_oid hash02a) $commit_sha2 | |
302 | $(test_oid hash01e) $commit_sha1 | |
809f38c8 JH |
303 | EOF |
304 | ||
305 | cat >expect_log_w <<EOF | |
306 | $commit_sha5 5th | |
307 | ||
308 | $commit_sha4 4th | |
309 | x notes on 4th commit | |
310 | ||
311 | $commit_sha3 3rd | |
312 | x notes on 3rd commit | |
313 | ||
314 | $commit_sha2 2nd | |
315 | x notes on 2nd commit | |
316 | ||
317 | $commit_sha1 1st | |
318 | w notes on 1st commit | |
319 | ||
320 | EOF | |
321 | ||
322 | test_expect_success 'can do merge without conflicts even if previous merge is unfinished (x => w)' ' | |
323 | test -d .git/NOTES_MERGE_WORKTREE && | |
324 | git notes merge x && | |
325 | verify_notes w && | |
326 | # Verify that other notes refs has not changed (x and y) | |
327 | verify_notes x && | |
328 | verify_notes y | |
329 | ' | |
330 | ||
6abb3655 | 331 | cat <<EOF | sort >expect_notes_m |
07877f39 | 332 | $(test_oid hash04f) $commit_sha4 |
333 | $(test_oid hash03b) $commit_sha3 | |
334 | $(test_oid hash02c) $commit_sha2 | |
335 | $(test_oid hash01f) $commit_sha1 | |
6abb3655 JH |
336 | EOF |
337 | ||
338 | cat >expect_log_m <<EOF | |
339 | $commit_sha5 5th | |
340 | ||
341 | $commit_sha4 4th | |
342 | y and z notes on 4th commit | |
343 | ||
344 | $commit_sha3 3rd | |
345 | y notes on 3rd commit | |
346 | ||
347 | $commit_sha2 2nd | |
348 | z notes on 2nd commit | |
349 | ||
350 | $commit_sha1 1st | |
351 | y and z notes on 1st commit | |
352 | ||
353 | EOF | |
354 | ||
11dd2b2e JK |
355 | test_expect_success 'do not allow mixing --commit and --abort' ' |
356 | test_must_fail git notes merge --commit --abort | |
357 | ' | |
358 | ||
359 | test_expect_success 'do not allow mixing --commit and --strategy' ' | |
360 | test_must_fail git notes merge --commit --strategy theirs | |
361 | ' | |
362 | ||
363 | test_expect_success 'do not allow mixing --abort and --strategy' ' | |
364 | test_must_fail git notes merge --abort --strategy theirs | |
365 | ' | |
366 | ||
6abb3655 JH |
367 | test_expect_success 'finalize conflicting merge (z => m)' ' |
368 | # Resolve conflicts and finalize merge | |
369 | cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF && | |
370 | y and z notes on 1st commit | |
371 | EOF | |
372 | cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF && | |
373 | y and z notes on 4th commit | |
374 | EOF | |
375 | git notes merge --commit && | |
86ce6e0d | 376 | notes_merge_files_gone && |
6abb3655 JH |
377 | # Merge commit has pre-merge y and pre-merge z as parents |
378 | test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && | |
379 | test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" && | |
380 | # Merge commit mentions the notes refs merged | |
381 | git log -1 --format=%B refs/notes/m > merge_commit_msg && | |
382 | grep -q refs/notes/m merge_commit_msg && | |
383 | grep -q refs/notes/z merge_commit_msg && | |
443259cf JH |
384 | # Merge commit mentions conflicting notes |
385 | grep -q "Conflicts" merge_commit_msg && | |
386 | ( for sha1 in $(cat expect_conflicts); do | |
387 | grep -q "$sha1" merge_commit_msg || | |
388 | exit 1 | |
389 | done ) && | |
6abb3655 JH |
390 | # Verify contents of merge result |
391 | verify_notes m && | |
392 | # Verify that other notes refs has not changed (w, x, y and z) | |
393 | verify_notes w && | |
394 | verify_notes x && | |
395 | verify_notes y && | |
396 | verify_notes z | |
397 | ' | |
398 | ||
399 | cat >expect_conflict_$commit_sha4 <<EOF | |
400 | <<<<<<< refs/notes/m | |
401 | y notes on 4th commit | |
402 | ======= | |
403 | z notes on 4th commit | |
404 | ||
405 | More z notes on 4th commit | |
406 | >>>>>>> refs/notes/z | |
407 | EOF | |
408 | ||
409 | cp expect_notes_y expect_notes_m | |
410 | cp expect_log_y expect_log_m | |
411 | ||
412 | git rev-parse refs/notes/y > pre_merge_y | |
413 | git rev-parse refs/notes/z > pre_merge_z | |
414 | ||
415 | test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' | |
416 | git update-ref refs/notes/m refs/notes/y && | |
417 | git config core.notesRef refs/notes/m && | |
89b9e31d | 418 | test_must_fail git notes merge z >output 2>&1 && |
6abb3655 | 419 | # Output should point to where to resolve conflicts |
6789275d | 420 | test_grep "\\.git/NOTES_MERGE_WORKTREE" output && |
6abb3655 JH |
421 | # Inspect merge conflicts |
422 | ls .git/NOTES_MERGE_WORKTREE >output_conflicts && | |
423 | test_cmp expect_conflicts output_conflicts && | |
424 | ( for f in $(cat expect_conflicts); do | |
425 | test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || | |
426 | exit 1 | |
427 | done ) && | |
428 | # Verify that current notes tree (pre-merge) has not changed (m == y) | |
429 | verify_notes y && | |
430 | verify_notes m && | |
431 | test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" | |
432 | ' | |
433 | ||
434 | test_expect_success 'abort notes merge' ' | |
435 | git notes merge --abort && | |
86ce6e0d | 436 | notes_merge_files_gone && |
6abb3655 | 437 | # m has not moved (still == y) |
02380389 | 438 | test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" && |
6abb3655 JH |
439 | # Verify that other notes refs has not changed (w, x, y and z) |
440 | verify_notes w && | |
441 | verify_notes x && | |
442 | verify_notes y && | |
443 | verify_notes z | |
444 | ' | |
445 | ||
446 | git rev-parse refs/notes/y > pre_merge_y | |
447 | git rev-parse refs/notes/z > pre_merge_z | |
448 | ||
449 | test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' | |
89b9e31d | 450 | test_must_fail git notes merge z >output 2>&1 && |
6abb3655 | 451 | # Output should point to where to resolve conflicts |
6789275d | 452 | test_grep "\\.git/NOTES_MERGE_WORKTREE" output && |
6abb3655 JH |
453 | # Inspect merge conflicts |
454 | ls .git/NOTES_MERGE_WORKTREE >output_conflicts && | |
455 | test_cmp expect_conflicts output_conflicts && | |
456 | ( for f in $(cat expect_conflicts); do | |
457 | test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || | |
458 | exit 1 | |
459 | done ) && | |
460 | # Verify that current notes tree (pre-merge) has not changed (m == y) | |
461 | verify_notes y && | |
462 | verify_notes m && | |
463 | test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" | |
464 | ' | |
465 | ||
466 | cat <<EOF | sort >expect_notes_m | |
07877f39 | 467 | $(test_oid hash05g) $commit_sha5 |
468 | $(test_oid hash02c) $commit_sha2 | |
469 | $(test_oid hash01f) $commit_sha1 | |
6abb3655 JH |
470 | EOF |
471 | ||
472 | cat >expect_log_m <<EOF | |
473 | $commit_sha5 5th | |
474 | new note on 5th commit | |
475 | ||
476 | $commit_sha4 4th | |
477 | ||
478 | $commit_sha3 3rd | |
479 | ||
480 | $commit_sha2 2nd | |
481 | z notes on 2nd commit | |
482 | ||
483 | $commit_sha1 1st | |
484 | y and z notes on 1st commit | |
485 | ||
486 | EOF | |
487 | ||
488 | test_expect_success 'add + remove notes in finalized merge (z => m)' ' | |
489 | # Resolve one conflict | |
490 | cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF && | |
491 | y and z notes on 1st commit | |
492 | EOF | |
493 | # Remove another conflict | |
494 | rm .git/NOTES_MERGE_WORKTREE/$commit_sha4 && | |
495 | # Remove a D/F conflict | |
496 | rm .git/NOTES_MERGE_WORKTREE/$commit_sha3 && | |
497 | # Add a new note | |
498 | echo "new note on 5th commit" > .git/NOTES_MERGE_WORKTREE/$commit_sha5 && | |
499 | # Finalize merge | |
500 | git notes merge --commit && | |
86ce6e0d | 501 | notes_merge_files_gone && |
6abb3655 JH |
502 | # Merge commit has pre-merge y and pre-merge z as parents |
503 | test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && | |
504 | test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" && | |
505 | # Merge commit mentions the notes refs merged | |
506 | git log -1 --format=%B refs/notes/m > merge_commit_msg && | |
507 | grep -q refs/notes/m merge_commit_msg && | |
508 | grep -q refs/notes/z merge_commit_msg && | |
443259cf JH |
509 | # Merge commit mentions conflicting notes |
510 | grep -q "Conflicts" merge_commit_msg && | |
511 | ( for sha1 in $(cat expect_conflicts); do | |
512 | grep -q "$sha1" merge_commit_msg || | |
513 | exit 1 | |
514 | done ) && | |
6abb3655 JH |
515 | # Verify contents of merge result |
516 | verify_notes m && | |
517 | # Verify that other notes refs has not changed (w, x, y and z) | |
518 | verify_notes w && | |
519 | verify_notes x && | |
520 | verify_notes y && | |
521 | verify_notes z | |
522 | ' | |
523 | ||
6cfd6a9d JH |
524 | cp expect_notes_y expect_notes_m |
525 | cp expect_log_y expect_log_m | |
526 | ||
527 | test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' | |
528 | git update-ref refs/notes/m refs/notes/y && | |
89b9e31d | 529 | test_must_fail git notes merge z >output 2>&1 && |
6cfd6a9d | 530 | # Output should point to where to resolve conflicts |
6789275d | 531 | test_grep "\\.git/NOTES_MERGE_WORKTREE" output && |
6cfd6a9d JH |
532 | # Inspect merge conflicts |
533 | ls .git/NOTES_MERGE_WORKTREE >output_conflicts && | |
534 | test_cmp expect_conflicts output_conflicts && | |
535 | ( for f in $(cat expect_conflicts); do | |
536 | test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || | |
537 | exit 1 | |
538 | done ) && | |
539 | # Verify that current notes tree (pre-merge) has not changed (m == y) | |
540 | verify_notes y && | |
541 | verify_notes m && | |
542 | test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" | |
543 | ' | |
544 | ||
545 | cp expect_notes_w expect_notes_m | |
546 | cp expect_log_w expect_log_m | |
547 | ||
548 | test_expect_success 'reset notes ref m to somewhere else (w)' ' | |
549 | git update-ref refs/notes/m refs/notes/w && | |
550 | verify_notes m && | |
551 | test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" | |
552 | ' | |
553 | ||
554 | test_expect_success 'fail to finalize conflicting merge if underlying ref has moved in the meantime (m != NOTES_MERGE_PARTIAL^1)' ' | |
555 | # Resolve conflicts | |
556 | cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF && | |
557 | y and z notes on 1st commit | |
558 | EOF | |
559 | cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF && | |
560 | y and z notes on 4th commit | |
561 | EOF | |
562 | # Fail to finalize merge | |
563 | test_must_fail git notes merge --commit >output 2>&1 && | |
110feb89 PS |
564 | # NOTES_MERGE_* refs and .git/NOTES_MERGE_* state files must remain |
565 | git rev-parse --verify NOTES_MERGE_PARTIAL && | |
566 | git rev-parse --verify NOTES_MERGE_REF && | |
6cfd6a9d JH |
567 | test -f .git/NOTES_MERGE_WORKTREE/$commit_sha1 && |
568 | test -f .git/NOTES_MERGE_WORKTREE/$commit_sha2 && | |
569 | test -f .git/NOTES_MERGE_WORKTREE/$commit_sha3 && | |
570 | test -f .git/NOTES_MERGE_WORKTREE/$commit_sha4 && | |
571 | # Refs are unchanged | |
02380389 RR |
572 | test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" && |
573 | test "$(git rev-parse refs/notes/y)" = "$(git rev-parse NOTES_MERGE_PARTIAL^1)" && | |
574 | test "$(git rev-parse refs/notes/m)" != "$(git rev-parse NOTES_MERGE_PARTIAL^1)" && | |
6cfd6a9d | 575 | # Mention refs/notes/m, and its current and expected value in output |
6789275d JH |
576 | test_grep -q "refs/notes/m" output && |
577 | test_grep -q "$(git rev-parse refs/notes/m)" output && | |
578 | test_grep -q "$(git rev-parse NOTES_MERGE_PARTIAL^1)" output && | |
6cfd6a9d JH |
579 | # Verify that other notes refs has not changed (w, x, y and z) |
580 | verify_notes w && | |
581 | verify_notes x && | |
582 | verify_notes y && | |
583 | verify_notes z | |
584 | ' | |
585 | ||
586 | test_expect_success 'resolve situation by aborting the notes merge' ' | |
587 | git notes merge --abort && | |
86ce6e0d | 588 | notes_merge_files_gone && |
6cfd6a9d | 589 | # m has not moved (still == w) |
02380389 | 590 | test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" && |
6cfd6a9d JH |
591 | # Verify that other notes refs has not changed (w, x, y and z) |
592 | verify_notes w && | |
593 | verify_notes x && | |
594 | verify_notes y && | |
595 | verify_notes z | |
596 | ' | |
597 | ||
01bfec8e JH |
598 | cat >expect_notes <<EOF |
599 | foo | |
600 | bar | |
601 | EOF | |
602 | ||
a0be62c1 | 603 | test_expect_success 'switch cwd before committing notes merge' ' |
01bfec8e JH |
604 | git notes add -m foo HEAD && |
605 | git notes --ref=other add -m bar HEAD && | |
606 | test_must_fail git notes merge refs/notes/other && | |
607 | ( | |
608 | cd .git/NOTES_MERGE_WORKTREE && | |
609 | echo "foo" > $(git rev-parse HEAD) && | |
610 | echo "bar" >> $(git rev-parse HEAD) && | |
611 | git notes merge --commit | |
612 | ) && | |
613 | git notes show HEAD > actual_notes && | |
614 | test_cmp expect_notes actual_notes | |
615 | ' | |
616 | ||
809f38c8 | 617 | test_done |