]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3311-notes-merge-fanout.sh
The sixth batch
[thirdparty/git.git] / t / t3311-notes-merge-fanout.sh
CommitLineData
305ddd44
JH
1#!/bin/sh
2#
3# Copyright (c) 2010 Johan Herland
4#
5
6test_description='Test notes merging at various fanout levels'
7
8. ./test-lib.sh
9
10verify_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"
23}
24
25verify_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
31 do
5df0f11f 32 echo "$path" | grep "^../[0-9a-f]*$" || {
305ddd44 33 echo "Invalid path \"$path\"" &&
5df0f11f 34 return 1;
35 }
305ddd44
JH
36 done
37}
38
39verify_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
45 do
5df0f11f 46 echo "$path" | grep -v "^../.*" || {
305ddd44 47 echo "Invalid path \"$path\"" &&
5df0f11f 48 return 1;
49 }
305ddd44
JH
50 done
51}
52
53# Set up a notes merge scenario with different kinds of conflicts
54test_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
57 do
58 test_commit "commit$i" >/dev/null &&
59 git notes add -m "notes for commit$i" || return 1
5df0f11f 60 done &&
61
62 git log --format=oneline &&
63
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
72
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
305ddd44
JH
81'
82
83commit_sha1=$(git rev-parse commit1^{commit})
84commit_sha2=$(git rev-parse commit2^{commit})
85commit_sha3=$(git rev-parse commit3^{commit})
86commit_sha4=$(git rev-parse commit4^{commit})
87commit_sha5=$(git rev-parse commit5^{commit})
88
89cat <<EOF | sort >expect_notes_x
5df0f11f 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
305ddd44
JH
95EOF
96
97cat >expect_log_x <<EOF
98$commit_sha5 commit5
99notes for commit5
100
101$commit_sha4 commit4
102notes for commit4
103
104$commit_sha3 commit3
105notes for commit3
106
107$commit_sha2 commit2
108notes for commit2
109
110$commit_sha1 commit1
111notes for commit1
112
113EOF
114
115test_expect_success 'sanity check (x)' '
116 verify_notes x commit5 &&
117 verify_no_fanout x
118'
119
120num=300
121
122cp expect_log_x expect_log_y
123
124test_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 &&
737b19b5
JK
127 test_commit_bulk --start=6 --id=commit $((num - 5)) &&
128 i=0 &&
129 while test $i -lt $((num - 5))
305ddd44 130 do
737b19b5
JK
131 git notes add -m "notes for commit$i" HEAD~$i || return 1
132 i=$((i + 1))
305ddd44
JH
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
140'
141
142test_expect_success 'notes tree has fanout (y)' 'verify_fanout y'
143
144test_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)"
149'
150
151test_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)"
155'
156
157cat <<EOF | sort >expect_notes_z
5df0f11f 158$(test_oid hash03b) $commit_sha3
159$(test_oid hash02b) $commit_sha2
160$(test_oid hash01a) $commit_sha1
305ddd44
JH
161EOF
162
163cat >expect_log_z <<EOF
164$commit_sha5 commit5
165
166$commit_sha4 commit4
167
168$commit_sha3 commit3
169notes for commit3
170
171appended notes for commit3
172
173$commit_sha2 commit2
174new notes for commit2
175
176$commit_sha1 commit1
177notes for commit1
178
179EOF
180
181test_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
189'
190
191test_expect_success 'notes tree has no fanout (z)' 'verify_no_fanout z'
192
193cp expect_log_z expect_log_m
194
195test_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
204'
205
206test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
207
208cat >expect_log_w <<EOF
209$commit_sha5 commit5
210
211$commit_sha4 commit4
212other notes for commit4
213
214$commit_sha3 commit3
215other notes for commit3
216
217$commit_sha2 commit2
218notes for commit2
219
220$commit_sha1 commit1
221other notes for commit1
222
223EOF
224
225test_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
233'
234
235cat >expect_log_m <<EOF
236$commit_sha5 commit5
237
238$commit_sha4 commit4
239other notes for commit4
240
241$commit_sha3 commit3
242other notes for commit3
243
244$commit_sha2 commit2
245new notes for commit2
246
247$commit_sha1 commit1
248other notes for commit1
249
250EOF
251
252test_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
262'
263
264test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
265
266cat >expect_log_m <<EOF
267$commit_sha5 commit5
268
269$commit_sha4 commit4
270
271$commit_sha3 commit3
272notes for commit3
273
274appended notes for commit3
275
276$commit_sha2 commit2
277new notes for commit2
278
279$commit_sha1 commit1
280other notes for commit1
281
282EOF
283
284test_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
293'
294
295test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
296
297cat >expect_log_m <<EOF
298$commit_sha5 commit5
299
300$commit_sha4 commit4
301other notes for commit4
302
303$commit_sha3 commit3
304other notes for commit3
305
306notes for commit3
307
308appended notes for commit3
309
310$commit_sha2 commit2
311new notes for commit2
312
313$commit_sha1 commit1
314other notes for commit1
315
316EOF
317
318test_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
327'
328
329test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
330
331cat >expect_log_m <<EOF
332$commit_sha5 commit5
333
334$commit_sha4 commit4
335other notes for commit4
336
337$commit_sha3 commit3
338appended notes for commit3
339notes for commit3
340other notes for commit3
341
342$commit_sha2 commit2
343new notes for commit2
344
345$commit_sha1 commit1
346other notes for commit1
347
348EOF
349
350test_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
359'
360
361test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
362
363# We're merging z into w. Here are the conflicts we expect:
364#
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
372
373test_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
376'
377
378test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
379
380cat <<EOF | sort >expect_conflicts
381$commit_sha3
382$commit_sha4
383EOF
384
385cat >expect_conflict_$commit_sha3 <<EOF
386<<<<<<< refs/notes/m
387other notes for commit3
388=======
389notes for commit3
390
391appended notes for commit3
392>>>>>>> refs/notes/z
393EOF
394
395cat >expect_conflict_$commit_sha4 <<EOF
396other notes for commit4
397EOF
398
399test_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)"
408'
409
410cat >expect_log_m <<EOF
411$commit_sha5 commit5
412
413$commit_sha4 commit4
414other notes for commit4
415
416$commit_sha3 commit3
417other notes for commit3
418
419appended notes for commit3
420
421$commit_sha2 commit2
422new notes for commit2
423
424$commit_sha1 commit1
425other notes for commit1
426
427EOF
428
429test_expect_success 'resolve and finalize merge (z => w)' '
430 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha3 <<EOF &&
431other notes for commit3
432
433appended notes for commit3
434EOF
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
442'
443
444test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
445
446test_done