Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t3311-notes-merge-fanout.sh
blob5b675417e9bbf9d21cac561473c90622b08def5a
1 #!/bin/sh
3 # Copyright (c) 2010 Johan Herland
6 test_description='Test notes merging at various fanout levels'
8 . ./test-lib.sh
10 verify_notes () {
11 notes_ref="$1"
12 commit="$2"
13 if test -f "expect_notes_$notes_ref"
14 then
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" ||
18 return 1
19 fi &&
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"
25 verify_fanout () {
26 notes_ref="$1"
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" |
30 while read path
32 echo "$path" | grep "^../[0-9a-f]*$" || {
33 echo "Invalid path \"$path\"" &&
34 return 1;
36 done
39 verify_no_fanout () {
40 notes_ref="$1"
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" |
44 while read path
46 echo "$path" | grep -v "^../.*" || {
47 echo "Invalid path \"$path\"" &&
48 return 1;
50 done
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 &&
56 for i in 1 2 3 4 5
58 test_commit "commit$i" >/dev/null &&
59 git notes add -m "notes for commit$i" || return 1
60 done &&
62 git log --format=oneline &&
64 test_oid_cache <<-EOF
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
80 EOF
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
95 EOF
97 cat >expect_log_x <<EOF
98 $commit_sha5 commit5
99 notes for commit5
101 $commit_sha4 commit4
102 notes for commit4
104 $commit_sha3 commit3
105 notes for commit3
107 $commit_sha2 commit2
108 notes for commit2
110 $commit_sha1 commit1
111 notes for commit1
115 test_expect_success 'sanity check (x)' '
116 verify_notes x commit5 &&
117 verify_no_fanout x
120 num=300
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)) &&
128 i=0 &&
129 while test $i -lt $((num - 5))
131 git notes add -m "notes for commit$i" HEAD~$i || return 1
132 i=$((i + 1))
133 done &&
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 &&
147 git notes merge x &&
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 &&
153 git notes merge y &&
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
164 $commit_sha5 commit5
166 $commit_sha4 commit4
168 $commit_sha3 commit3
169 notes for commit3
171 appended notes for commit3
173 $commit_sha2 commit2
174 new notes for commit2
176 $commit_sha1 commit1
177 notes for commit1
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 &&
198 git notes merge y &&
199 verify_notes m commit5 &&
200 # x/y/z unchanged
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
209 $commit_sha5 commit5
211 $commit_sha4 commit4
212 other notes for commit4
214 $commit_sha3 commit3
215 other notes for commit3
217 $commit_sha2 commit2
218 notes for commit2
220 $commit_sha1 commit1
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
236 $commit_sha5 commit5
238 $commit_sha4 commit4
239 other notes for commit4
241 $commit_sha3 commit3
242 other notes for commit3
244 $commit_sha2 commit2
245 new notes for commit2
247 $commit_sha1 commit1
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 &&
257 # w/x/y/z unchanged
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
267 $commit_sha5 commit5
269 $commit_sha4 commit4
271 $commit_sha3 commit3
272 notes for commit3
274 appended notes for commit3
276 $commit_sha2 commit2
277 new notes for commit2
279 $commit_sha1 commit1
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 &&
288 # w/x/y/z unchanged
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
298 $commit_sha5 commit5
300 $commit_sha4 commit4
301 other notes for commit4
303 $commit_sha3 commit3
304 other notes for commit3
306 notes for commit3
308 appended notes for commit3
310 $commit_sha2 commit2
311 new notes for commit2
313 $commit_sha1 commit1
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 &&
322 # w/x/y/z unchanged
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
332 $commit_sha5 commit5
334 $commit_sha4 commit4
335 other notes for commit4
337 $commit_sha3 commit3
338 appended notes for commit3
339 notes for commit3
340 other notes for commit3
342 $commit_sha2 commit2
343 new notes for commit2
345 $commit_sha1 commit1
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 &&
354 # w/x/y/z unchanged
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
381 $commit_sha3
382 $commit_sha4
385 cat >expect_conflict_$commit_sha3 <<EOF
386 <<<<<<< refs/notes/m
387 other notes for commit3
388 =======
389 notes for commit3
391 appended notes for commit3
392 >>>>>>> refs/notes/z
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" ||
404 exit 1
405 done ) &&
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
411 $commit_sha5 commit5
413 $commit_sha4 commit4
414 other notes for commit4
416 $commit_sha3 commit3
417 other notes for commit3
419 appended notes for commit3
421 $commit_sha2 commit2
422 new notes for commit2
424 $commit_sha1 commit1
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 &&
437 # w/x/y/z unchanged
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'
446 test_done