3 # Copyright (c) 2009 Johan Herland
6 test_description
='test git fast-import of notes objects'
11 cat >input
<<INPUT_END
12 commit refs/heads/master
13 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
20 file foo in first commit
25 file bar in first commit
28 M 644 inline baz/xyzzy
30 file baz/xyzzy in first commit
33 commit refs/heads/master
34 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
41 file foo in second commit
44 M 755 inline baz/xyzzy
46 file baz/xyzzy in second commit
49 commit refs/heads/master
50 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
57 file foo in third commit
60 commit refs/heads/master
61 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
68 file bar in fourth commit
73 test_expect_success
'set up master branch' '
75 git fast-import <input &&
76 git whatchanged master
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")
85 cat >input
<<INPUT_END
86 commit refs/notes/test
87 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
94 first note for first commit
99 first note for second commit
104 cat >expect
<<EXPECT_END
108 first note for second commit
110 first note for first commit
113 test_expect_success
'add notes with simple M command' '
115 git fast-import <input &&
116 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
117 test_cmp expect actual
122 cat >input
<<INPUT_END
123 commit refs/notes/test
124 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
129 from refs/notes/test^0
132 first note for third commit
137 first note for fourth commit
142 cat >expect
<<EXPECT_END
144 first note for fourth commit
146 first note for third commit
148 first note for second commit
150 first note for first commit
153 test_expect_success
'add notes with simple N command' '
155 git fast-import <input &&
156 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
157 test_cmp expect actual
162 cat >input
<<INPUT_END
163 commit refs/notes/test
164 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
169 from refs/notes/test^0
172 second note for first commit
177 second note for second commit
182 second note for third commit
187 second note for fourth commit
192 cat >expect
<<EXPECT_END
194 second note for fourth commit
196 second note for third commit
198 second note for second commit
200 second note for first commit
203 test_expect_success
'update existing notes with N command' '
205 git fast-import <input &&
206 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
207 test_cmp expect actual
212 cat >input
<<INPUT_END
213 commit refs/notes/test
214 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
219 from refs/notes/test^0
220 M 644 inline $(echo "$commit3" | sed "s|^..|&/|")
222 prefix of note for third commit
225 M 644 inline $(echo "$commit4" | sed "s|^..|&/|")
227 prefix of note for fourth commit
230 M 644 inline $(echo "$commit4" | sed "s|^\(..\)\(..\)|\1/\2/|")
232 pre-prefix of note for fourth commit
237 third note for first commit
242 third note for second commit
247 third note for third commit
252 third note for fourth commit
258 cat >expect
<<EXPECT_END
260 pre-prefix of note for fourth commit
261 prefix of note for fourth commit
262 third note for fourth commit
264 prefix of note for third commit
265 third note for third commit
267 third note for second commit
269 third note for first commit
272 test_expect_success
'add concatentation notes with M command' '
274 git fast-import <input &&
275 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
276 test_cmp expect actual
281 cat >input
<<INPUT_END
282 commit refs/notes/test
283 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
288 from refs/notes/test^0
293 cat >expect
<<EXPECT_END
300 test_expect_success
'verify that deleteall also removes notes' '
302 git fast-import <input &&
303 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
304 test_cmp expect actual
309 cat >input
<<INPUT_END
310 commit refs/notes/test
311 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
316 from refs/notes/test^0
317 M 644 inline $commit1
319 third note for first commit
322 M 644 inline $commit3
324 third note for third commit
329 fourth note for first commit
334 fourth note for third commit
339 cat >expect
<<EXPECT_END
342 fourth note for third commit
345 fourth note for first commit
348 test_expect_success
'verify that later N commands override earlier M commands' '
350 git fast-import <input &&
351 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
352 test_cmp expect actual
356 # Write fast-import commands to create the given number of commits
357 fast_import_commits
() {
362 while test $my_i -lt $my_num_commits
366 cat >>"$my_append_to_file" <<INPUT_END
369 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
376 file contents in commit #$my_i
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
() {
391 cat >>"$my_append_to_file" <<INPUT_END
393 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
395 committing $my_num_commits notes
401 while test $my_i -lt $my_num_commits
404 cat >>"$my_append_to_file" <<INPUT_END
407 note for commit #$my_i$my_note_append
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
423 cat >>input
<<INPUT_END
424 commit refs/notes/many_notes
425 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
427 committing some non-notes to the notes tree
430 M 755 inline foobar/non-note.txt
432 This is not a note, but rather a regular file residing in a notes tree
435 M 644 inline deadbeef
440 M 644 inline de/adbeef
442 Another non-note file
446 # Finally create the expected output from all these notes and commits
450 cat >>expect
<<EXPECT_END
457 test_expect_success
'add lots of commits and notes' '
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
466 test_expect_success
'verify that lots of notes trigger a fanout scheme' '
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 |
472 if test $(expr length "$path") -ge 40
480 cat >>expect_non-note1
<< EOF
481 This is not a note, but rather a regular file residing in a notes tree
484 cat >>expect_non-note2
<< EOF
488 cat >>expect_non-note3
<< EOF
489 Another non-note file
492 test_expect_success
'verify that non-notes are untouched by a fanout change' '
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
504 cat >>input
<<INPUT_END
505 commit refs/notes/many_notes
506 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
508 removing all notes but $remaining_notes
510 from refs/notes/many_notes^0
514 while test $i -lt $num_commits
517 cat >>input
<<INPUT_END
518 N 0000000000000000000000000000000000000000 :$i
526 cat >>expect
<<EXPECT_END
529 if test $i -le $remaining_notes
531 cat >>expect
<<EXPECT_END
538 test_expect_success
'remove lots of notes' '
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
547 test_expect_success
'verify that removing notes trigger fanout consolidation' '
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 |
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
558 if test $(expr length "$path") -ne 40
566 test_expect_success
'verify that non-notes are untouched by a fanout change' '
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
583 fast_import_commits
"refs/heads/more_commits" $num_commits input
584 # Create one note per above commit per notes ref
586 while test $i -lt $num_notes_refs
589 fast_import_notes
"refs/notes/more_notes_$i" $num_commits input
591 # Trigger branch reloading in git-fast-import by repeating the note creation
593 while test $i -lt $num_notes_refs
596 fast_import_notes
"refs/notes/more_notes_$i" $some_commits input
" (2)"
598 # Finally create the expected output from the notes in refs/notes/more_notes_1
602 note_data
="note for commit #$i"
603 if test $i -le $some_commits
605 note_data
="$note_data (2)"
607 cat >>expect
<<EXPECT_END
614 test_expect_success
"add notes to $num_commits commits in each of $num_notes_refs refs" '
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