git notes merge: Manual conflict resolution, part 2/2
[git/jrn.git] / t / t3310-notes-merge-manual-resolve.sh
blob0ec315aa9ba2f98fa281104d0d9f214c11aeadab
1 #!/bin/sh
3 # Copyright (c) 2010 Johan Herland
6 test_description='Test notes merging with manual conflict resolution'
8 . ./test-lib.sh
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 &&
16 test_commit 5th
19 commit_sha1=$(git rev-parse 1st^{commit})
20 commit_sha2=$(git rev-parse 2nd^{commit})
21 commit_sha3=$(git rev-parse 3rd^{commit})
22 commit_sha4=$(git rev-parse 4th^{commit})
23 commit_sha5=$(git rev-parse 5th^{commit})
25 verify_notes () {
26 notes_ref="$1"
27 git -c core.notesRef="refs/notes/$notes_ref" notes |
28 sort >"output_notes_$notes_ref" &&
29 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" &&
30 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
31 >"output_log_$notes_ref" &&
32 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
35 cat <<EOF | sort >expect_notes_x
36 6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4
37 e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3
38 ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
39 EOF
41 cat >expect_log_x <<EOF
42 $commit_sha5 5th
44 $commit_sha4 4th
45 x notes on 4th commit
47 $commit_sha3 3rd
48 x notes on 3rd commit
50 $commit_sha2 2nd
51 x notes on 2nd commit
53 $commit_sha1 1st
55 EOF
57 test_expect_success 'setup merge base (x)' '
58 git config core.notesRef refs/notes/x &&
59 git notes add -m "x notes on 2nd commit" 2nd &&
60 git notes add -m "x notes on 3rd commit" 3rd &&
61 git notes add -m "x notes on 4th commit" 4th &&
62 verify_notes x
65 cat <<EOF | sort >expect_notes_y
66 e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
67 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
68 b0a6021ec006d07e80e9b20ec9b444cbd9d560d3 $commit_sha1
69 EOF
71 cat >expect_log_y <<EOF
72 $commit_sha5 5th
74 $commit_sha4 4th
75 y notes on 4th commit
77 $commit_sha3 3rd
78 y notes on 3rd commit
80 $commit_sha2 2nd
82 $commit_sha1 1st
83 y notes on 1st commit
85 EOF
87 test_expect_success 'setup local branch (y)' '
88 git update-ref refs/notes/y refs/notes/x &&
89 git config core.notesRef refs/notes/y &&
90 git notes add -f -m "y notes on 1st commit" 1st &&
91 git notes remove 2nd &&
92 git notes add -f -m "y notes on 3rd commit" 3rd &&
93 git notes add -f -m "y notes on 4th commit" 4th &&
94 verify_notes y
97 cat <<EOF | sort >expect_notes_z
98 cff59c793c20bb49a4e01bc06fb06bad642e0d54 $commit_sha4
99 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
100 0a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1
103 cat >expect_log_z <<EOF
104 $commit_sha5 5th
106 $commit_sha4 4th
107 z notes on 4th commit
109 $commit_sha3 3rd
111 $commit_sha2 2nd
112 z notes on 2nd commit
114 $commit_sha1 1st
115 z notes on 1st commit
119 test_expect_success 'setup remote branch (z)' '
120 git update-ref refs/notes/z refs/notes/x &&
121 git config core.notesRef refs/notes/z &&
122 git notes add -f -m "z notes on 1st commit" 1st &&
123 git notes add -f -m "z notes on 2nd commit" 2nd &&
124 git notes remove 3rd &&
125 git notes add -f -m "z notes on 4th commit" 4th &&
126 verify_notes z
129 # At this point, before merging z into y, we have the following status:
131 # commit | base/x | local/y | remote/z | diff from x to y/z
132 # -------|---------|---------|----------|---------------------------
133 # 1st | [none] | b0a6021 | 0a81da8 | added / added (diff)
134 # 2nd | ceefa67 | [none] | 283b482 | removed / changed
135 # 3rd | e5388c1 | 5772f42 | [none] | changed / removed
136 # 4th | 6e8e3fe | e2bfd06 | cff59c7 | changed / changed (diff)
137 # 5th | [none] | [none] | [none] | [none]
139 cat <<EOF | sort >expect_conflicts
140 $commit_sha1
141 $commit_sha2
142 $commit_sha3
143 $commit_sha4
146 cat >expect_conflict_$commit_sha1 <<EOF
147 <<<<<<< refs/notes/m
148 y notes on 1st commit
149 =======
150 z notes on 1st commit
151 >>>>>>> refs/notes/z
154 cat >expect_conflict_$commit_sha2 <<EOF
155 z notes on 2nd commit
158 cat >expect_conflict_$commit_sha3 <<EOF
159 y notes on 3rd commit
162 cat >expect_conflict_$commit_sha4 <<EOF
163 <<<<<<< refs/notes/m
164 y notes on 4th commit
165 =======
166 z notes on 4th commit
167 >>>>>>> refs/notes/z
170 cp expect_notes_y expect_notes_m
171 cp expect_log_y expect_log_m
173 git rev-parse refs/notes/y > pre_merge_y
174 git rev-parse refs/notes/z > pre_merge_z
176 test_expect_success 'merge z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
177 git update-ref refs/notes/m refs/notes/y &&
178 git config core.notesRef refs/notes/m &&
179 test_must_fail git notes merge z >output &&
180 # Output should point to where to resolve conflicts
181 grep -q "\\.git/NOTES_MERGE_WORKTREE" output &&
182 # Inspect merge conflicts
183 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
184 test_cmp expect_conflicts output_conflicts &&
185 ( for f in $(cat expect_conflicts); do
186 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
187 exit 1
188 done ) &&
189 # Verify that current notes tree (pre-merge) has not changed (m == y)
190 verify_notes y &&
191 verify_notes m &&
192 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
195 cat <<EOF | sort >expect_notes_z
196 00494adecf2d9635a02fa431308d67993f853968 $commit_sha4
197 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
198 0a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1
201 cat >expect_log_z <<EOF
202 $commit_sha5 5th
204 $commit_sha4 4th
205 z notes on 4th commit
207 More z notes on 4th commit
209 $commit_sha3 3rd
211 $commit_sha2 2nd
212 z notes on 2nd commit
214 $commit_sha1 1st
215 z notes on 1st commit
219 test_expect_success 'change notes in z' '
220 git notes --ref z append -m "More z notes on 4th commit" 4th &&
221 verify_notes z
224 test_expect_success 'cannot do merge w/conflicts when previous merge is unfinished' '
225 test -d .git/NOTES_MERGE_WORKTREE &&
226 test_must_fail git notes merge z >output 2>&1 &&
227 # Output should indicate what is wrong
228 grep -q "\\.git/NOTES_MERGE_\\* exists" output
231 # Setup non-conflicting merge between x and new notes ref w
233 cat <<EOF | sort >expect_notes_w
234 ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
235 f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1
238 cat >expect_log_w <<EOF
239 $commit_sha5 5th
241 $commit_sha4 4th
243 $commit_sha3 3rd
245 $commit_sha2 2nd
246 x notes on 2nd commit
248 $commit_sha1 1st
249 w notes on 1st commit
253 test_expect_success 'setup unrelated notes ref (w)' '
254 git config core.notesRef refs/notes/w &&
255 git notes add -m "w notes on 1st commit" 1st &&
256 git notes add -m "x notes on 2nd commit" 2nd &&
257 verify_notes w
260 cat <<EOF | sort >expect_notes_w
261 6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4
262 e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3
263 ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
264 f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1
267 cat >expect_log_w <<EOF
268 $commit_sha5 5th
270 $commit_sha4 4th
271 x notes on 4th commit
273 $commit_sha3 3rd
274 x notes on 3rd commit
276 $commit_sha2 2nd
277 x notes on 2nd commit
279 $commit_sha1 1st
280 w notes on 1st commit
284 test_expect_success 'can do merge without conflicts even if previous merge is unfinished (x => w)' '
285 test -d .git/NOTES_MERGE_WORKTREE &&
286 git notes merge x &&
287 verify_notes w &&
288 # Verify that other notes refs has not changed (x and y)
289 verify_notes x &&
290 verify_notes y
293 cat <<EOF | sort >expect_notes_m
294 021faa20e931fb48986ffc6282b4bb05553ac946 $commit_sha4
295 5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
296 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
297 0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 $commit_sha1
300 cat >expect_log_m <<EOF
301 $commit_sha5 5th
303 $commit_sha4 4th
304 y and z notes on 4th commit
306 $commit_sha3 3rd
307 y notes on 3rd commit
309 $commit_sha2 2nd
310 z notes on 2nd commit
312 $commit_sha1 1st
313 y and z notes on 1st commit
317 test_expect_success 'finalize conflicting merge (z => m)' '
318 # Resolve conflicts and finalize merge
319 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
320 y and z notes on 1st commit
322 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF &&
323 y and z notes on 4th commit
325 git notes merge --commit &&
326 # No .git/NOTES_MERGE_* files left
327 test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
328 test_cmp /dev/null output &&
329 # Merge commit has pre-merge y and pre-merge z as parents
330 test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" &&
331 test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" &&
332 # Merge commit mentions the notes refs merged
333 git log -1 --format=%B refs/notes/m > merge_commit_msg &&
334 grep -q refs/notes/m merge_commit_msg &&
335 grep -q refs/notes/z merge_commit_msg &&
336 # Verify contents of merge result
337 verify_notes m &&
338 # Verify that other notes refs has not changed (w, x, y and z)
339 verify_notes w &&
340 verify_notes x &&
341 verify_notes y &&
342 verify_notes z
345 cat >expect_conflict_$commit_sha4 <<EOF
346 <<<<<<< refs/notes/m
347 y notes on 4th commit
348 =======
349 z notes on 4th commit
351 More z notes on 4th commit
352 >>>>>>> refs/notes/z
355 cp expect_notes_y expect_notes_m
356 cp expect_log_y expect_log_m
358 git rev-parse refs/notes/y > pre_merge_y
359 git rev-parse refs/notes/z > pre_merge_z
361 test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
362 git update-ref refs/notes/m refs/notes/y &&
363 git config core.notesRef refs/notes/m &&
364 test_must_fail git notes merge z >output &&
365 # Output should point to where to resolve conflicts
366 grep -q "\\.git/NOTES_MERGE_WORKTREE" output &&
367 # Inspect merge conflicts
368 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
369 test_cmp expect_conflicts output_conflicts &&
370 ( for f in $(cat expect_conflicts); do
371 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
372 exit 1
373 done ) &&
374 # Verify that current notes tree (pre-merge) has not changed (m == y)
375 verify_notes y &&
376 verify_notes m &&
377 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
380 test_expect_success 'abort notes merge' '
381 git notes merge --abort &&
382 # No .git/NOTES_MERGE_* files left
383 test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
384 test_cmp /dev/null output &&
385 # m has not moved (still == y)
386 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
387 # Verify that other notes refs has not changed (w, x, y and z)
388 verify_notes w &&
389 verify_notes x &&
390 verify_notes y &&
391 verify_notes z
394 git rev-parse refs/notes/y > pre_merge_y
395 git rev-parse refs/notes/z > pre_merge_z
397 test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
398 test_must_fail git notes merge z >output &&
399 # Output should point to where to resolve conflicts
400 grep -q "\\.git/NOTES_MERGE_WORKTREE" output &&
401 # Inspect merge conflicts
402 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
403 test_cmp expect_conflicts output_conflicts &&
404 ( for f in $(cat expect_conflicts); do
405 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
406 exit 1
407 done ) &&
408 # Verify that current notes tree (pre-merge) has not changed (m == y)
409 verify_notes y &&
410 verify_notes m &&
411 test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
414 cat <<EOF | sort >expect_notes_m
415 304dfb4325cf243025b9957486eb605a9b51c199 $commit_sha5
416 283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
417 0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 $commit_sha1
420 cat >expect_log_m <<EOF
421 $commit_sha5 5th
422 new note on 5th commit
424 $commit_sha4 4th
426 $commit_sha3 3rd
428 $commit_sha2 2nd
429 z notes on 2nd commit
431 $commit_sha1 1st
432 y and z notes on 1st commit
436 test_expect_success 'add + remove notes in finalized merge (z => m)' '
437 # Resolve one conflict
438 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF &&
439 y and z notes on 1st commit
441 # Remove another conflict
442 rm .git/NOTES_MERGE_WORKTREE/$commit_sha4 &&
443 # Remove a D/F conflict
444 rm .git/NOTES_MERGE_WORKTREE/$commit_sha3 &&
445 # Add a new note
446 echo "new note on 5th commit" > .git/NOTES_MERGE_WORKTREE/$commit_sha5 &&
447 # Finalize merge
448 git notes merge --commit &&
449 # No .git/NOTES_MERGE_* files left
450 test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null &&
451 test_cmp /dev/null output &&
452 # Merge commit has pre-merge y and pre-merge z as parents
453 test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" &&
454 test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" &&
455 # Merge commit mentions the notes refs merged
456 git log -1 --format=%B refs/notes/m > merge_commit_msg &&
457 grep -q refs/notes/m merge_commit_msg &&
458 grep -q refs/notes/z merge_commit_msg &&
459 # Verify contents of merge result
460 verify_notes m &&
461 # Verify that other notes refs has not changed (w, x, y and z)
462 verify_notes w &&
463 verify_notes x &&
464 verify_notes y &&
465 verify_notes z
468 test_done