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' '
70 a1d8fa6 refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
72 git reflog show refs/notes/commits >actual &&
73 test_cmp expect actual
76 test_expect_success
'edit existing notes' '
77 MSG=b3 git notes edit &&
78 test_path_is_missing .git/NOTES_EDITMSG &&
79 git ls-tree -r refs/notes/commits >actual &&
80 test_line_count = 1 actual &&
81 test "b3" = "$(git notes show)" &&
83 test_must_fail git notes show HEAD^
86 test_expect_success
'cannot "git notes add -m" where notes already exists' '
87 test_must_fail git notes add -m "b2" &&
88 test_path_is_missing .git/NOTES_EDITMSG &&
89 git ls-tree -r refs/notes/commits >actual &&
90 test_line_count = 1 actual &&
91 test "b3" = "$(git notes show)" &&
93 test_must_fail git notes show HEAD^
96 test_expect_success
'can overwrite existing note with "git notes add -f -m"' '
97 git notes add -f -m "b1" &&
98 test_path_is_missing .git/NOTES_EDITMSG &&
99 git ls-tree -r refs/notes/commits >actual &&
100 test_line_count = 1 actual &&
101 test "b1" = "$(git notes show)" &&
103 test_must_fail git notes show HEAD^
106 test_expect_success
'add w/no options on existing note morphs into edit' '
107 MSG=b2 git notes add &&
108 test_path_is_missing .git/NOTES_EDITMSG &&
109 git ls-tree -r refs/notes/commits >actual &&
110 test_line_count = 1 actual &&
111 test "b2" = "$(git notes show)" &&
113 test_must_fail git notes show HEAD^
116 test_expect_success
'can overwrite existing note with "git notes add -f"' '
117 MSG=b1 git notes add -f &&
118 test_path_is_missing .git/NOTES_EDITMSG &&
119 git ls-tree -r refs/notes/commits >actual &&
120 test_line_count = 1 actual &&
121 test "b1" = "$(git notes show)" &&
123 test_must_fail git notes show HEAD^
126 test_expect_success
'show notes' '
127 cat >expect <<-EOF &&
128 commit 7a4ca6ee52a974a66cbaa78e33214535dff1d691
129 Author: A U Thor <author@example.com>
130 Date: Thu Apr 7 15:14:13 2005 -0700
137 ! (git cat-file commit HEAD | grep b1) &&
138 git log -1 >actual &&
139 test_cmp expect actual
142 test_expect_success
'show multi-line notes' '
144 MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
145 cat >expect-multiline <<-EOF &&
146 commit d07d62e5208f22eb5695e7eb47667dc8b9860290
147 Author: A U Thor <author@example.com>
148 Date: Thu Apr 7 15:15:13 2005 -0700
158 cat expect >>expect-multiline &&
159 git log -2 >actual &&
160 test_cmp expect-multiline actual
163 test_expect_success
'show -F notes' '
165 echo "xyzzy" >note5 &&
166 git notes add -F note5 &&
167 cat >expect-F <<-EOF &&
168 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
169 Author: A U Thor <author@example.com>
170 Date: Thu Apr 7 15:16:13 2005 -0700
178 cat expect-multiline >>expect-F &&
179 git log -3 >actual &&
180 test_cmp expect-F actual
183 test_expect_success
'Re-adding -F notes without -f fails' '
184 echo "zyxxy" >note5 &&
185 test_must_fail git notes add -F note5 &&
186 git log -3 >actual &&
187 test_cmp expect-F actual
190 test_expect_success
'git log --pretty=raw does not show notes' '
191 cat >expect <<-EOF &&
192 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
193 tree 05ac65288c4c4b3b709a020ae94b2ece2f2201ae
194 parent d07d62e5208f22eb5695e7eb47667dc8b9860290
195 author A U Thor <author@example.com> 1112912173 -0700
196 committer C O Mitter <committer@example.com> 1112912173 -0700
200 git log -1 --pretty=raw >actual &&
201 test_cmp expect actual
204 test_expect_success
'git log --show-notes' '
205 cat >>expect <<-EOF &&
210 git log -1 --pretty=raw --show-notes >actual &&
211 test_cmp expect actual
214 test_expect_success
'git log --no-notes' '
215 git log -1 --no-notes >actual &&
219 test_expect_success
'git format-patch does not show notes' '
220 git format-patch -1 --stdout >actual &&
224 test_expect_success
'git format-patch --show-notes does show notes' '
225 git format-patch --show-notes -1 --stdout >actual &&
230 "" --pretty --pretty=raw
--pretty=short
--pretty=medium \
231 --pretty=full
--pretty=fuller
--pretty=format
:%s
--oneline
234 "") p
= not
= negate
="" ;;
235 ?
*) p
="$pretty" not
=" not" negate
="!" ;;
237 test_expect_success
"git show $pretty does$not show notes" '
238 git show $p >actual &&
239 eval "$negate grep xyzzy actual"
243 test_expect_success
'setup alternate notes ref' '
244 git notes --ref=alternate add -m alternate
247 test_expect_success
'git log --notes shows default notes' '
248 git log -1 --notes >actual &&
250 ! grep alternate actual
253 test_expect_success
'git log --notes=X shows only X' '
254 git log -1 --notes=alternate >actual &&
255 ! grep xyzzy actual &&
256 grep alternate actual
259 test_expect_success
'git log --notes --notes=X shows both' '
260 git log -1 --notes --notes=alternate >actual &&
262 grep alternate actual
265 test_expect_success
'git log --no-notes resets default state' '
266 git log -1 --notes --notes=alternate \
267 --no-notes --notes=alternate \
269 ! grep xyzzy actual &&
270 grep alternate actual
273 test_expect_success
'git log --no-notes resets ref list' '
274 git log -1 --notes --notes=alternate \
278 ! grep alternate actual
281 test_expect_success
'show -m notes' '
283 git notes add -m spam -m "foo${LF}bar${LF}baz" &&
284 cat >expect-m <<-EOF &&
285 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
286 Author: A U Thor <author@example.com>
287 Date: Thu Apr 7 15:17:13 2005 -0700
299 cat expect-F >>expect-m &&
300 git log -4 >actual &&
301 test_cmp expect-m actual
304 test_expect_success
'remove note with add -f -F /dev/null' '
305 git notes add -f -F /dev/null &&
306 cat >expect-rm-F <<-EOF &&
307 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
308 Author: A U Thor <author@example.com>
309 Date: Thu Apr 7 15:17:13 2005 -0700
314 cat expect-F >>expect-rm-F &&
315 git log -4 >actual &&
316 test_cmp expect-rm-F actual &&
317 test_must_fail git notes show
320 test_expect_success
'do not create empty note with -m ""' '
321 git notes add -m "" &&
322 git log -4 >actual &&
323 test_cmp expect-rm-F actual &&
324 test_must_fail git notes show
327 test_expect_success
'create note with combination of -m and -F' '
328 cat >expect-combine_m_and_F <<-EOF &&
339 echo "xyzzy" >note_a &&
340 echo "zyxxy" >note_b &&
341 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
342 git notes show >actual &&
343 test_cmp expect-combine_m_and_F actual
346 test_expect_success
'remove note with "git notes remove"' '
347 git notes remove HEAD^ &&
349 cat >expect-rm-remove <<-EOF &&
350 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
351 Author: A U Thor <author@example.com>
352 Date: Thu Apr 7 15:17:13 2005 -0700
356 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
357 Author: A U Thor <author@example.com>
358 Date: Thu Apr 7 15:16:13 2005 -0700
363 cat expect-multiline >>expect-rm-remove &&
364 git log -4 >actual &&
365 test_cmp expect-rm-remove actual &&
366 test_must_fail git notes show HEAD^
369 test_expect_success
'removing non-existing note should not create new commit' '
370 git rev-parse --verify refs/notes/commits >before_commit &&
371 test_must_fail git notes remove HEAD^ &&
372 git rev-parse --verify refs/notes/commits >after_commit &&
373 test_cmp before_commit after_commit
376 test_expect_success
'removing more than one' '
377 before=$(git rev-parse --verify refs/notes/commits) &&
378 test_when_finished "git update-ref refs/notes/commits $before" &&
380 # We have only two -- add another and make sure it stays
381 git notes add -m "extra" &&
382 git notes list HEAD >after-removal-expect &&
383 git notes remove HEAD^^ HEAD^^^ &&
384 git notes list | sed -e "s/ .*//" >actual &&
385 test_cmp after-removal-expect actual
388 test_expect_success
'removing is atomic' '
389 before=$(git rev-parse --verify refs/notes/commits) &&
390 test_when_finished "git update-ref refs/notes/commits $before" &&
391 test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
392 after=$(git rev-parse --verify refs/notes/commits) &&
393 test "$before" = "$after"
396 test_expect_success
'removing with --ignore-missing' '
397 before=$(git rev-parse --verify refs/notes/commits) &&
398 test_when_finished "git update-ref refs/notes/commits $before" &&
400 # We have only two -- add another and make sure it stays
401 git notes add -m "extra" &&
402 git notes list HEAD >after-removal-expect &&
403 git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
404 git notes list | sed -e "s/ .*//" >actual &&
405 test_cmp after-removal-expect actual
408 test_expect_success
'removing with --ignore-missing but bogus ref' '
409 before=$(git rev-parse --verify refs/notes/commits) &&
410 test_when_finished "git update-ref refs/notes/commits $before" &&
411 test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
412 after=$(git rev-parse --verify refs/notes/commits) &&
413 test "$before" = "$after"
416 test_expect_success
'remove reads from --stdin' '
417 before=$(git rev-parse --verify refs/notes/commits) &&
418 test_when_finished "git update-ref refs/notes/commits $before" &&
420 # We have only two -- add another and make sure it stays
421 git notes add -m "extra" &&
422 git notes list HEAD >after-removal-expect &&
423 git rev-parse HEAD^^ HEAD^^^ >input &&
424 git notes remove --stdin <input &&
425 git notes list | sed -e "s/ .*//" >actual &&
426 test_cmp after-removal-expect actual
429 test_expect_success
'remove --stdin is also atomic' '
430 before=$(git rev-parse --verify refs/notes/commits) &&
431 test_when_finished "git update-ref refs/notes/commits $before" &&
432 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
433 test_must_fail git notes remove --stdin <input &&
434 after=$(git rev-parse --verify refs/notes/commits) &&
435 test "$before" = "$after"
438 test_expect_success
'removing with --stdin --ignore-missing' '
439 before=$(git rev-parse --verify refs/notes/commits) &&
440 test_when_finished "git update-ref refs/notes/commits $before" &&
442 # We have only two -- add another and make sure it stays
443 git notes add -m "extra" &&
444 git notes list HEAD >after-removal-expect &&
445 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
446 git notes remove --ignore-missing --stdin <input &&
447 git notes list | sed -e "s/ .*//" >actual &&
448 test_cmp after-removal-expect actual
451 test_expect_success
'list notes with "git notes list"' '
452 cat >expect <<-EOF &&
453 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
454 c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
456 git notes list >actual &&
457 test_cmp expect actual
460 test_expect_success
'list notes with "git notes"' '
462 test_cmp expect actual
465 test_expect_success
'list specific note with "git notes list <object>"' '
466 cat >expect <<-EOF &&
467 c18dc024e14f08d18d14eea0d747ff692d66d6a3
469 git notes list HEAD^^ >actual &&
470 test_cmp expect actual
473 test_expect_success
'listing non-existing notes fails' '
474 cat >expect <<-EOF &&
476 test_must_fail git notes list HEAD >actual &&
477 test_cmp expect actual
480 test_expect_success
'append to existing note with "git notes append"' '
481 cat >expect <<-EOF &&
484 More notes appended with git notes append
486 git notes add -m "Initial set of notes" &&
487 git notes append -m "More notes appended with git notes append" &&
488 git notes show >actual &&
489 test_cmp expect actual
492 test_expect_success
'"git notes list" does not expand to "git notes list HEAD"' '
493 cat >expect_list <<-EOF &&
494 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
495 4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
496 c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
498 git notes list >actual &&
499 test_cmp expect_list actual
502 test_expect_success
'appending empty string does not change existing note' '
503 git notes append -m "" &&
504 git notes show >actual &&
505 test_cmp expect actual
508 test_expect_success
'git notes append == add when there is no existing note' '
509 git notes remove HEAD &&
510 test_must_fail git notes list HEAD &&
511 git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
512 git notes show >actual &&
513 test_cmp expect actual
516 test_expect_success
'appending empty string to non-existing note does not create note' '
517 git notes remove HEAD &&
518 test_must_fail git notes list HEAD &&
519 git notes append -m "" &&
520 test_must_fail git notes list HEAD
523 test_expect_success
'create other note on a different notes ref (setup)' '
525 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
526 cat >expect-not-other <<-EOF &&
527 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
528 Author: A U Thor <author@example.com>
529 Date: Thu Apr 7 15:18:13 2005 -0700
533 cp expect-not-other expect-other &&
534 cat >>expect-other <<-EOF
541 test_expect_success
'Do not show note on other ref by default' '
542 git log -1 >actual &&
543 test_cmp expect-not-other actual
546 test_expect_success
'Do show note when ref is given in GIT_NOTES_REF' '
547 GIT_NOTES_REF="refs/notes/other" git log -1 >actual &&
548 test_cmp expect-other actual
551 test_expect_success
'Do show note when ref is given in core.notesRef config' '
552 test_config core.notesRef "refs/notes/other" &&
553 git log -1 >actual &&
554 test_cmp expect-other actual
557 test_expect_success
'Do not show note when core.notesRef is overridden' '
558 test_config core.notesRef "refs/notes/other" &&
559 GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual &&
560 test_cmp expect-not-other actual
563 test_expect_success
'Show all notes when notes.displayRef=refs/notes/*' '
564 cat >expect-both <<-EOF &&
565 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
566 Author: A U Thor <author@example.com>
567 Date: Thu Apr 7 15:18:13 2005 -0700
577 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
578 Author: A U Thor <author@example.com>
579 Date: Thu Apr 7 15:17:13 2005 -0700
584 ${indent}replacement for deleted note
586 GIT_NOTES_REF=refs/notes/commits git notes add \
587 -m"replacement for deleted note" HEAD^ &&
588 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
589 test_unconfig core.notesRef &&
590 test_config notes.displayRef "refs/notes/*" &&
591 git log -2 >actual &&
592 test_cmp expect-both actual
595 test_expect_success
'core.notesRef is implicitly in notes.displayRef' '
596 test_config core.notesRef refs/notes/commits &&
597 test_config notes.displayRef refs/notes/other &&
598 git log -2 >actual &&
599 test_cmp expect-both actual
602 test_expect_success
'notes.displayRef can be given more than once' '
603 test_unconfig core.notesRef &&
604 test_config notes.displayRef refs/notes/commits &&
605 git config --add notes.displayRef refs/notes/other &&
606 git log -2 >actual &&
607 test_cmp expect-both actual
610 test_expect_success
'notes.displayRef respects order' '
611 cat >expect-both-reversed <<-EOF &&
612 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
613 Author: A U Thor <author@example.com>
614 Date: Thu Apr 7 15:18:13 2005 -0700
624 test_config core.notesRef refs/notes/other &&
625 test_config notes.displayRef refs/notes/commits &&
626 git log -1 >actual &&
627 test_cmp expect-both-reversed actual
630 test_expect_success
'GIT_NOTES_DISPLAY_REF works' '
631 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
632 git log -2 >actual &&
633 test_cmp expect-both actual
636 test_expect_success
'GIT_NOTES_DISPLAY_REF overrides config' '
637 cat >expect-none <<-EOF &&
638 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
639 Author: A U Thor <author@example.com>
640 Date: Thu Apr 7 15:18:13 2005 -0700
644 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
645 Author: A U Thor <author@example.com>
646 Date: Thu Apr 7 15:17:13 2005 -0700
650 test_config notes.displayRef "refs/notes/*" &&
651 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual &&
652 test_cmp expect-none actual
655 test_expect_success
'--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
656 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual &&
657 test_cmp expect-both actual
660 test_expect_success
'--no-standard-notes' '
661 cat >expect-commits <<-EOF &&
662 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
663 Author: A U Thor <author@example.com>
664 Date: Thu Apr 7 15:18:13 2005 -0700
671 git log --no-standard-notes --show-notes=commits -1 >actual &&
672 test_cmp expect-commits actual
675 test_expect_success
'--standard-notes' '
676 test_config notes.displayRef "refs/notes/*" &&
677 git log --no-standard-notes --show-notes=commits \
678 --standard-notes -2 >actual &&
679 test_cmp expect-both actual
682 test_expect_success
'--show-notes=ref accumulates' '
683 git log --show-notes=other --show-notes=commits \
684 --no-standard-notes -1 >actual &&
685 test_cmp expect-both-reversed actual
688 test_expect_success
'Allow notes on non-commits (trees, blobs, tags)' '
689 test_config core.notesRef refs/notes/other &&
690 echo "Note on a tree" >expect &&
691 git notes add -m "Note on a tree" HEAD: &&
692 git notes show HEAD: >actual &&
693 test_cmp expect actual &&
694 echo "Note on a blob" >expect &&
695 filename=$(git ls-tree --name-only HEAD | head -n1) &&
696 git notes add -m "Note on a blob" HEAD:$filename &&
697 git notes show HEAD:$filename >actual &&
698 test_cmp expect actual &&
699 echo "Note on a tag" >expect &&
700 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
701 git notes add -m "Note on a tag" foobar &&
702 git notes show foobar >actual &&
703 test_cmp expect actual
706 test_expect_success
'create note from other note with "git notes add -C"' '
707 cat >expect <<-EOF &&
708 commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c
709 Author: A U Thor <author@example.com>
710 Date: Thu Apr 7 15:19:13 2005 -0700
718 git notes add -C $(git notes list HEAD^) &&
719 git log -1 >actual &&
720 test_cmp expect actual &&
721 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
724 test_expect_success
'create note from non-existing note with "git notes add -C" fails' '
726 test_must_fail git notes add -C deadbeef &&
727 test_must_fail git notes list HEAD
730 test_expect_success
'create note from non-blob with "git notes add -C" fails' '
731 commit=$(git rev-parse --verify HEAD) &&
732 tree=$(git rev-parse --verify HEAD:) &&
733 test_must_fail git notes add -C $commit &&
734 test_must_fail git notes add -C $tree &&
735 test_must_fail git notes list HEAD
738 test_expect_success
'create note from blob with "git notes add -C" reuses blob id' '
739 cat >expect <<-EOF &&
740 commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf
741 Author: A U Thor <author@example.com>
742 Date: Thu Apr 7 15:20:13 2005 -0700
747 ${indent}This is a blob object
749 blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
750 git notes add -C $blob &&
751 git log -1 >actual &&
752 test_cmp expect actual &&
753 test "$(git notes list HEAD)" = "$blob"
756 test_expect_success
'create note from other note with "git notes add -c"' '
757 cat >expect <<-EOF &&
758 commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
759 Author: A U Thor <author@example.com>
760 Date: Thu Apr 7 15:21:13 2005 -0700
765 ${indent}yet another note
768 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
769 git log -1 >actual &&
770 test_cmp expect actual
773 test_expect_success
'create note from non-existing note with "git notes add -c" fails' '
775 test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
776 test_must_fail git notes list HEAD
779 test_expect_success
'append to note from other note with "git notes append -C"' '
780 cat >expect <<-EOF &&
781 commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
782 Author: A U Thor <author@example.com>
783 Date: Thu Apr 7 15:21:13 2005 -0700
788 ${indent}yet another note
790 ${indent}yet another note
792 git notes append -C $(git notes list HEAD^) HEAD^ &&
793 git log -1 HEAD^ >actual &&
794 test_cmp expect actual
797 test_expect_success
'create note from other note with "git notes append -c"' '
798 cat >expect <<-EOF &&
799 commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
800 Author: A U Thor <author@example.com>
801 Date: Thu Apr 7 15:22:13 2005 -0700
808 MSG="other note" git notes append -c $(git notes list HEAD^) &&
809 git log -1 >actual &&
810 test_cmp expect actual
813 test_expect_success
'append to note from other note with "git notes append -c"' '
814 cat >expect <<-EOF &&
815 commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
816 Author: A U Thor <author@example.com>
817 Date: Thu Apr 7 15:22:13 2005 -0700
824 ${indent}yet another note
826 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
827 git log -1 >actual &&
828 test_cmp expect actual
831 test_expect_success
'copy note with "git notes copy"' '
832 cat >expect <<-EOF &&
833 commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
834 Author: A U Thor <author@example.com>
835 Date: Thu Apr 7 15:23:13 2005 -0700
842 ${indent}yet another note
845 git notes copy HEAD^ HEAD &&
846 git log -1 >actual &&
847 test_cmp expect actual &&
848 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
851 test_expect_success
'prevent overwrite with "git notes copy"' '
852 test_must_fail git notes copy HEAD~2 HEAD &&
853 git log -1 >actual &&
854 test_cmp expect actual &&
855 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
858 test_expect_success
'allow overwrite with "git notes copy -f"' '
859 cat >expect <<-EOF &&
860 commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
861 Author: A U Thor <author@example.com>
862 Date: Thu Apr 7 15:23:13 2005 -0700
867 ${indent}yet another note
869 ${indent}yet another note
871 git notes copy -f HEAD~2 HEAD &&
872 git log -1 >actual &&
873 test_cmp expect actual &&
874 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
877 test_expect_success
'cannot copy note from object without notes' '
880 test_must_fail git notes copy HEAD^ HEAD
883 test_expect_success
'git notes copy --stdin' '
884 cat >expect <<-EOF &&
885 commit e871aa61182b1d95d0a6fb75445d891722863b6b
886 Author: A U Thor <author@example.com>
887 Date: Thu Apr 7 15:25:13 2005 -0700
892 ${indent}yet another note
894 ${indent}yet another note
896 commit 65e263ded02ae4e8839bc151095113737579dc12
897 Author: A U Thor <author@example.com>
898 Date: Thu Apr 7 15:24:13 2005 -0700
905 ${indent}yet another note
907 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
908 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
909 git notes copy --stdin &&
910 git log -2 >actual &&
911 test_cmp expect actual &&
912 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
913 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
916 test_expect_success
'git notes copy --for-rewrite (unconfigured)' '
917 cat >expect <<-EOF &&
918 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
919 Author: A U Thor <author@example.com>
920 Date: Thu Apr 7 15:27:13 2005 -0700
924 commit 07c85d77059393ed0154b8c96906547a59dfcddd
925 Author: A U Thor <author@example.com>
926 Date: Thu Apr 7 15:26:13 2005 -0700
932 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
933 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
934 git notes copy --for-rewrite=foo &&
935 git log -2 >actual &&
936 test_cmp expect actual
939 test_expect_success
'git notes copy --for-rewrite (enabled)' '
940 cat >expect <<-EOF &&
941 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
942 Author: A U Thor <author@example.com>
943 Date: Thu Apr 7 15:27:13 2005 -0700
948 ${indent}yet another note
950 ${indent}yet another note
952 commit 07c85d77059393ed0154b8c96906547a59dfcddd
953 Author: A U Thor <author@example.com>
954 Date: Thu Apr 7 15:26:13 2005 -0700
961 ${indent}yet another note
963 test_config notes.rewriteMode overwrite &&
964 test_config notes.rewriteRef "refs/notes/*" &&
965 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
966 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
967 git notes copy --for-rewrite=foo &&
968 git log -2 >actual &&
969 test_cmp expect actual
972 test_expect_success
'git notes copy --for-rewrite (disabled)' '
973 test_config notes.rewrite.bar false &&
974 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
975 git notes copy --for-rewrite=bar &&
976 git log -2 >actual &&
977 test_cmp expect actual
980 test_expect_success
'git notes copy --for-rewrite (overwrite)' '
981 cat >expect <<-EOF &&
982 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
983 Author: A U Thor <author@example.com>
984 Date: Thu Apr 7 15:27:13 2005 -0700
989 ${indent}a fresh note
991 git notes add -f -m"a fresh note" HEAD^ &&
992 test_config notes.rewriteMode overwrite &&
993 test_config notes.rewriteRef "refs/notes/*" &&
994 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
995 git notes copy --for-rewrite=foo &&
996 git log -1 >actual &&
997 test_cmp expect actual
1000 test_expect_success
'git notes copy --for-rewrite (ignore)' '
1001 test_config notes.rewriteMode ignore &&
1002 test_config notes.rewriteRef "refs/notes/*" &&
1003 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1004 git notes copy --for-rewrite=foo &&
1005 git log -1 >actual &&
1006 test_cmp expect actual
1009 test_expect_success
'git notes copy --for-rewrite (append)' '
1010 cat >expect <<-EOF &&
1011 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1012 Author: A U Thor <author@example.com>
1013 Date: Thu Apr 7 15:27:13 2005 -0700
1018 ${indent}a fresh note
1020 ${indent}another fresh note
1022 git notes add -f -m"another fresh note" HEAD^ &&
1023 test_config notes.rewriteMode concatenate &&
1024 test_config notes.rewriteRef "refs/notes/*" &&
1025 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1026 git notes copy --for-rewrite=foo &&
1027 git log -1 >actual &&
1028 test_cmp expect actual
1031 test_expect_success
'git notes copy --for-rewrite (append two to one)' '
1032 cat >expect <<-EOF &&
1033 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1034 Author: A U Thor <author@example.com>
1035 Date: Thu Apr 7 15:27:13 2005 -0700
1040 ${indent}a fresh note
1042 ${indent}another fresh note
1048 git notes add -f -m"append 1" HEAD^ &&
1049 git notes add -f -m"append 2" HEAD^^ &&
1050 test_config notes.rewriteMode concatenate &&
1051 test_config notes.rewriteRef "refs/notes/*" &&
1052 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
1053 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1054 git notes copy --for-rewrite=foo &&
1055 git log -1 >actual &&
1056 test_cmp expect actual
1059 test_expect_success
'git notes copy --for-rewrite (append empty)' '
1060 git notes remove HEAD^ &&
1061 test_config notes.rewriteMode concatenate &&
1062 test_config notes.rewriteRef "refs/notes/*" &&
1063 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1064 git notes copy --for-rewrite=foo &&
1065 git log -1 >actual &&
1066 test_cmp expect actual
1069 test_expect_success
'GIT_NOTES_REWRITE_MODE works' '
1070 cat >expect <<-EOF &&
1071 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1072 Author: A U Thor <author@example.com>
1073 Date: Thu Apr 7 15:27:13 2005 -0700
1078 ${indent}replacement note 1
1080 test_config notes.rewriteMode concatenate &&
1081 test_config notes.rewriteRef "refs/notes/*" &&
1082 git notes add -f -m"replacement note 1" HEAD^ &&
1083 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1084 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1085 git log -1 >actual &&
1086 test_cmp expect actual
1089 test_expect_success
'GIT_NOTES_REWRITE_REF works' '
1090 cat >expect <<-EOF &&
1091 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1092 Author: A U Thor <author@example.com>
1093 Date: Thu Apr 7 15:27:13 2005 -0700
1098 ${indent}replacement note 2
1100 git notes add -f -m"replacement note 2" HEAD^ &&
1101 test_config notes.rewriteMode overwrite &&
1102 test_unconfig notes.rewriteRef &&
1103 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1104 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1105 git notes copy --for-rewrite=foo &&
1106 git log -1 >actual &&
1107 test_cmp expect actual
1110 test_expect_success
'GIT_NOTES_REWRITE_REF overrides config' '
1111 git notes add -f -m"replacement note 3" HEAD^ &&
1112 test_config notes.rewriteMode overwrite &&
1113 test_config notes.rewriteRef refs/notes/other &&
1114 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1115 GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1116 git log -1 >actual &&
1117 test_cmp expect actual
1120 test_expect_success
'git notes copy diagnoses too many or too few parameters' '
1121 test_must_fail git notes copy &&
1122 test_must_fail git notes copy one two three
1125 test_expect_success
'git notes get-ref (no overrides)' '
1126 test_unconfig core.notesRef &&
1127 sane_unset GIT_NOTES_REF &&
1128 test "$(git notes get-ref)" = "refs/notes/commits"
1131 test_expect_success
'git notes get-ref (core.notesRef)' '
1132 test_config core.notesRef refs/notes/foo &&
1133 test "$(git notes get-ref)" = "refs/notes/foo"
1136 test_expect_success
'git notes get-ref (GIT_NOTES_REF)' '
1137 test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1140 test_expect_success
'git notes get-ref (--ref)' '
1141 test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1144 test_expect_success
'setup testing of empty notes' '
1145 test_unconfig core.notesRef &&
1147 empty_blob=$(git hash-object -w /dev/null) &&
1148 echo "$empty_blob" >expect_empty
1153 test_expect_success
"'git notes $cmd' removes empty note" "
1154 test_might_fail git notes remove HEAD &&
1155 MSG= git notes $cmd &&
1156 test_must_fail git notes list HEAD
1159 test_expect_success
"'git notes $cmd --allow-empty' stores empty note" "
1160 test_might_fail git notes remove HEAD &&
1161 MSG= git notes $cmd --allow-empty &&
1162 git notes list HEAD >actual &&
1163 test_cmp expect_empty actual
1169 add
-c "$empty_blob"
1170 add
-C "$empty_blob"
1174 append
-c "$empty_blob"
1175 append
-C "$empty_blob"
1179 test_expect_success
'empty notes are displayed by git log' '
1181 git log -1 >expect &&
1182 cat >>expect <<-EOF &&
1186 git notes add -C "$empty_blob" --allow-empty &&
1187 git log -1 >actual &&
1188 test_cmp expect actual