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" |
32 echo "$path" | grep "^../[0-9a-f]*$" || {
33 echo "Invalid path \"$path\"" &&
41 # Expect entire notes tree to have a fanout == 0
42 git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null &&
43 git ls-tree -r --name-only "refs/notes/$notes_ref" |
46 echo "$path" | grep -v "^../.*" || {
47 echo "Invalid path \"$path\"" &&
53 # Set up a notes merge scenario with different kinds of conflicts
54 test_expect_success 'setup a few initial commits with notes (notes ref: x)' '
55 git config core.notesRef refs/notes/x &&
58 test_commit "commit$i" >/dev/null &&
59 git notes add -m "notes for commit$i" || return 1
62 git log --format=oneline &&
65 hash05a sha1:aed91155c7a72c2188e781fdf40e0f3761b299db
66 hash04a sha1:99fab268f9d7ee7b011e091a436c78def8eeee69
67 hash03a sha1:953c20ae26c7aa0b428c20693fe38bc687f9d1a9
68 hash02a sha1:6358796131b8916eaa2dde6902642942a1cb37e1
69 hash01a sha1:b02d459c32f0e68f2fe0981033bb34f38776ba47
70 hash03b sha1:9f506ee70e20379d7f78204c77b334f43d77410d
71 hash02b sha1:23a47d6ea7d589895faf800752054818e1e7627b
73 hash05a sha256:3aae5d26619d96dba93795f66325716e4cbc486884f95a6adee8fb0615a76d12
74 hash04a sha256:07e43dd3d89fe634d3252e253b426aacc7285a995dcdbcf94ac284060a1122cf
75 hash03a sha256:26fb52eaa7f4866bf735254587be7b31209ec10e525912ffd8e8ba549ba892ff
76 hash02a sha256:b57ebdf23634e750dcbc4b9a37991d70f90830d568a0e4529ce9de0a3f8d605c
77 hash01a sha256:377903b1572bd5117087a5518fcb1011b5053cccbc59e3c7c823a8615204173b
78 hash03b sha256:04e7b392fda7c185bfa17c9179b56db732edc2dc2b3bf887308dcaabb717270d
79 hash02b sha256:66099aaaec49a485ed990acadd9a9b81232ea592079964113d8f581ff69ef50b
83 commit_sha1=$(git rev-parse commit1^{commit})
84 commit_sha2=$(git rev-parse commit2^{commit})
85 commit_sha3=$(git rev-parse commit3^{commit})
86 commit_sha4=$(git rev-parse commit4^{commit})
87 commit_sha5=$(git rev-parse commit5^{commit})
89 cat <<EOF | sort >expect_notes_x
90 $(test_oid hash05a) $commit_sha5
91 $(test_oid hash04a) $commit_sha4
92 $(test_oid hash03a) $commit_sha3
93 $(test_oid hash02a) $commit_sha2
94 $(test_oid hash01a) $commit_sha1
97 cat >expect_log_x <<EOF
115 test_expect_success 'sanity check (x)' '
116 verify_notes x commit5 &&
122 cp expect_log_x expect_log_y
124 test_expect_success 'Add a few hundred commits w/notes to trigger fanout (x -> y)' '
125 git update-ref refs/notes/y refs/notes/x &&
126 git config core.notesRef refs/notes/y &&
127 test_commit_bulk --start=6 --id=commit $((num - 5)) &&
129 while test $i -lt $((num - 5))
131 git notes add -m "notes for commit$i" HEAD~$i || return 1
134 test "$(git rev-parse refs/notes/y)" != "$(git rev-parse refs/notes/x)" &&
135 # Expected number of commits and notes
136 test $(git rev-list HEAD | wc -l) = $num &&
137 test $(git notes list | wc -l) = $num &&
138 # 5 first notes unchanged
139 verify_notes y commit5
142 test_expect_success 'notes tree has fanout (y)' 'verify_fanout y'
144 test_expect_success 'No-op merge (already included) (x => y)' '
145 git update-ref refs/notes/m refs/notes/y &&
146 git config core.notesRef refs/notes/m &&
148 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)"
151 test_expect_success 'Fast-forward merge (y => x)' '
152 git update-ref refs/notes/m refs/notes/x &&
154 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)"
157 cat <<EOF | sort >expect_notes_z
158 $(test_oid hash03b) $commit_sha3
159 $(test_oid hash02b) $commit_sha2
160 $(test_oid hash01a) $commit_sha1
163 cat >expect_log_z <<EOF
171 appended notes for commit3
174 new notes for commit2
181 test_expect_success 'change some of the initial 5 notes (x -> z)' '
182 git update-ref refs/notes/z refs/notes/x &&
183 git config core.notesRef refs/notes/z &&
184 git notes add -f -m "new notes for commit2" commit2 &&
185 git notes append -m "appended notes for commit3" commit3 &&
186 git notes remove commit4 &&
187 git notes remove commit5 &&
188 verify_notes z commit5
191 test_expect_success 'notes tree has no fanout (z)' 'verify_no_fanout z'
193 cp expect_log_z expect_log_m
195 test_expect_success 'successful merge without conflicts (y => z)' '
196 git update-ref refs/notes/m refs/notes/z &&
197 git config core.notesRef refs/notes/m &&
199 verify_notes m commit5 &&
201 verify_notes x commit5 &&
202 verify_notes y commit5 &&
203 verify_notes z commit5
206 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
208 cat >expect_log_w <<EOF
212 other notes for commit4
215 other notes for commit3
221 other notes for commit1
225 test_expect_success 'introduce conflicting changes (y -> w)' '
226 git update-ref refs/notes/w refs/notes/y &&
227 git config core.notesRef refs/notes/w &&
228 git notes add -f -m "other notes for commit1" commit1 &&
229 git notes add -f -m "other notes for commit3" commit3 &&
230 git notes add -f -m "other notes for commit4" commit4 &&
231 git notes remove commit5 &&
232 verify_notes w commit5
235 cat >expect_log_m <<EOF
239 other notes for commit4
242 other notes for commit3
245 new notes for commit2
248 other notes for commit1
252 test_expect_success 'successful merge using "ours" strategy (z => w)' '
253 git update-ref refs/notes/m refs/notes/w &&
254 git config core.notesRef refs/notes/m &&
255 git notes merge -s ours z &&
256 verify_notes m commit5 &&
258 verify_notes w commit5 &&
259 verify_notes x commit5 &&
260 verify_notes y commit5 &&
261 verify_notes z commit5
264 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
266 cat >expect_log_m <<EOF
274 appended notes for commit3
277 new notes for commit2
280 other notes for commit1
284 test_expect_success 'successful merge using "theirs" strategy (z => w)' '
285 git update-ref refs/notes/m refs/notes/w &&
286 git notes merge -s theirs z &&
287 verify_notes m commit5 &&
289 verify_notes w commit5 &&
290 verify_notes x commit5 &&
291 verify_notes y commit5 &&
292 verify_notes z commit5
295 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
297 cat >expect_log_m <<EOF
301 other notes for commit4
304 other notes for commit3
308 appended notes for commit3
311 new notes for commit2
314 other notes for commit1
318 test_expect_success 'successful merge using "union" strategy (z => w)' '
319 git update-ref refs/notes/m refs/notes/w &&
320 git notes merge -s union z &&
321 verify_notes m commit5 &&
323 verify_notes w commit5 &&
324 verify_notes x commit5 &&
325 verify_notes y commit5 &&
326 verify_notes z commit5
329 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
331 cat >expect_log_m <<EOF
335 other notes for commit4
338 appended notes for commit3
340 other notes for commit3
343 new notes for commit2
346 other notes for commit1
350 test_expect_success 'successful merge using "cat_sort_uniq" strategy (z => w)' '
351 git update-ref refs/notes/m refs/notes/w &&
352 git notes merge -s cat_sort_uniq z &&
353 verify_notes m commit5 &&
355 verify_notes w commit5 &&
356 verify_notes x commit5 &&
357 verify_notes y commit5 &&
358 verify_notes z commit5
361 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
363 # We're merging z into w. Here are the conflicts we expect:
365 # commit | x -> w | x -> z | conflict?
366 # -------|-----------|-----------|----------
367 # 1 | changed | unchanged | no, use w
368 # 2 | unchanged | changed | no, use z
369 # 3 | changed | changed | yes (w, then z in conflict markers)
370 # 4 | changed | deleted | yes (w)
371 # 5 | deleted | deleted | no, deleted
373 test_expect_success 'fails to merge using "manual" strategy (z => w)' '
374 git update-ref refs/notes/m refs/notes/w &&
375 test_must_fail git notes merge z
378 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
380 cat <<EOF | sort >expect_conflicts
385 cat >expect_conflict_$commit_sha3 <<EOF
387 other notes for commit3
391 appended notes for commit3
395 cat >expect_conflict_$commit_sha4 <<EOF
396 other notes for commit4
399 test_expect_success 'verify conflict entries (with no fanout)' '
400 ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
401 test_cmp expect_conflicts output_conflicts &&
402 ( for f in $(cat expect_conflicts); do
403 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
406 # Verify that current notes tree (pre-merge) has not changed (m == w)
407 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
410 cat >expect_log_m <<EOF
414 other notes for commit4
417 other notes for commit3
419 appended notes for commit3
422 new notes for commit2
425 other notes for commit1
429 test_expect_success 'resolve and finalize merge (z => w)' '
430 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha3 <<EOF &&
431 other notes for commit3
433 appended notes for commit3
435 git notes merge --commit &&
436 verify_notes m commit5 &&
438 verify_notes w commit5 &&
439 verify_notes x commit5 &&
440 verify_notes y commit5 &&
441 verify_notes z commit5
444 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'