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
124 commit refs/notes/test
125 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
130 from refs/notes/test^0
133 first note for third commit
138 first note for fourth commit
143 cat >expect
<<EXPECT_END
145 first note for fourth commit
147 first note for third commit
149 first note for second commit
151 first note for first commit
154 test_expect_success
'add notes with simple N command' '
156 git fast-import <input &&
157 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
158 test_cmp expect actual
163 cat >input
<<INPUT_END
164 commit refs/notes/test
165 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
170 from refs/notes/test^0
173 second note for first commit
178 second note for second commit
183 second note for third commit
188 second note for fourth commit
193 cat >expect
<<EXPECT_END
195 second note for fourth commit
197 second note for third commit
199 second note for second commit
201 second note for first commit
204 test_expect_success
'update existing notes with N command' '
206 git fast-import <input &&
207 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
208 test_cmp expect actual
213 cat >input
<<INPUT_END
214 commit refs/notes/test
215 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
220 from refs/notes/test^0
221 M 644 inline $(echo "$commit3" | sed "s|^..|&/|")
223 prefix of note for third commit
226 M 644 inline $(echo "$commit4" | sed "s|^..|&/|")
228 prefix of note for fourth commit
231 M 644 inline $(echo "$commit4" | sed "s|^\(..\)\(..\)|\1/\2/|")
233 pre-prefix of note for fourth commit
238 third note for first commit
243 third note for second commit
248 third note for third commit
253 third note for fourth commit
259 cat >expect
<<EXPECT_END
261 pre-prefix of note for fourth commit
262 prefix of note for fourth commit
263 third note for fourth commit
265 prefix of note for third commit
266 third note for third commit
268 third note for second commit
270 third note for first commit
273 test_expect_success
'add concatentation notes with M command' '
275 git fast-import <input &&
276 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
277 test_cmp expect actual
282 cat >input
<<INPUT_END
283 commit refs/notes/test
284 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
289 from refs/notes/test^0
294 cat >expect
<<EXPECT_END
301 test_expect_success
'verify that deleteall also removes notes' '
303 git fast-import <input &&
304 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
305 test_cmp expect actual
310 cat >input
<<INPUT_END
311 commit refs/notes/test
312 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
317 from refs/notes/test^0
318 M 644 inline $commit1
320 third note for first commit
323 M 644 inline $commit3
325 third note for third commit
330 fourth note for first commit
335 fourth note for third commit
340 cat >expect
<<EXPECT_END
343 fourth note for third commit
346 fourth note for first commit
349 test_expect_success
'verify that later N commands override earlier M commands' '
351 git fast-import <input &&
352 GIT_NOTES_REF=refs/notes/test git log | grep "^ " > actual &&
353 test_cmp expect actual
357 # Write fast-import commands to create the given number of commits
358 fast_import_commits
() {
363 while test $my_i -lt $my_num_commits
367 cat >>"$my_append_to_file" <<INPUT_END
370 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
377 file contents in commit #$my_i
384 # Write fast-import commands to create the given number of notes annotating
385 # the commits created by fast_import_commits()
386 fast_import_notes
() {
392 cat >>"$my_append_to_file" <<INPUT_END
394 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
396 committing $my_num_commits notes
402 while test $my_i -lt $my_num_commits
405 cat >>"$my_append_to_file" <<INPUT_END
408 note for commit #$my_i$my_note_append
418 # Create lots of commits
419 fast_import_commits
"refs/heads/many_commits" $num_commits input
420 # Create one note per above commit
421 fast_import_notes
"refs/notes/many_notes" $num_commits input
422 # Add a couple of non-notes as well
424 cat >>input
<<INPUT_END
425 commit refs/notes/many_notes
426 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
428 committing some non-notes to the notes tree
431 M 755 inline foobar/non-note.txt
433 This is not a note, but rather a regular file residing in a notes tree
436 M 644 inline deadbeef
441 M 644 inline de/adbeef
443 Another non-note file
447 # Finally create the expected output from all these notes and commits
451 cat >>expect
<<EXPECT_END
458 test_expect_success
'add lots of commits and notes' '
460 git fast-import <input &&
461 GIT_NOTES_REF=refs/notes/many_notes git log refs/heads/many_commits |
462 grep "^ " > actual &&
463 test_cmp expect actual
467 test_expect_success
'verify that lots of notes trigger a fanout scheme' '
469 # None of the entries in the top-level notes tree should be a full SHA1
470 git ls-tree --name-only refs/notes/many_notes |
473 if test $(expr length "$path") -ge 40
481 cat >>expect_non-note1
<< EOF
482 This is not a note, but rather a regular file residing in a notes tree
485 cat >>expect_non-note2
<< EOF
489 cat >>expect_non-note3
<< EOF
490 Another non-note file
493 test_expect_success
'verify that non-notes are untouched by a fanout change' '
495 git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual &&
496 test_cmp expect_non-note1 actual &&
497 git cat-file -p refs/notes/many_notes:deadbeef > actual &&
498 test_cmp expect_non-note2 actual &&
499 git cat-file -p refs/notes/many_notes:de/adbeef > actual &&
500 test_cmp expect_non-note3 actual
505 cat >>input
<<INPUT_END
506 commit refs/notes/many_notes
507 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
509 removing all notes but $remaining_notes
511 from refs/notes/many_notes^0
515 while test $i -lt $num_commits
518 cat >>input
<<INPUT_END
519 N 0000000000000000000000000000000000000000 :$i
527 cat >>expect
<<EXPECT_END
530 if test $i -le $remaining_notes
532 cat >>expect
<<EXPECT_END
539 test_expect_success
'remove lots of notes' '
541 git fast-import <input &&
542 GIT_NOTES_REF=refs/notes/many_notes git log refs/heads/many_commits |
543 grep "^ " > actual &&
544 test_cmp expect actual
548 test_expect_success
'verify that removing notes trigger fanout consolidation' '
550 # All entries in the top-level notes tree should be a full SHA1
551 git ls-tree --name-only -r refs/notes/many_notes |
554 # Explicitly ignore the non-note paths
555 test "$path" = "foobar/non-note.txt" && continue
556 test "$path" = "deadbeef" && continue
557 test "$path" = "de/adbeef" && continue
559 if test $(expr length "$path") -ne 40
567 test_expect_success
'verify that non-notes are untouched by a fanout change' '
569 git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual &&
570 test_cmp expect_non-note1 actual &&
571 git cat-file -p refs/notes/many_notes:deadbeef > actual &&
572 test_cmp expect_non-note2 actual &&
573 git cat-file -p refs/notes/many_notes:de/adbeef > actual &&
574 test_cmp expect_non-note3 actual
584 fast_import_commits
"refs/heads/more_commits" $num_commits input
585 # Create one note per above commit per notes ref
587 while test $i -lt $num_notes_refs
590 fast_import_notes
"refs/notes/more_notes_$i" $num_commits input
592 # Trigger branch reloading in git-fast-import by repeating the note creation
594 while test $i -lt $num_notes_refs
597 fast_import_notes
"refs/notes/more_notes_$i" $some_commits input
" (2)"
599 # Finally create the expected output from the notes in refs/notes/more_notes_1
603 note_data
="note for commit #$i"
604 if test $i -le $some_commits
606 note_data
="$note_data (2)"
608 cat >>expect
<<EXPECT_END
615 test_expect_success
"add notes to $num_commits commits in each of $num_notes_refs refs" '
617 git fast-import --active-branches=5 <input &&
618 GIT_NOTES_REF=refs/notes/more_notes_1 git log refs/heads/more_commits |
619 grep "^ " > actual &&
620 test_cmp expect actual