3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test commit notes'
10 write_script fake_editor <<\EOF
14 GIT_EDITOR=./fake_editor
19 test_expect_success 'cannot annotate non-existing HEAD' '
20 test_must_fail env MSG=3 git notes add
23 test_expect_success 'setup' '
28 test_expect_success 'need valid notes ref' '
29 test_must_fail env MSG=1 GIT_NOTES_REF=/ git notes show &&
30 test_must_fail env MSG=2 GIT_NOTES_REF=/ git notes show
33 test_expect_success 'refusing to add notes in refs/heads/' '
34 test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add
37 test_expect_success 'refusing to edit notes in refs/remotes/' '
38 test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit
41 # 1 indicates caught gracefully by die, 128 means git-show barked
42 test_expect_success 'handle empty notes gracefully' '
43 test_expect_code 1 git notes show
46 test_expect_success 'show non-existent notes entry with %N' '
47 test_write_lines A B >expect &&
48 git show -s --format="A%n%NB" >actual &&
49 test_cmp expect actual
52 test_expect_success 'create notes' '
53 MSG=b4 git notes add &&
54 test_path_is_missing .git/NOTES_EDITMSG &&
55 git ls-tree -r refs/notes/commits >actual &&
56 test_line_count = 1 actual &&
57 test "b4" = "$(git notes show)" &&
59 test_must_fail git notes show HEAD^
62 test_expect_success 'show notes entry with %N' '
63 test_write_lines A b4 B >expect &&
64 git show -s --format="A%n%NB" >actual &&
65 test_cmp expect actual
68 test_expect_success 'create reflog entry' '
69 ref=$(git rev-parse --short refs/notes/commits) &&
71 $ref refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
73 git reflog show refs/notes/commits >actual &&
74 test_cmp expect actual
77 test_expect_success 'edit existing notes' '
78 MSG=b3 git notes edit &&
79 test_path_is_missing .git/NOTES_EDITMSG &&
80 git ls-tree -r refs/notes/commits >actual &&
81 test_line_count = 1 actual &&
82 test "b3" = "$(git notes show)" &&
84 test_must_fail git notes show HEAD^
87 test_expect_success 'show notes from treeish' '
88 test "b3" = "$(git notes --ref commits^{tree} show)" &&
89 test "b4" = "$(git notes --ref commits@{1} show)"
92 test_expect_success 'cannot edit notes from non-ref' '
93 test_must_fail git notes --ref commits^{tree} edit &&
94 test_must_fail git notes --ref commits@{1} edit
97 test_expect_success 'cannot "git notes add -m" where notes already exists' '
98 test_must_fail git notes add -m "b2" &&
99 test_path_is_missing .git/NOTES_EDITMSG &&
100 git ls-tree -r refs/notes/commits >actual &&
101 test_line_count = 1 actual &&
102 test "b3" = "$(git notes show)" &&
104 test_must_fail git notes show HEAD^
107 test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
108 git notes add -f -m "b1" &&
109 test_path_is_missing .git/NOTES_EDITMSG &&
110 git ls-tree -r refs/notes/commits >actual &&
111 test_line_count = 1 actual &&
112 test "b1" = "$(git notes show)" &&
114 test_must_fail git notes show HEAD^
117 test_expect_success 'add w/no options on existing note morphs into edit' '
118 MSG=b2 git notes add &&
119 test_path_is_missing .git/NOTES_EDITMSG &&
120 git ls-tree -r refs/notes/commits >actual &&
121 test_line_count = 1 actual &&
122 test "b2" = "$(git notes show)" &&
124 test_must_fail git notes show HEAD^
127 test_expect_success 'can overwrite existing note with "git notes add -f"' '
128 MSG=b1 git notes add -f &&
129 test_path_is_missing .git/NOTES_EDITMSG &&
130 git ls-tree -r refs/notes/commits >actual &&
131 test_line_count = 1 actual &&
132 test "b1" = "$(git notes show)" &&
134 test_must_fail git notes show HEAD^
137 test_expect_success 'show notes' '
138 commit=$(git rev-parse HEAD) &&
139 cat >expect <<-EOF &&
141 Author: A U Thor <author@example.com>
142 Date: Thu Apr 7 15:14:13 2005 -0700
149 ! (git cat-file commit HEAD | grep b1) &&
150 git log -1 >actual &&
151 test_cmp expect actual
154 test_expect_success 'show multi-line notes' '
156 MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
157 commit=$(git rev-parse HEAD) &&
158 cat >expect-multiline <<-EOF &&
160 Author: A U Thor <author@example.com>
161 Date: Thu Apr 7 15:15:13 2005 -0700
171 cat expect >>expect-multiline &&
172 git log -2 >actual &&
173 test_cmp expect-multiline actual
176 test_expect_success 'show -F notes' '
178 echo "xyzzy" >note5 &&
179 git notes add -F note5 &&
180 commit=$(git rev-parse HEAD) &&
181 cat >expect-F <<-EOF &&
183 Author: A U Thor <author@example.com>
184 Date: Thu Apr 7 15:16:13 2005 -0700
192 cat expect-multiline >>expect-F &&
193 git log -3 >actual &&
194 test_cmp expect-F actual
197 test_expect_success 'Re-adding -F notes without -f fails' '
198 echo "zyxxy" >note5 &&
199 test_must_fail git notes add -F note5 &&
200 git log -3 >actual &&
201 test_cmp expect-F actual
204 test_expect_success 'git log --pretty=raw does not show notes' '
205 commit=$(git rev-parse HEAD) &&
206 tree=$(git rev-parse HEAD^{tree}) &&
207 parent=$(git rev-parse HEAD^) &&
208 cat >expect <<-EOF &&
212 author A U Thor <author@example.com> 1112912173 -0700
213 committer C O Mitter <committer@example.com> 1112912173 -0700
217 git log -1 --pretty=raw >actual &&
218 test_cmp expect actual
221 test_expect_success 'git log --show-notes' '
222 cat >>expect <<-EOF &&
227 git log -1 --pretty=raw --show-notes >actual &&
228 test_cmp expect actual
231 test_expect_success 'git log --no-notes' '
232 git log -1 --no-notes >actual &&
236 test_expect_success 'git format-patch does not show notes' '
237 git format-patch -1 --stdout >actual &&
241 test_expect_success 'git format-patch --show-notes does show notes' '
242 git format-patch --show-notes -1 --stdout >actual &&
247 "" --pretty --pretty=raw --pretty=short --pretty=medium \
248 --pretty=full --pretty=fuller --pretty=format:%s --oneline
251 "") p= not= negate="" ;;
252 ?*) p="$pretty" not=" not" negate="!" ;;
254 test_expect_success "git show $pretty does$not show notes" '
255 git show $p >actual &&
256 eval "$negate grep xyzzy actual"
260 test_expect_success 'setup alternate notes ref' '
261 git notes --ref=alternate add -m alternate
264 test_expect_success 'git log --notes shows default notes' '
265 git log -1 --notes >actual &&
267 ! grep alternate actual
270 test_expect_success 'git log --notes=X shows only X' '
271 git log -1 --notes=alternate >actual &&
272 ! grep xyzzy actual &&
273 grep alternate actual
276 test_expect_success 'git log --notes --notes=X shows both' '
277 git log -1 --notes --notes=alternate >actual &&
279 grep alternate actual
282 test_expect_success 'git log --no-notes resets default state' '
283 git log -1 --notes --notes=alternate \
284 --no-notes --notes=alternate \
286 ! grep xyzzy actual &&
287 grep alternate actual
290 test_expect_success 'git log --no-notes resets ref list' '
291 git log -1 --notes --notes=alternate \
295 ! grep alternate actual
298 test_expect_success 'show -m notes' '
300 git notes add -m spam -m "foo${LF}bar${LF}baz" &&
301 commit=$(git rev-parse HEAD) &&
302 cat >expect-m <<-EOF &&
304 Author: A U Thor <author@example.com>
305 Date: Thu Apr 7 15:17:13 2005 -0700
317 cat expect-F >>expect-m &&
318 git log -4 >actual &&
319 test_cmp expect-m actual
322 test_expect_success 'remove note with add -f -F /dev/null' '
323 git notes add -f -F /dev/null &&
324 commit=$(git rev-parse HEAD) &&
325 cat >expect-rm-F <<-EOF &&
327 Author: A U Thor <author@example.com>
328 Date: Thu Apr 7 15:17:13 2005 -0700
333 cat expect-F >>expect-rm-F &&
334 git log -4 >actual &&
335 test_cmp expect-rm-F actual &&
336 test_must_fail git notes show
339 test_expect_success 'do not create empty note with -m ""' '
340 git notes add -m "" &&
341 git log -4 >actual &&
342 test_cmp expect-rm-F actual &&
343 test_must_fail git notes show
346 test_expect_success 'create note with combination of -m and -F' '
347 cat >expect-combine_m_and_F <<-EOF &&
358 echo "xyzzy" >note_a &&
359 echo "zyxxy" >note_b &&
360 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
361 git notes show >actual &&
362 test_cmp expect-combine_m_and_F actual
365 test_expect_success 'remove note with "git notes remove"' '
366 git notes remove HEAD^ &&
368 commit=$(git rev-parse HEAD) &&
369 parent=$(git rev-parse HEAD^) &&
370 cat >expect-rm-remove <<-EOF &&
372 Author: A U Thor <author@example.com>
373 Date: Thu Apr 7 15:17:13 2005 -0700
378 Author: A U Thor <author@example.com>
379 Date: Thu Apr 7 15:16:13 2005 -0700
384 cat expect-multiline >>expect-rm-remove &&
385 git log -4 >actual &&
386 test_cmp expect-rm-remove actual &&
387 test_must_fail git notes show HEAD^
390 test_expect_success 'removing non-existing note should not create new commit' '
391 git rev-parse --verify refs/notes/commits >before_commit &&
392 test_must_fail git notes remove HEAD^ &&
393 git rev-parse --verify refs/notes/commits >after_commit &&
394 test_cmp before_commit after_commit
397 test_expect_success 'removing more than one' '
398 before=$(git rev-parse --verify refs/notes/commits) &&
399 test_when_finished "git update-ref refs/notes/commits $before" &&
401 # We have only two -- add another and make sure it stays
402 git notes add -m "extra" &&
403 git notes list HEAD >after-removal-expect &&
404 git notes remove HEAD^^ HEAD^^^ &&
405 git notes list | sed -e "s/ .*//" >actual &&
406 test_cmp after-removal-expect actual
409 test_expect_success 'removing is atomic' '
410 before=$(git rev-parse --verify refs/notes/commits) &&
411 test_when_finished "git update-ref refs/notes/commits $before" &&
412 test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
413 after=$(git rev-parse --verify refs/notes/commits) &&
414 test "$before" = "$after"
417 test_expect_success 'removing with --ignore-missing' '
418 before=$(git rev-parse --verify refs/notes/commits) &&
419 test_when_finished "git update-ref refs/notes/commits $before" &&
421 # We have only two -- add another and make sure it stays
422 git notes add -m "extra" &&
423 git notes list HEAD >after-removal-expect &&
424 git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
425 git notes list | sed -e "s/ .*//" >actual &&
426 test_cmp after-removal-expect actual
429 test_expect_success 'removing with --ignore-missing but bogus ref' '
430 before=$(git rev-parse --verify refs/notes/commits) &&
431 test_when_finished "git update-ref refs/notes/commits $before" &&
432 test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
433 after=$(git rev-parse --verify refs/notes/commits) &&
434 test "$before" = "$after"
437 test_expect_success 'remove reads from --stdin' '
438 before=$(git rev-parse --verify refs/notes/commits) &&
439 test_when_finished "git update-ref refs/notes/commits $before" &&
441 # We have only two -- add another and make sure it stays
442 git notes add -m "extra" &&
443 git notes list HEAD >after-removal-expect &&
444 git rev-parse HEAD^^ HEAD^^^ >input &&
445 git notes remove --stdin <input &&
446 git notes list | sed -e "s/ .*//" >actual &&
447 test_cmp after-removal-expect actual
450 test_expect_success 'remove --stdin is also atomic' '
451 before=$(git rev-parse --verify refs/notes/commits) &&
452 test_when_finished "git update-ref refs/notes/commits $before" &&
453 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
454 test_must_fail git notes remove --stdin <input &&
455 after=$(git rev-parse --verify refs/notes/commits) &&
456 test "$before" = "$after"
459 test_expect_success 'removing with --stdin --ignore-missing' '
460 before=$(git rev-parse --verify refs/notes/commits) &&
461 test_when_finished "git update-ref refs/notes/commits $before" &&
463 # We have only two -- add another and make sure it stays
464 git notes add -m "extra" &&
465 git notes list HEAD >after-removal-expect &&
466 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
467 git notes remove --ignore-missing --stdin <input &&
468 git notes list | sed -e "s/ .*//" >actual &&
469 test_cmp after-removal-expect actual
472 test_expect_success 'list notes with "git notes list"' '
473 commit_2=$(git rev-parse 2nd) &&
474 commit_3=$(git rev-parse 3rd) &&
475 sort -t" " -k2 >expect <<-EOF &&
476 $(git rev-parse refs/notes/commits:$commit_2) $commit_2
477 $(git rev-parse refs/notes/commits:$commit_3) $commit_3
479 git notes list >actual &&
480 test_cmp expect actual
483 test_expect_success 'list notes with "git notes"' '
485 test_cmp expect actual
488 test_expect_success 'list specific note with "git notes list <object>"' '
489 cat >expect <<-EOF &&
490 $(git rev-parse refs/notes/commits:$commit_3)
492 git notes list HEAD^^ >actual &&
493 test_cmp expect actual
496 test_expect_success 'listing non-existing notes fails' '
497 test_must_fail git notes list HEAD >actual &&
498 test_must_be_empty actual
501 test_expect_success 'append to existing note with "git notes append"' '
502 cat >expect <<-EOF &&
505 More notes appended with git notes append
507 git notes add -m "Initial set of notes" &&
508 git notes append -m "More notes appended with git notes append" &&
509 git notes show >actual &&
510 test_cmp expect actual
513 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
514 commit_5=$(git rev-parse 5th) &&
515 sort -t" " -k2 >expect_list <<-EOF &&
516 $(git rev-parse refs/notes/commits:$commit_2) $commit_2
517 $(git rev-parse refs/notes/commits:$commit_3) $commit_3
518 $(git rev-parse refs/notes/commits:$commit_5) $commit_5
520 git notes list >actual &&
521 test_cmp expect_list actual
524 test_expect_success 'appending empty string does not change existing note' '
525 git notes append -m "" &&
526 git notes show >actual &&
527 test_cmp expect actual
530 test_expect_success 'git notes append == add when there is no existing note' '
531 git notes remove HEAD &&
532 test_must_fail git notes list HEAD &&
533 git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
534 git notes show >actual &&
535 test_cmp expect actual
538 test_expect_success 'appending empty string to non-existing note does not create note' '
539 git notes remove HEAD &&
540 test_must_fail git notes list HEAD &&
541 git notes append -m "" &&
542 test_must_fail git notes list HEAD
545 test_expect_success 'create other note on a different notes ref (setup)' '
547 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
548 commit=$(git rev-parse HEAD) &&
549 cat >expect-not-other <<-EOF &&
551 Author: A U Thor <author@example.com>
552 Date: Thu Apr 7 15:18:13 2005 -0700
556 cp expect-not-other expect-other &&
557 cat >>expect-other <<-EOF
564 test_expect_success 'Do not show note on other ref by default' '
565 git log -1 >actual &&
566 test_cmp expect-not-other actual
569 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
570 GIT_NOTES_REF="refs/notes/other" git log -1 >actual &&
571 test_cmp expect-other actual
574 test_expect_success 'Do show note when ref is given in core.notesRef config' '
575 test_config core.notesRef "refs/notes/other" &&
576 git log -1 >actual &&
577 test_cmp expect-other actual
580 test_expect_success 'Do not show note when core.notesRef is overridden' '
581 test_config core.notesRef "refs/notes/other" &&
582 GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual &&
583 test_cmp expect-not-other actual
586 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
587 commit=$(git rev-parse HEAD) &&
588 parent=$(git rev-parse HEAD^) &&
589 cat >expect-both <<-EOF &&
591 Author: A U Thor <author@example.com>
592 Date: Thu Apr 7 15:18:13 2005 -0700
603 Author: A U Thor <author@example.com>
604 Date: Thu Apr 7 15:17:13 2005 -0700
609 ${indent}replacement for deleted note
611 GIT_NOTES_REF=refs/notes/commits git notes add \
612 -m"replacement for deleted note" HEAD^ &&
613 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
614 test_unconfig core.notesRef &&
615 test_config notes.displayRef "refs/notes/*" &&
616 git log -2 >actual &&
617 test_cmp expect-both actual
620 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
621 test_config core.notesRef refs/notes/commits &&
622 test_config notes.displayRef refs/notes/other &&
623 git log -2 >actual &&
624 test_cmp expect-both actual
627 test_expect_success 'notes.displayRef can be given more than once' '
628 test_unconfig core.notesRef &&
629 test_config notes.displayRef refs/notes/commits &&
630 git config --add notes.displayRef refs/notes/other &&
631 git log -2 >actual &&
632 test_cmp expect-both actual
635 test_expect_success 'notes.displayRef respects order' '
636 commit=$(git rev-parse HEAD) &&
637 cat >expect-both-reversed <<-EOF &&
639 Author: A U Thor <author@example.com>
640 Date: Thu Apr 7 15:18:13 2005 -0700
650 test_config core.notesRef refs/notes/other &&
651 test_config notes.displayRef refs/notes/commits &&
652 git log -1 >actual &&
653 test_cmp expect-both-reversed actual
656 test_expect_success 'notes.displayRef with no value handled gracefully' '
657 test_must_fail git -c notes.displayRef log -0 --notes &&
658 test_must_fail git -c notes.displayRef diff-tree --notes HEAD
661 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
662 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
663 git log -2 >actual &&
664 test_cmp expect-both actual
667 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
668 commit=$(git rev-parse HEAD) &&
669 parent=$(git rev-parse HEAD^) &&
670 cat >expect-none <<-EOF &&
672 Author: A U Thor <author@example.com>
673 Date: Thu Apr 7 15:18:13 2005 -0700
678 Author: A U Thor <author@example.com>
679 Date: Thu Apr 7 15:17:13 2005 -0700
683 test_config notes.displayRef "refs/notes/*" &&
684 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual &&
685 test_cmp expect-none actual
688 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
689 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual &&
690 test_cmp expect-both actual
693 test_expect_success '--no-standard-notes' '
694 commit=$(git rev-parse HEAD) &&
695 cat >expect-commits <<-EOF &&
697 Author: A U Thor <author@example.com>
698 Date: Thu Apr 7 15:18:13 2005 -0700
705 git log --no-standard-notes --show-notes=commits -1 >actual &&
706 test_cmp expect-commits actual
709 test_expect_success '--standard-notes' '
710 test_config notes.displayRef "refs/notes/*" &&
711 git log --no-standard-notes --show-notes=commits \
712 --standard-notes -2 >actual &&
713 test_cmp expect-both actual
716 test_expect_success '--show-notes=ref accumulates' '
717 git log --show-notes=other --show-notes=commits \
718 --no-standard-notes -1 >actual &&
719 test_cmp expect-both-reversed actual
722 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
723 test_config core.notesRef refs/notes/other &&
724 echo "Note on a tree" >expect &&
725 git notes add -m "Note on a tree" HEAD: &&
726 git notes show HEAD: >actual &&
727 test_cmp expect actual &&
728 echo "Note on a blob" >expect &&
729 filename=$(git ls-tree --name-only HEAD | head -n1) &&
730 git notes add -m "Note on a blob" HEAD:$filename &&
731 git notes show HEAD:$filename >actual &&
732 test_cmp expect actual &&
733 echo "Note on a tag" >expect &&
734 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
735 git notes add -m "Note on a tag" foobar &&
736 git notes show foobar >actual &&
737 test_cmp expect actual
740 test_expect_success 'create note from other note with "git notes add -C"' '
742 commit=$(git rev-parse HEAD) &&
743 cat >expect <<-EOF &&
745 Author: A U Thor <author@example.com>
746 Date: Thu Apr 7 15:19:13 2005 -0700
753 git notes add -C $(git notes list HEAD^) &&
754 git log -1 >actual &&
755 test_cmp expect actual &&
756 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
759 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
761 test_must_fail git notes add -C deadbeef &&
762 test_must_fail git notes list HEAD
765 test_expect_success 'create note from non-blob with "git notes add -C" fails' '
766 commit=$(git rev-parse --verify HEAD) &&
767 tree=$(git rev-parse --verify HEAD:) &&
768 test_must_fail git notes add -C $commit &&
769 test_must_fail git notes add -C $tree &&
770 test_must_fail git notes list HEAD
773 test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
774 commit=$(git rev-parse HEAD) &&
775 cat >expect <<-EOF &&
777 Author: A U Thor <author@example.com>
778 Date: Thu Apr 7 15:20:13 2005 -0700
783 ${indent}This is a blob object
785 blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
786 git notes add -C $blob &&
787 git log -1 >actual &&
788 test_cmp expect actual &&
789 test "$(git notes list HEAD)" = "$blob"
792 test_expect_success 'create note from other note with "git notes add -c"' '
794 commit=$(git rev-parse HEAD) &&
795 cat >expect <<-EOF &&
797 Author: A U Thor <author@example.com>
798 Date: Thu Apr 7 15:21:13 2005 -0700
803 ${indent}yet another note
805 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
806 git log -1 >actual &&
807 test_cmp expect actual
810 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
812 test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
813 test_must_fail git notes list HEAD
816 test_expect_success 'append to note from other note with "git notes append -C"' '
817 commit=$(git rev-parse HEAD^) &&
818 cat >expect <<-EOF &&
820 Author: A U Thor <author@example.com>
821 Date: Thu Apr 7 15:21:13 2005 -0700
826 ${indent}yet another note
828 ${indent}yet another note
830 git notes append -C $(git notes list HEAD^) HEAD^ &&
831 git log -1 HEAD^ >actual &&
832 test_cmp expect actual
835 test_expect_success 'create note from other note with "git notes append -c"' '
836 commit=$(git rev-parse HEAD) &&
837 cat >expect <<-EOF &&
839 Author: A U Thor <author@example.com>
840 Date: Thu Apr 7 15:22:13 2005 -0700
847 MSG="other note" git notes append -c $(git notes list HEAD^) &&
848 git log -1 >actual &&
849 test_cmp expect actual
852 test_expect_success 'append to note from other note with "git notes append -c"' '
853 commit=$(git rev-parse HEAD) &&
854 cat >expect <<-EOF &&
856 Author: A U Thor <author@example.com>
857 Date: Thu Apr 7 15:22:13 2005 -0700
864 ${indent}yet another note
866 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
867 git log -1 >actual &&
868 test_cmp expect actual
871 test_expect_success 'copy note with "git notes copy"' '
873 commit=$(git rev-parse HEAD) &&
874 cat >expect <<-EOF &&
876 Author: A U Thor <author@example.com>
877 Date: Thu Apr 7 15:23:13 2005 -0700
884 ${indent}yet another note
886 git notes copy HEAD^ HEAD &&
887 git log -1 >actual &&
888 test_cmp expect actual &&
889 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
892 test_expect_success 'prevent overwrite with "git notes copy"' '
893 test_must_fail git notes copy HEAD~2 HEAD &&
894 git log -1 >actual &&
895 test_cmp expect actual &&
896 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
899 test_expect_success 'allow overwrite with "git notes copy -f"' '
900 commit=$(git rev-parse HEAD) &&
901 cat >expect <<-EOF &&
903 Author: A U Thor <author@example.com>
904 Date: Thu Apr 7 15:23:13 2005 -0700
909 ${indent}yet another note
911 ${indent}yet another note
913 git notes copy -f HEAD~2 HEAD &&
914 git log -1 >actual &&
915 test_cmp expect actual &&
916 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
919 test_expect_success 'cannot copy note from object without notes' '
922 test_must_fail git notes copy HEAD^ HEAD
925 test_expect_success 'git notes copy --stdin' '
926 commit=$(git rev-parse HEAD) &&
927 parent=$(git rev-parse HEAD^) &&
928 cat >expect <<-EOF &&
930 Author: A U Thor <author@example.com>
931 Date: Thu Apr 7 15:25:13 2005 -0700
936 ${indent}yet another note
938 ${indent}yet another note
941 Author: A U Thor <author@example.com>
942 Date: Thu Apr 7 15:24:13 2005 -0700
949 ${indent}yet another note
951 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
952 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
953 git notes copy --stdin &&
954 git log -2 >actual &&
955 test_cmp expect actual &&
956 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
957 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
960 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
963 commit=$(git rev-parse HEAD) &&
964 parent=$(git rev-parse HEAD^) &&
965 cat >expect <<-EOF &&
967 Author: A U Thor <author@example.com>
968 Date: Thu Apr 7 15:27:13 2005 -0700
973 Author: A U Thor <author@example.com>
974 Date: Thu Apr 7 15:26:13 2005 -0700
978 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
979 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
980 git notes copy --for-rewrite=foo &&
981 git log -2 >actual &&
982 test_cmp expect actual
985 test_expect_success 'git notes copy --for-rewrite (enabled)' '
986 commit=$(git rev-parse HEAD) &&
987 parent=$(git rev-parse HEAD^) &&
988 cat >expect <<-EOF &&
990 Author: A U Thor <author@example.com>
991 Date: Thu Apr 7 15:27:13 2005 -0700
996 ${indent}yet another note
998 ${indent}yet another note
1001 Author: A U Thor <author@example.com>
1002 Date: Thu Apr 7 15:26:13 2005 -0700
1009 ${indent}yet another note
1011 test_config notes.rewriteMode overwrite &&
1012 test_config notes.rewriteRef "refs/notes/*" &&
1013 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
1014 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
1015 git notes copy --for-rewrite=foo &&
1016 git log -2 >actual &&
1017 test_cmp expect actual
1020 test_expect_success 'git notes copy --for-rewrite (disabled)' '
1021 test_config notes.rewrite.bar false &&
1022 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
1023 git notes copy --for-rewrite=bar &&
1024 git log -2 >actual &&
1025 test_cmp expect actual
1028 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
1029 commit=$(git rev-parse HEAD) &&
1030 cat >expect <<-EOF &&
1032 Author: A U Thor <author@example.com>
1033 Date: Thu Apr 7 15:27:13 2005 -0700
1038 ${indent}a fresh note
1040 git notes add -f -m"a fresh note" HEAD^ &&
1041 test_config notes.rewriteMode overwrite &&
1042 test_config notes.rewriteRef "refs/notes/*" &&
1043 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1044 git notes copy --for-rewrite=foo &&
1045 git log -1 >actual &&
1046 test_cmp expect actual
1049 test_expect_success 'git notes copy --for-rewrite (ignore)' '
1050 test_config notes.rewriteMode ignore &&
1051 test_config notes.rewriteRef "refs/notes/*" &&
1052 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1053 git notes copy --for-rewrite=foo &&
1054 git log -1 >actual &&
1055 test_cmp expect actual
1058 test_expect_success 'git notes copy --for-rewrite (append)' '
1059 commit=$(git rev-parse HEAD) &&
1060 cat >expect <<-EOF &&
1062 Author: A U Thor <author@example.com>
1063 Date: Thu Apr 7 15:27:13 2005 -0700
1068 ${indent}a fresh note
1070 ${indent}another fresh note
1072 git notes add -f -m"another fresh note" HEAD^ &&
1073 test_config notes.rewriteMode concatenate &&
1074 test_config notes.rewriteRef "refs/notes/*" &&
1075 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1076 git notes copy --for-rewrite=foo &&
1077 git log -1 >actual &&
1078 test_cmp expect actual
1081 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1082 commit=$(git rev-parse HEAD) &&
1083 cat >expect <<-EOF &&
1085 Author: A U Thor <author@example.com>
1086 Date: Thu Apr 7 15:27:13 2005 -0700
1091 ${indent}a fresh note
1093 ${indent}another fresh note
1099 git notes add -f -m"append 1" HEAD^ &&
1100 git notes add -f -m"append 2" HEAD^^ &&
1101 test_config notes.rewriteMode concatenate &&
1102 test_config notes.rewriteRef "refs/notes/*" &&
1103 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD) &&
1104 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1105 git notes copy --for-rewrite=foo &&
1106 git log -1 >actual &&
1107 test_cmp expect actual
1110 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1111 git notes remove HEAD^ &&
1112 test_config notes.rewriteMode concatenate &&
1113 test_config notes.rewriteRef "refs/notes/*" &&
1114 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1115 git notes copy --for-rewrite=foo &&
1116 git log -1 >actual &&
1117 test_cmp expect actual
1120 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1121 commit=$(git rev-parse HEAD) &&
1122 cat >expect <<-EOF &&
1124 Author: A U Thor <author@example.com>
1125 Date: Thu Apr 7 15:27:13 2005 -0700
1130 ${indent}replacement note 1
1132 test_config notes.rewriteMode concatenate &&
1133 test_config notes.rewriteRef "refs/notes/*" &&
1134 git notes add -f -m"replacement note 1" HEAD^ &&
1135 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1136 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1137 git log -1 >actual &&
1138 test_cmp expect actual
1141 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1142 commit=$(git rev-parse HEAD) &&
1143 cat >expect <<-EOF &&
1145 Author: A U Thor <author@example.com>
1146 Date: Thu Apr 7 15:27:13 2005 -0700
1151 ${indent}replacement note 2
1153 git notes add -f -m"replacement note 2" HEAD^ &&
1154 test_config notes.rewriteMode overwrite &&
1155 test_unconfig notes.rewriteRef &&
1156 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1157 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1158 git notes copy --for-rewrite=foo &&
1159 git log -1 >actual &&
1160 test_cmp expect actual
1163 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1164 git notes add -f -m"replacement note 3" HEAD^ &&
1165 test_config notes.rewriteMode overwrite &&
1166 test_config notes.rewriteRef refs/notes/other &&
1167 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1168 GIT_NOTES_REWRITE_REF=refs/notes/commits \
1169 git notes copy --for-rewrite=foo &&
1170 git log -1 >actual &&
1171 grep "replacement note 3" actual
1174 test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1175 test_must_fail git notes copy &&
1176 test_must_fail git notes copy one two three
1179 test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '
1180 test_unconfig core.notesRef &&
1181 sane_unset GIT_NOTES_REF &&
1182 test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master"
1185 test_expect_success 'git notes get-ref (no overrides)' '
1186 test_unconfig core.notesRef &&
1187 sane_unset GIT_NOTES_REF &&
1188 test "$(git notes get-ref)" = "refs/notes/commits"
1191 test_expect_success 'git notes get-ref (core.notesRef)' '
1192 test_config core.notesRef refs/notes/foo &&
1193 test "$(git notes get-ref)" = "refs/notes/foo"
1196 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1197 test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1200 test_expect_success 'git notes get-ref (--ref)' '
1201 test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1204 test_expect_success 'setup testing of empty notes' '
1205 test_unconfig core.notesRef &&
1207 empty_blob=$(git hash-object -w /dev/null) &&
1208 echo "$empty_blob" >expect_empty
1213 test_expect_success "'git notes $cmd' removes empty note" "
1214 test_might_fail git notes remove HEAD &&
1215 MSG= git notes $cmd &&
1216 test_must_fail git notes list HEAD
1219 test_expect_success "'git notes $cmd --allow-empty' stores empty note" "
1220 test_might_fail git notes remove HEAD &&
1221 MSG= git notes $cmd --allow-empty &&
1222 git notes list HEAD >actual &&
1223 test_cmp expect_empty actual
1229 add -c "$empty_blob"
1230 add -C "$empty_blob"
1234 append -c "$empty_blob"
1235 append -C "$empty_blob"
1239 test_expect_success 'empty notes are displayed by git log' '
1241 git log -1 >expect &&
1242 cat >>expect <<-EOF &&
1246 git notes add -C "$empty_blob" --allow-empty &&
1247 git log -1 >actual &&
1248 test_cmp expect actual