Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t3311-notes-merge-fanout.sh
blobce4144db0f24c7bd9ccbbe30575118b565bb4486
1 #!/bin/sh
3 # Copyright (c) 2010 Johan Herland
6 test_description='Test notes merging at various fanout levels'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 verify_notes () {
12 notes_ref="$1"
13 commit="$2"
14 if test -f "expect_notes_$notes_ref"
15 then
16 git -c core.notesRef="refs/notes/$notes_ref" notes |
17 sort >"output_notes_$notes_ref" &&
18 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" ||
19 return 1
20 fi &&
21 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
22 "$commit" >"output_log_$notes_ref" &&
23 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
26 verify_fanout () {
27 notes_ref="$1"
28 # Expect entire notes tree to have a fanout == 1
29 git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null &&
30 git ls-tree -r --name-only "refs/notes/$notes_ref" |
31 while read path
33 echo "$path" | grep "^../[0-9a-f]*$" || {
34 echo "Invalid path \"$path\"" &&
35 return 1;
37 done
40 verify_no_fanout () {
41 notes_ref="$1"
42 # Expect entire notes tree to have a fanout == 0
43 git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null &&
44 git ls-tree -r --name-only "refs/notes/$notes_ref" |
45 while read path
47 echo "$path" | grep -v "^../.*" || {
48 echo "Invalid path \"$path\"" &&
49 return 1;
51 done
54 # Set up a notes merge scenario with different kinds of conflicts
55 test_expect_success 'setup a few initial commits with notes (notes ref: x)' '
56 git config core.notesRef refs/notes/x &&
57 for i in 1 2 3 4 5
59 test_commit "commit$i" >/dev/null &&
60 git notes add -m "notes for commit$i" || return 1
61 done &&
63 git log --format=oneline &&
65 test_oid_cache <<-EOF
66 hash05a sha1:aed91155c7a72c2188e781fdf40e0f3761b299db
67 hash04a sha1:99fab268f9d7ee7b011e091a436c78def8eeee69
68 hash03a sha1:953c20ae26c7aa0b428c20693fe38bc687f9d1a9
69 hash02a sha1:6358796131b8916eaa2dde6902642942a1cb37e1
70 hash01a sha1:b02d459c32f0e68f2fe0981033bb34f38776ba47
71 hash03b sha1:9f506ee70e20379d7f78204c77b334f43d77410d
72 hash02b sha1:23a47d6ea7d589895faf800752054818e1e7627b
74 hash05a sha256:3aae5d26619d96dba93795f66325716e4cbc486884f95a6adee8fb0615a76d12
75 hash04a sha256:07e43dd3d89fe634d3252e253b426aacc7285a995dcdbcf94ac284060a1122cf
76 hash03a sha256:26fb52eaa7f4866bf735254587be7b31209ec10e525912ffd8e8ba549ba892ff
77 hash02a sha256:b57ebdf23634e750dcbc4b9a37991d70f90830d568a0e4529ce9de0a3f8d605c
78 hash01a sha256:377903b1572bd5117087a5518fcb1011b5053cccbc59e3c7c823a8615204173b
79 hash03b sha256:04e7b392fda7c185bfa17c9179b56db732edc2dc2b3bf887308dcaabb717270d
80 hash02b sha256:66099aaaec49a485ed990acadd9a9b81232ea592079964113d8f581ff69ef50b
81 EOF
84 commit_sha1=$(git rev-parse commit1^{commit})
85 commit_sha2=$(git rev-parse commit2^{commit})
86 commit_sha3=$(git rev-parse commit3^{commit})
87 commit_sha4=$(git rev-parse commit4^{commit})
88 commit_sha5=$(git rev-parse commit5^{commit})
90 cat <<EOF | sort >expect_notes_x
91 $(test_oid hash05a) $commit_sha5
92 $(test_oid hash04a) $commit_sha4
93 $(test_oid hash03a) $commit_sha3
94 $(test_oid hash02a) $commit_sha2
95 $(test_oid hash01a) $commit_sha1
96 EOF
98 cat >expect_log_x <<EOF
99 $commit_sha5 commit5
100 notes for commit5
102 $commit_sha4 commit4
103 notes for commit4
105 $commit_sha3 commit3
106 notes for commit3
108 $commit_sha2 commit2
109 notes for commit2
111 $commit_sha1 commit1
112 notes for commit1
116 test_expect_success 'sanity check (x)' '
117 verify_notes x commit5 &&
118 verify_no_fanout x
121 num=300
123 cp expect_log_x expect_log_y
125 test_expect_success 'Add a few hundred commits w/notes to trigger fanout (x -> y)' '
126 git update-ref refs/notes/y refs/notes/x &&
127 git config core.notesRef refs/notes/y &&
128 test_commit_bulk --start=6 --id=commit $((num - 5)) &&
129 i=0 &&
130 while test $i -lt $((num - 5))
132 git notes add -m "notes for commit$i" HEAD~$i || return 1
133 i=$((i + 1))
134 done &&
135 test "$(git rev-parse refs/notes/y)" != "$(git rev-parse refs/notes/x)" &&
136 # Expected number of commits and notes
137 test $(git rev-list HEAD | wc -l) = $num &&
138 test $(git notes list | wc -l) = $num &&
139 # 5 first notes unchanged
140 verify_notes y commit5
143 test_expect_success 'notes tree has fanout (y)' 'verify_fanout y'
145 test_expect_success 'No-op merge (already included) (x => y)' '
146 git update-ref refs/notes/m refs/notes/y &&
147 git config core.notesRef refs/notes/m &&
148 git notes merge x &&
149 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)"
152 test_expect_success 'Fast-forward merge (y => x)' '
153 git update-ref refs/notes/m refs/notes/x &&
154 git notes merge y &&
155 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)"
158 cat <<EOF | sort >expect_notes_z
159 $(test_oid hash03b) $commit_sha3
160 $(test_oid hash02b) $commit_sha2
161 $(test_oid hash01a) $commit_sha1
164 cat >expect_log_z <<EOF
165 $commit_sha5 commit5
167 $commit_sha4 commit4
169 $commit_sha3 commit3
170 notes for commit3
172 appended notes for commit3
174 $commit_sha2 commit2
175 new notes for commit2
177 $commit_sha1 commit1
178 notes for commit1
182 test_expect_success 'change some of the initial 5 notes (x -> z)' '
183 git update-ref refs/notes/z refs/notes/x &&
184 git config core.notesRef refs/notes/z &&
185 git notes add -f -m "new notes for commit2" commit2 &&
186 git notes append -m "appended notes for commit3" commit3 &&
187 git notes remove commit4 &&
188 git notes remove commit5 &&
189 verify_notes z commit5
192 test_expect_success 'notes tree has no fanout (z)' 'verify_no_fanout z'
194 cp expect_log_z expect_log_m
196 test_expect_success 'successful merge without conflicts (y => z)' '
197 git update-ref refs/notes/m refs/notes/z &&
198 git config core.notesRef refs/notes/m &&
199 git notes merge y &&
200 verify_notes m commit5 &&
201 # x/y/z unchanged
202 verify_notes x commit5 &&
203 verify_notes y commit5 &&
204 verify_notes z commit5
207 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
209 cat >expect_log_w <<EOF
210 $commit_sha5 commit5
212 $commit_sha4 commit4
213 other notes for commit4
215 $commit_sha3 commit3
216 other notes for commit3
218 $commit_sha2 commit2
219 notes for commit2
221 $commit_sha1 commit1
222 other notes for commit1
226 test_expect_success 'introduce conflicting changes (y -> w)' '
227 git update-ref refs/notes/w refs/notes/y &&
228 git config core.notesRef refs/notes/w &&
229 git notes add -f -m "other notes for commit1" commit1 &&
230 git notes add -f -m "other notes for commit3" commit3 &&
231 git notes add -f -m "other notes for commit4" commit4 &&
232 git notes remove commit5 &&
233 verify_notes w commit5
236 cat >expect_log_m <<EOF
237 $commit_sha5 commit5
239 $commit_sha4 commit4
240 other notes for commit4
242 $commit_sha3 commit3
243 other notes for commit3
245 $commit_sha2 commit2
246 new notes for commit2
248 $commit_sha1 commit1
249 other notes for commit1
253 test_expect_success 'successful merge using "ours" strategy (z => w)' '
254 git update-ref refs/notes/m refs/notes/w &&
255 git config core.notesRef refs/notes/m &&
256 git notes merge -s ours z &&
257 verify_notes m commit5 &&
258 # w/x/y/z unchanged
259 verify_notes w commit5 &&
260 verify_notes x commit5 &&
261 verify_notes y commit5 &&
262 verify_notes z commit5
265 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
267 cat >expect_log_m <<EOF
268 $commit_sha5 commit5
270 $commit_sha4 commit4
272 $commit_sha3 commit3
273 notes for commit3
275 appended notes for commit3
277 $commit_sha2 commit2
278 new notes for commit2
280 $commit_sha1 commit1
281 other notes for commit1
285 test_expect_success 'successful merge using "theirs" strategy (z => w)' '
286 git update-ref refs/notes/m refs/notes/w &&
287 git notes merge -s theirs z &&
288 verify_notes m commit5 &&
289 # w/x/y/z unchanged
290 verify_notes w commit5 &&
291 verify_notes x commit5 &&
292 verify_notes y commit5 &&
293 verify_notes z commit5
296 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
298 cat >expect_log_m <<EOF
299 $commit_sha5 commit5
301 $commit_sha4 commit4
302 other notes for commit4
304 $commit_sha3 commit3
305 other notes for commit3
307 notes for commit3
309 appended notes for commit3
311 $commit_sha2 commit2
312 new notes for commit2
314 $commit_sha1 commit1
315 other notes for commit1
319 test_expect_success 'successful merge using "union" strategy (z => w)' '
320 git update-ref refs/notes/m refs/notes/w &&
321 git notes merge -s union z &&
322 verify_notes m commit5 &&
323 # w/x/y/z unchanged
324 verify_notes w commit5 &&
325 verify_notes x commit5 &&
326 verify_notes y commit5 &&
327 verify_notes z commit5
330 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
332 cat >expect_log_m <<EOF
333 $commit_sha5 commit5
335 $commit_sha4 commit4
336 other notes for commit4
338 $commit_sha3 commit3
339 appended notes for commit3
340 notes for commit3
341 other notes for commit3
343 $commit_sha2 commit2
344 new notes for commit2
346 $commit_sha1 commit1
347 other notes for commit1
351 test_expect_success 'successful merge using "cat_sort_uniq" strategy (z => w)' '
352 git update-ref refs/notes/m refs/notes/w &&
353 git notes merge -s cat_sort_uniq z &&
354 verify_notes m commit5 &&
355 # w/x/y/z unchanged
356 verify_notes w commit5 &&
357 verify_notes x commit5 &&
358 verify_notes y commit5 &&
359 verify_notes z commit5
362 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
364 # We're merging z into w. Here are the conflicts we expect:
366 # commit | x -> w | x -> z | conflict?
367 # -------|-----------|-----------|----------
368 # 1 | changed | unchanged | no, use w
369 # 2 | unchanged | changed | no, use z
370 # 3 | changed | changed | yes (w, then z in conflict markers)
371 # 4 | changed | deleted | yes (w)
372 # 5 | deleted | deleted | no, deleted
374 test_expect_success 'fails to merge using "manual" strategy (z => w)' '
375 git update-ref refs/notes/m refs/notes/w &&
376 test_must_fail git notes merge z
379 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
381 cat <<EOF | sort >expect_conflicts
382 $commit_sha3
383 $commit_sha4
386 cat >expect_conflict_$commit_sha3 <<EOF
387 <<<<<<< refs/notes/m
388 other notes for commit3
389 =======
390 notes for commit3
392 appended notes for commit3
393 >>>>>>> refs/notes/z
396 cat >expect_conflict_$commit_sha4 <<EOF
397 other notes for commit4
400 test_expect_success 'verify conflict entries (with no fanout)' '
401 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
402 test_cmp expect_conflicts output_conflicts &&
403 ( for f in $(cat expect_conflicts); do
404 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
405 exit 1
406 done ) &&
407 # Verify that current notes tree (pre-merge) has not changed (m == w)
408 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
411 cat >expect_log_m <<EOF
412 $commit_sha5 commit5
414 $commit_sha4 commit4
415 other notes for commit4
417 $commit_sha3 commit3
418 other notes for commit3
420 appended notes for commit3
422 $commit_sha2 commit2
423 new notes for commit2
425 $commit_sha1 commit1
426 other notes for commit1
430 test_expect_success 'resolve and finalize merge (z => w)' '
431 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha3 <<EOF &&
432 other notes for commit3
434 appended notes for commit3
436 git notes merge --commit &&
437 verify_notes m commit5 &&
438 # w/x/y/z unchanged
439 verify_notes w commit5 &&
440 verify_notes x commit5 &&
441 verify_notes y commit5 &&
442 verify_notes z commit5
445 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
447 test_done