3 # Copyright (c) 2010 Johan Herland
6 test_description='Test notes merging at various fanout levels'
13 if test -f "expect_notes_$notes_ref"
15 git -c core.notesRef="refs/notes/$notes_ref" notes |
16 sort >"output_notes_$notes_ref" &&
17 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" ||
20 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
21 "$commit" >"output_log_$notes_ref" &&
22 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
27 # Expect entire notes tree to have a fanout == 1
28 git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null &&
29 git ls-tree -r --name-only "refs/notes/$notes_ref" |
33 ??/??????????????????????????????????????)
37 echo "Invalid path \"$path\"" &&
46 # Expect entire notes tree to have a fanout == 0
47 git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null &&
48 git ls-tree -r --name-only "refs/notes/$notes_ref" |
52 ????????????????????????????????????????)
56 echo "Invalid path \"$path\"" &&
63 # Set up a notes merge scenario with different kinds of conflicts
64 test_expect_success 'setup a few initial commits with notes (notes ref: x)' '
65 git config core.notesRef refs/notes/x &&
68 test_commit "commit$i" >/dev/null &&
69 git notes add -m "notes for commit$i" || return 1
73 commit_sha1=$(git rev-parse commit1^{commit})
74 commit_sha2=$(git rev-parse commit2^{commit})
75 commit_sha3=$(git rev-parse commit3^{commit})
76 commit_sha4=$(git rev-parse commit4^{commit})
77 commit_sha5=$(git rev-parse commit5^{commit})
79 cat <<EOF | sort >expect_notes_x
80 aed91155c7a72c2188e781fdf40e0f3761b299db $commit_sha5
81 99fab268f9d7ee7b011e091a436c78def8eeee69 $commit_sha4
82 953c20ae26c7aa0b428c20693fe38bc687f9d1a9 $commit_sha3
83 6358796131b8916eaa2dde6902642942a1cb37e1 $commit_sha2
84 b02d459c32f0e68f2fe0981033bb34f38776ba47 $commit_sha1
87 cat >expect_log_x <<EOF
105 test_expect_success 'sanity check (x)' '
106 verify_notes x commit5 &&
112 cp expect_log_x expect_log_y
114 test_expect_success 'Add a few hundred commits w/notes to trigger fanout (x -> y)' '
115 git update-ref refs/notes/y refs/notes/x &&
116 git config core.notesRef refs/notes/y &&
117 test_commit_bulk --start=6 --id=commit $((num - 5)) &&
119 while test $i -lt $((num - 5))
121 git notes add -m "notes for commit$i" HEAD~$i || return 1
124 test "$(git rev-parse refs/notes/y)" != "$(git rev-parse refs/notes/x)" &&
125 # Expected number of commits and notes
126 test $(git rev-list HEAD | wc -l) = $num &&
127 test $(git notes list | wc -l) = $num &&
128 # 5 first notes unchanged
129 verify_notes y commit5
132 test_expect_success 'notes tree has fanout (y)' 'verify_fanout y'
134 test_expect_success 'No-op merge (already included) (x => y)' '
135 git update-ref refs/notes/m refs/notes/y &&
136 git config core.notesRef refs/notes/m &&
138 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)"
141 test_expect_success 'Fast-forward merge (y => x)' '
142 git update-ref refs/notes/m refs/notes/x &&
144 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)"
147 cat <<EOF | sort >expect_notes_z
148 9f506ee70e20379d7f78204c77b334f43d77410d $commit_sha3
149 23a47d6ea7d589895faf800752054818e1e7627b $commit_sha2
150 b02d459c32f0e68f2fe0981033bb34f38776ba47 $commit_sha1
153 cat >expect_log_z <<EOF
161 appended notes for commit3
164 new notes for commit2
171 test_expect_success 'change some of the initial 5 notes (x -> z)' '
172 git update-ref refs/notes/z refs/notes/x &&
173 git config core.notesRef refs/notes/z &&
174 git notes add -f -m "new notes for commit2" commit2 &&
175 git notes append -m "appended notes for commit3" commit3 &&
176 git notes remove commit4 &&
177 git notes remove commit5 &&
178 verify_notes z commit5
181 test_expect_success 'notes tree has no fanout (z)' 'verify_no_fanout z'
183 cp expect_log_z expect_log_m
185 test_expect_success 'successful merge without conflicts (y => z)' '
186 git update-ref refs/notes/m refs/notes/z &&
187 git config core.notesRef refs/notes/m &&
189 verify_notes m commit5 &&
191 verify_notes x commit5 &&
192 verify_notes y commit5 &&
193 verify_notes z commit5
196 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
198 cat >expect_log_w <<EOF
202 other notes for commit4
205 other notes for commit3
211 other notes for commit1
215 test_expect_success 'introduce conflicting changes (y -> w)' '
216 git update-ref refs/notes/w refs/notes/y &&
217 git config core.notesRef refs/notes/w &&
218 git notes add -f -m "other notes for commit1" commit1 &&
219 git notes add -f -m "other notes for commit3" commit3 &&
220 git notes add -f -m "other notes for commit4" commit4 &&
221 git notes remove commit5 &&
222 verify_notes w commit5
225 cat >expect_log_m <<EOF
229 other notes for commit4
232 other notes for commit3
235 new notes for commit2
238 other notes for commit1
242 test_expect_success 'successful merge using "ours" strategy (z => w)' '
243 git update-ref refs/notes/m refs/notes/w &&
244 git config core.notesRef refs/notes/m &&
245 git notes merge -s ours z &&
246 verify_notes m commit5 &&
248 verify_notes w commit5 &&
249 verify_notes x commit5 &&
250 verify_notes y commit5 &&
251 verify_notes z commit5
254 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
256 cat >expect_log_m <<EOF
264 appended notes for commit3
267 new notes for commit2
270 other notes for commit1
274 test_expect_success 'successful merge using "theirs" strategy (z => w)' '
275 git update-ref refs/notes/m refs/notes/w &&
276 git notes merge -s theirs z &&
277 verify_notes m commit5 &&
279 verify_notes w commit5 &&
280 verify_notes x commit5 &&
281 verify_notes y commit5 &&
282 verify_notes z commit5
285 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
287 cat >expect_log_m <<EOF
291 other notes for commit4
294 other notes for commit3
298 appended notes for commit3
301 new notes for commit2
304 other notes for commit1
308 test_expect_success 'successful merge using "union" strategy (z => w)' '
309 git update-ref refs/notes/m refs/notes/w &&
310 git notes merge -s union z &&
311 verify_notes m commit5 &&
313 verify_notes w commit5 &&
314 verify_notes x commit5 &&
315 verify_notes y commit5 &&
316 verify_notes z commit5
319 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
321 cat >expect_log_m <<EOF
325 other notes for commit4
328 appended notes for commit3
330 other notes for commit3
333 new notes for commit2
336 other notes for commit1
340 test_expect_success 'successful merge using "cat_sort_uniq" strategy (z => w)' '
341 git update-ref refs/notes/m refs/notes/w &&
342 git notes merge -s cat_sort_uniq z &&
343 verify_notes m commit5 &&
345 verify_notes w commit5 &&
346 verify_notes x commit5 &&
347 verify_notes y commit5 &&
348 verify_notes z commit5
351 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
353 # We're merging z into w. Here are the conflicts we expect:
355 # commit | x -> w | x -> z | conflict?
356 # -------|-----------|-----------|----------
357 # 1 | changed | unchanged | no, use w
358 # 2 | unchanged | changed | no, use z
359 # 3 | changed | changed | yes (w, then z in conflict markers)
360 # 4 | changed | deleted | yes (w)
361 # 5 | deleted | deleted | no, deleted
363 test_expect_success 'fails to merge using "manual" strategy (z => w)' '
364 git update-ref refs/notes/m refs/notes/w &&
365 test_must_fail git notes merge z
368 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
370 cat <<EOF | sort >expect_conflicts
375 cat >expect_conflict_$commit_sha3 <<EOF
377 other notes for commit3
381 appended notes for commit3
385 cat >expect_conflict_$commit_sha4 <<EOF
386 other notes for commit4
389 test_expect_success 'verify conflict entries (with no fanout)' '
390 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
391 test_cmp expect_conflicts output_conflicts &&
392 ( for f in $(cat expect_conflicts); do
393 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
396 # Verify that current notes tree (pre-merge) has not changed (m == w)
397 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
400 cat >expect_log_m <<EOF
404 other notes for commit4
407 other notes for commit3
409 appended notes for commit3
412 new notes for commit2
415 other notes for commit1
419 test_expect_success 'resolve and finalize merge (z => w)' '
420 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha3 <<EOF &&
421 other notes for commit3
423 appended notes for commit3
425 git notes merge --commit &&
426 verify_notes m commit5 &&
428 verify_notes w commit5 &&
429 verify_notes x commit5 &&
430 verify_notes y commit5 &&
431 verify_notes z commit5
434 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'