]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9301-fast-import-notes.sh
parse-options: allow git commands to invent new option types
[thirdparty/git.git] / t / t9301-fast-import-notes.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009 Johan Herland
4 #
5
6 test_description='test git fast-import of notes objects'
7 . ./test-lib.sh
8
9
10 test_tick
11 cat >input <<INPUT_END
12 commit refs/heads/master
13 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
14 data <<COMMIT
15 first commit
16 COMMIT
17
18 M 644 inline foo
19 data <<EOF
20 file foo in first commit
21 EOF
22
23 M 755 inline bar
24 data <<EOF
25 file bar in first commit
26 EOF
27
28 M 644 inline baz/xyzzy
29 data <<EOF
30 file baz/xyzzy in first commit
31 EOF
32
33 commit refs/heads/master
34 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
35 data <<COMMIT
36 second commit
37 COMMIT
38
39 M 644 inline foo
40 data <<EOF
41 file foo in second commit
42 EOF
43
44 M 755 inline baz/xyzzy
45 data <<EOF
46 file baz/xyzzy in second commit
47 EOF
48
49 commit refs/heads/master
50 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
51 data <<COMMIT
52 third commit
53 COMMIT
54
55 M 644 inline foo
56 data <<EOF
57 file foo in third commit
58 EOF
59
60 commit refs/heads/master
61 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
62 data <<COMMIT
63 fourth commit
64 COMMIT
65
66 M 755 inline bar
67 data <<EOF
68 file bar in fourth commit
69 EOF
70
71 INPUT_END
72
73 test_expect_success 'set up master branch' '
74
75 git fast-import <input &&
76 git whatchanged master
77 '
78
79 commit4=$(git rev-parse refs/heads/master)
80 commit3=$(git rev-parse "$commit4^")
81 commit2=$(git rev-parse "$commit4~2")
82 commit1=$(git rev-parse "$commit4~3")
83
84 test_tick
85 cat >input <<INPUT_END
86 commit refs/notes/test
87 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
88 data <<COMMIT
89 first notes commit
90 COMMIT
91
92 M 644 inline $commit1
93 data <<EOF
94 first note for first commit
95 EOF
96
97 M 755 inline $commit2
98 data <<EOF
99 first note for second commit
100 EOF
101
102 INPUT_END
103
104 cat >expect <<EXPECT_END
105 fourth commit
106 third commit
107 second commit
108 first note for second commit
109 first commit
110 first note for first commit
111 EXPECT_END
112
113 test_expect_success 'add notes with simple M command' '
114
115 git fast-import <input &&
116 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
117 test_cmp expect actual
118
119 '
120
121 test_tick
122 cat >input <<INPUT_END
123 commit refs/notes/test
124 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
125 data <<COMMIT
126 second notes commit
127 COMMIT
128
129 from refs/notes/test^0
130 N inline $commit3
131 data <<EOF
132 first note for third commit
133 EOF
134
135 N inline $commit4
136 data <<EOF
137 first note for fourth commit
138 EOF
139
140 INPUT_END
141
142 cat >expect <<EXPECT_END
143 fourth commit
144 first note for fourth commit
145 third commit
146 first note for third commit
147 second commit
148 first note for second commit
149 first commit
150 first note for first commit
151 EXPECT_END
152
153 test_expect_success 'add notes with simple N command' '
154
155 git fast-import <input &&
156 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
157 test_cmp expect actual
158
159 '
160
161 test_tick
162 cat >input <<INPUT_END
163 commit refs/notes/test
164 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
165 data <<COMMIT
166 third notes commit
167 COMMIT
168
169 from refs/notes/test^0
170 N inline $commit1
171 data <<EOF
172 second note for first commit
173 EOF
174
175 N inline $commit2
176 data <<EOF
177 second note for second commit
178 EOF
179
180 N inline $commit3
181 data <<EOF
182 second note for third commit
183 EOF
184
185 N inline $commit4
186 data <<EOF
187 second note for fourth commit
188 EOF
189
190 INPUT_END
191
192 cat >expect <<EXPECT_END
193 fourth commit
194 second note for fourth commit
195 third commit
196 second note for third commit
197 second commit
198 second note for second commit
199 first commit
200 second note for first commit
201 EXPECT_END
202
203 test_expect_success 'update existing notes with N command' '
204
205 git fast-import <input &&
206 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
207 test_cmp expect actual
208
209 '
210
211 test_tick
212 cat >input <<INPUT_END
213 commit refs/notes/test
214 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
215 data <<COMMIT
216 fourth notes commit
217 COMMIT
218
219 from refs/notes/test^0
220 M 644 inline $(echo "$commit3" | sed "s|^..|&/|")
221 data <<EOF
222 prefix of note for third commit
223 EOF
224
225 M 644 inline $(echo "$commit4" | sed "s|^..|&/|")
226 data <<EOF
227 prefix of note for fourth commit
228 EOF
229
230 M 644 inline $(echo "$commit4" | sed "s|^\(..\)\(..\)|\1/\2/|")
231 data <<EOF
232 pre-prefix of note for fourth commit
233 EOF
234
235 N inline $commit1
236 data <<EOF
237 third note for first commit
238 EOF
239
240 N inline $commit2
241 data <<EOF
242 third note for second commit
243 EOF
244
245 N inline $commit3
246 data <<EOF
247 third note for third commit
248 EOF
249
250 N inline $commit4
251 data <<EOF
252 third note for fourth commit
253 EOF
254
255
256 INPUT_END
257
258 cat >expect <<EXPECT_END
259 fourth commit
260 pre-prefix of note for fourth commit
261 prefix of note for fourth commit
262 third note for fourth commit
263 third commit
264 prefix of note for third commit
265 third note for third commit
266 second commit
267 third note for second commit
268 first commit
269 third note for first commit
270 EXPECT_END
271
272 test_expect_success 'add concatentation notes with M command' '
273
274 git fast-import <input &&
275 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
276 test_cmp expect actual
277
278 '
279
280 test_tick
281 cat >input <<INPUT_END
282 commit refs/notes/test
283 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
284 data <<COMMIT
285 fifth notes commit
286 COMMIT
287
288 from refs/notes/test^0
289 deleteall
290
291 INPUT_END
292
293 cat >expect <<EXPECT_END
294 fourth commit
295 third commit
296 second commit
297 first commit
298 EXPECT_END
299
300 test_expect_success 'verify that deleteall also removes notes' '
301
302 git fast-import <input &&
303 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
304 test_cmp expect actual
305
306 '
307
308 test_tick
309 cat >input <<INPUT_END
310 commit refs/notes/test
311 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
312 data <<COMMIT
313 sixth notes commit
314 COMMIT
315
316 from refs/notes/test^0
317 M 644 inline $commit1
318 data <<EOF
319 third note for first commit
320 EOF
321
322 M 644 inline $commit3
323 data <<EOF
324 third note for third commit
325 EOF
326
327 N inline $commit1
328 data <<EOF
329 fourth note for first commit
330 EOF
331
332 N inline $commit3
333 data <<EOF
334 fourth note for third commit
335 EOF
336
337 INPUT_END
338
339 cat >expect <<EXPECT_END
340 fourth commit
341 third commit
342 fourth note for third commit
343 second commit
344 first commit
345 fourth note for first commit
346 EXPECT_END
347
348 test_expect_success 'verify that later N commands override earlier M commands' '
349
350 git fast-import <input &&
351 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
352 test_cmp expect actual
353
354 '
355
356 # Write fast-import commands to create the given number of commits
357 fast_import_commits () {
358 my_ref=$1
359 my_num_commits=$2
360 my_append_to_file=$3
361 my_i=0
362 while test $my_i -lt $my_num_commits
363 do
364 my_i=$(($my_i + 1))
365 test_tick
366 cat >>"$my_append_to_file" <<INPUT_END
367 commit $my_ref
368 mark :$my_i
369 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
370 data <<COMMIT
371 commit #$my_i
372 COMMIT
373
374 M 644 inline file
375 data <<EOF
376 file contents in commit #$my_i
377 EOF
378
379 INPUT_END
380 done
381 }
382
383 # Write fast-import commands to create the given number of notes annotating
384 # the commits created by fast_import_commits()
385 fast_import_notes () {
386 my_notes_ref=$1
387 my_num_commits=$2
388 my_append_to_file=$3
389 my_note_append=$4
390 test_tick
391 cat >>"$my_append_to_file" <<INPUT_END
392 commit $my_notes_ref
393 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
394 data <<COMMIT
395 committing $my_num_commits notes
396 COMMIT
397
398 INPUT_END
399
400 my_i=0
401 while test $my_i -lt $my_num_commits
402 do
403 my_i=$(($my_i + 1))
404 cat >>"$my_append_to_file" <<INPUT_END
405 N inline :$my_i
406 data <<EOF
407 note for commit #$my_i$my_note_append
408 EOF
409
410 INPUT_END
411 done
412 }
413
414
415 rm input expect
416 num_commits=400
417 # Create lots of commits
418 fast_import_commits "refs/heads/many_commits" $num_commits input
419 # Create one note per above commit
420 fast_import_notes "refs/notes/many_notes" $num_commits input
421 # Add a couple of non-notes as well
422 test_tick
423 cat >>input <<INPUT_END
424 commit refs/notes/many_notes
425 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
426 data <<COMMIT
427 committing some non-notes to the notes tree
428 COMMIT
429
430 M 755 inline foobar/non-note.txt
431 data <<EOF
432 This is not a note, but rather a regular file residing in a notes tree
433 EOF
434
435 M 644 inline deadbeef
436 data <<EOF
437 Non-note file
438 EOF
439
440 M 644 inline de/adbeef
441 data <<EOF
442 Another non-note file
443 EOF
444
445 INPUT_END
446 # Finally create the expected output from all these notes and commits
447 i=$num_commits
448 while test $i -gt 0
449 do
450 cat >>expect <<EXPECT_END
451 commit #$i
452 note for commit #$i
453 EXPECT_END
454 i=$(($i - 1))
455 done
456
457 test_expect_success 'add lots of commits and notes' '
458
459 git fast-import <input &&
460 GIT_NOTES_REF=refs/notes/many_notes git log refs/heads/many_commits |
461 grep "^ " > actual &&
462 test_cmp expect actual
463
464 '
465
466 test_expect_success 'verify that lots of notes trigger a fanout scheme' '
467
468 # None of the entries in the top-level notes tree should be a full SHA1
469 git ls-tree --name-only refs/notes/many_notes |
470 while read path
471 do
472 if test $(expr length "$path") -ge 40
473 then
474 return 1
475 fi
476 done
477
478 '
479
480 cat >>expect_non-note1 << EOF
481 This is not a note, but rather a regular file residing in a notes tree
482 EOF
483
484 cat >>expect_non-note2 << EOF
485 Non-note file
486 EOF
487
488 cat >>expect_non-note3 << EOF
489 Another non-note file
490 EOF
491
492 test_expect_success 'verify that non-notes are untouched by a fanout change' '
493
494 git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual &&
495 test_cmp expect_non-note1 actual &&
496 git cat-file -p refs/notes/many_notes:deadbeef > actual &&
497 test_cmp expect_non-note2 actual &&
498 git cat-file -p refs/notes/many_notes:de/adbeef > actual &&
499 test_cmp expect_non-note3 actual
500
501 '
502 remaining_notes=10
503 test_tick
504 cat >>input <<INPUT_END
505 commit refs/notes/many_notes
506 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
507 data <<COMMIT
508 removing all notes but $remaining_notes
509 COMMIT
510 from refs/notes/many_notes^0
511 INPUT_END
512
513 i=$remaining_notes
514 while test $i -lt $num_commits
515 do
516 i=$(($i + 1))
517 cat >>input <<INPUT_END
518 N 0000000000000000000000000000000000000000 :$i
519 INPUT_END
520 done
521
522 i=$num_commits
523 rm expect
524 while test $i -gt 0
525 do
526 cat >>expect <<EXPECT_END
527 commit #$i
528 EXPECT_END
529 if test $i -le $remaining_notes
530 then
531 cat >>expect <<EXPECT_END
532 note for commit #$i
533 EXPECT_END
534 fi
535 i=$(($i - 1))
536 done
537
538 test_expect_success 'remove lots of notes' '
539
540 git fast-import <input &&
541 GIT_NOTES_REF=refs/notes/many_notes git log refs/heads/many_commits |
542 grep "^ " > actual &&
543 test_cmp expect actual
544
545 '
546
547 test_expect_success 'verify that removing notes trigger fanout consolidation' '
548
549 # All entries in the top-level notes tree should be a full SHA1
550 git ls-tree --name-only -r refs/notes/many_notes |
551 while read path
552 do
553 # Explicitly ignore the non-note paths
554 test "$path" = "foobar/non-note.txt" && continue
555 test "$path" = "deadbeef" && continue
556 test "$path" = "de/adbeef" && continue
557
558 if test $(expr length "$path") -ne 40
559 then
560 return 1
561 fi
562 done
563
564 '
565
566 test_expect_success 'verify that non-notes are untouched by a fanout change' '
567
568 git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual &&
569 test_cmp expect_non-note1 actual &&
570 git cat-file -p refs/notes/many_notes:deadbeef > actual &&
571 test_cmp expect_non-note2 actual &&
572 git cat-file -p refs/notes/many_notes:de/adbeef > actual &&
573 test_cmp expect_non-note3 actual
574
575 '
576
577
578 rm input expect
579 num_notes_refs=10
580 num_commits=16
581 some_commits=8
582 # Create commits
583 fast_import_commits "refs/heads/more_commits" $num_commits input
584 # Create one note per above commit per notes ref
585 i=0
586 while test $i -lt $num_notes_refs
587 do
588 i=$(($i + 1))
589 fast_import_notes "refs/notes/more_notes_$i" $num_commits input
590 done
591 # Trigger branch reloading in git-fast-import by repeating the note creation
592 i=0
593 while test $i -lt $num_notes_refs
594 do
595 i=$(($i + 1))
596 fast_import_notes "refs/notes/more_notes_$i" $some_commits input " (2)"
597 done
598 # Finally create the expected output from the notes in refs/notes/more_notes_1
599 i=$num_commits
600 while test $i -gt 0
601 do
602 note_data="note for commit #$i"
603 if test $i -le $some_commits
604 then
605 note_data="$note_data (2)"
606 fi
607 cat >>expect <<EXPECT_END
608 commit #$i
609 $note_data
610 EXPECT_END
611 i=$(($i - 1))
612 done
613
614 test_expect_success "add notes to $num_commits commits in each of $num_notes_refs refs" '
615
616 git fast-import --active-branches=5 <input &&
617 GIT_NOTES_REF=refs/notes/more_notes_1 git log refs/heads/more_commits |
618 grep "^ " > actual &&
619 test_cmp expect actual
620
621 '
622
623 test_done