Merge branch 'es/add-doc-list-short-form-of-all-in-synopsis' into maint-2.43
[git.git] / t / t3301-notes.sh
blobcf23c06c098756abec968d689bcbf3e58541901b
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test commit notes'
8 . ./test-lib.sh
10 write_script fake_editor <<\EOF
11 echo "$MSG" >"$1"
12 echo "$MSG" >&2
13 EOF
14 GIT_EDITOR=./fake_editor
15 export GIT_EDITOR
17 indent=" "
19 test_expect_success 'cannot annotate non-existing HEAD' '
20 test_must_fail env MSG=3 git notes add
23 test_expect_success 'setup' '
24 test_commit 1st &&
25 test_commit 2nd
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 echo b4 >expect &&
58 git notes show >actual &&
59 test_cmp expect actual &&
60 git show HEAD^ &&
61 test_must_fail git notes show HEAD^
64 test_expect_success 'show notes entry with %N' '
65 test_write_lines A b4 B >expect &&
66 git show -s --format="A%n%NB" >actual &&
67 test_cmp expect actual
70 test_expect_success 'create reflog entry' '
71 ref=$(git rev-parse --short refs/notes/commits) &&
72 cat <<-EOF >expect &&
73 $ref refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
74 EOF
75 git reflog show refs/notes/commits >actual &&
76 test_cmp expect actual
79 test_expect_success 'edit existing notes' '
80 MSG=b3 git notes edit &&
81 test_path_is_missing .git/NOTES_EDITMSG &&
82 git ls-tree -r refs/notes/commits >actual &&
83 test_line_count = 1 actual &&
84 echo b3 >expect &&
85 git notes show >actual &&
86 test_cmp expect actual &&
87 git show HEAD^ &&
88 test_must_fail git notes show HEAD^
91 test_expect_success 'show notes from treeish' '
92 echo b3 >expect &&
93 git notes --ref commits^{tree} show >actual &&
94 test_cmp expect actual &&
96 echo b4 >expect &&
97 git notes --ref commits@{1} show >actual &&
98 test_cmp expect actual
101 test_expect_success 'cannot edit notes from non-ref' '
102 test_must_fail git notes --ref commits^{tree} edit &&
103 test_must_fail git notes --ref commits@{1} edit
106 test_expect_success 'cannot "git notes add -m" where notes already exists' '
107 test_must_fail git notes add -m "b2" &&
108 test_path_is_missing .git/NOTES_EDITMSG &&
109 git ls-tree -r refs/notes/commits >actual &&
110 test_line_count = 1 actual &&
111 echo b3 >expect &&
112 git notes show >actual &&
113 test_cmp expect actual &&
114 git show HEAD^ &&
115 test_must_fail git notes show HEAD^
118 test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
119 git notes add -f -m "b1" &&
120 test_path_is_missing .git/NOTES_EDITMSG &&
121 git ls-tree -r refs/notes/commits >actual &&
122 test_line_count = 1 actual &&
123 echo b1 >expect &&
124 git notes show >actual &&
125 test_cmp expect actual &&
126 git show HEAD^ &&
127 test_must_fail git notes show HEAD^
130 test_expect_success 'add w/no options on existing note morphs into edit' '
131 MSG=b2 git notes add &&
132 test_path_is_missing .git/NOTES_EDITMSG &&
133 git ls-tree -r refs/notes/commits >actual &&
134 test_line_count = 1 actual &&
135 echo b2 >expect &&
136 git notes show >actual &&
137 test_cmp expect actual &&
138 git show HEAD^ &&
139 test_must_fail git notes show HEAD^
142 test_expect_success 'can overwrite existing note with "git notes add -f"' '
143 MSG=b1 git notes add -f &&
144 test_path_is_missing .git/NOTES_EDITMSG &&
145 git ls-tree -r refs/notes/commits >actual &&
146 test_line_count = 1 actual &&
147 echo b1 >expect &&
148 git notes show >actual &&
149 test_cmp expect actual &&
150 git show HEAD^ &&
151 test_must_fail git notes show HEAD^
154 test_expect_success 'show notes' '
155 commit=$(git rev-parse HEAD) &&
156 cat >expect <<-EOF &&
157 commit $commit
158 Author: A U Thor <author@example.com>
159 Date: Thu Apr 7 15:14:13 2005 -0700
161 ${indent}2nd
163 Notes:
164 ${indent}b1
166 git cat-file commit HEAD >commits &&
167 ! grep b1 commits &&
168 git log -1 >actual &&
169 test_cmp expect actual
172 test_expect_success 'show multi-line notes' '
173 test_commit 3rd &&
174 MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
175 commit=$(git rev-parse HEAD) &&
176 cat >expect-multiline <<-EOF &&
177 commit $commit
178 Author: A U Thor <author@example.com>
179 Date: Thu Apr 7 15:15:13 2005 -0700
181 ${indent}3rd
183 Notes:
184 ${indent}b3
185 ${indent}c3c3c3c3
186 ${indent}d3d3d3
189 cat expect >>expect-multiline &&
190 git log -2 >actual &&
191 test_cmp expect-multiline actual
194 test_expect_success 'show -F notes' '
195 test_commit 4th &&
196 echo "xyzzy" >note5 &&
197 git notes add -F note5 &&
198 commit=$(git rev-parse HEAD) &&
199 cat >expect-F <<-EOF &&
200 commit $commit
201 Author: A U Thor <author@example.com>
202 Date: Thu Apr 7 15:16:13 2005 -0700
204 ${indent}4th
206 Notes:
207 ${indent}xyzzy
210 cat expect-multiline >>expect-F &&
211 git log -3 >actual &&
212 test_cmp expect-F actual
215 test_expect_success 'Re-adding -F notes without -f fails' '
216 echo "zyxxy" >note5 &&
217 test_must_fail git notes add -F note5 &&
218 git log -3 >actual &&
219 test_cmp expect-F actual
222 test_expect_success 'git log --pretty=raw does not show notes' '
223 commit=$(git rev-parse HEAD) &&
224 tree=$(git rev-parse HEAD^{tree}) &&
225 parent=$(git rev-parse HEAD^) &&
226 cat >expect <<-EOF &&
227 commit $commit
228 tree $tree
229 parent $parent
230 author A U Thor <author@example.com> 1112912173 -0700
231 committer C O Mitter <committer@example.com> 1112912173 -0700
233 ${indent}4th
235 git log -1 --pretty=raw >actual &&
236 test_cmp expect actual
239 test_expect_success 'git log --show-notes' '
240 cat >>expect <<-EOF &&
242 Notes:
243 ${indent}xyzzy
245 git log -1 --pretty=raw --show-notes >actual &&
246 test_cmp expect actual
249 test_expect_success 'git log --no-notes' '
250 git log -1 --no-notes >actual &&
251 ! grep xyzzy actual
254 test_expect_success 'git format-patch does not show notes' '
255 git format-patch -1 --stdout >actual &&
256 ! grep xyzzy actual
259 test_expect_success 'git format-patch --show-notes does show notes' '
260 git format-patch --show-notes -1 --stdout >actual &&
261 grep xyzzy actual
264 for pretty in \
265 "" --pretty --pretty=raw --pretty=short --pretty=medium \
266 --pretty=full --pretty=fuller --pretty=format:%s --oneline
268 case "$pretty" in
269 "") p= not= negate="" ;;
270 ?*) p="$pretty" not=" not" negate="!" ;;
271 esac
272 test_expect_success "git show $pretty does$not show notes" '
273 git show $p >actual &&
274 eval "$negate grep xyzzy actual"
276 done
278 test_expect_success 'setup alternate notes ref' '
279 git notes --ref=alternate add -m alternate
282 test_expect_success 'git log --notes shows default notes' '
283 git log -1 --notes >actual &&
284 grep xyzzy actual &&
285 ! grep alternate actual
288 test_expect_success 'git log --notes=X shows only X' '
289 git log -1 --notes=alternate >actual &&
290 ! grep xyzzy actual &&
291 grep alternate actual
294 test_expect_success 'git log --notes --notes=X shows both' '
295 git log -1 --notes --notes=alternate >actual &&
296 grep xyzzy actual &&
297 grep alternate actual
300 test_expect_success 'git log --no-notes resets default state' '
301 git log -1 --notes --notes=alternate \
302 --no-notes --notes=alternate \
303 >actual &&
304 ! grep xyzzy actual &&
305 grep alternate actual
308 test_expect_success 'git log --no-notes resets ref list' '
309 git log -1 --notes --notes=alternate \
310 --no-notes --notes \
311 >actual &&
312 grep xyzzy actual &&
313 ! grep alternate actual
316 test_expect_success 'show -m notes' '
317 test_commit 5th &&
318 git notes add -m spam -m "foo${LF}bar${LF}baz" &&
319 commit=$(git rev-parse HEAD) &&
320 cat >expect-m <<-EOF &&
321 commit $commit
322 Author: A U Thor <author@example.com>
323 Date: Thu Apr 7 15:17:13 2005 -0700
325 ${indent}5th
327 Notes:
328 ${indent}spam
329 ${indent}
330 ${indent}foo
331 ${indent}bar
332 ${indent}baz
335 cat expect-F >>expect-m &&
336 git log -4 >actual &&
337 test_cmp expect-m actual
340 test_expect_success 'remove note with add -f -F /dev/null' '
341 git notes add -f -F /dev/null &&
342 commit=$(git rev-parse HEAD) &&
343 cat >expect-rm-F <<-EOF &&
344 commit $commit
345 Author: A U Thor <author@example.com>
346 Date: Thu Apr 7 15:17:13 2005 -0700
348 ${indent}5th
351 cat expect-F >>expect-rm-F &&
352 git log -4 >actual &&
353 test_cmp expect-rm-F actual &&
354 test_must_fail git notes show
357 test_expect_success 'do not create empty note with -m ""' '
358 git notes add -m "" &&
359 git log -4 >actual &&
360 test_cmp expect-rm-F actual &&
361 test_must_fail git notes show
364 test_expect_success 'create note with combination of -m and -F' '
365 test_when_finished git notes remove HEAD &&
366 cat >expect-combine_m_and_F <<-EOF &&
369 xyzzy
373 zyxxy
377 echo "xyzzy" >note_a &&
378 echo "zyxxy" >note_b &&
379 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
380 git notes show >actual &&
381 test_cmp expect-combine_m_and_F actual
384 test_expect_success 'create note with combination of -m and -F and --separator' '
385 test_when_finished git notes remove HEAD &&
386 cat >expect-combine_m_and_F <<-\EOF &&
388 -------
389 xyzzy
390 -------
392 -------
393 zyxxy
394 -------
397 echo "xyzzy" >note_a &&
398 echo "zyxxy" >note_b &&
399 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --separator="-------" &&
400 git notes show >actual &&
401 test_cmp expect-combine_m_and_F actual
404 test_expect_success 'create note with combination of -m and -F and --no-separator' '
405 cat >expect-combine_m_and_F <<-\EOF &&
407 xyzzy
409 zyxxy
412 echo "xyzzy" >note_a &&
413 echo "zyxxy" >note_b &&
414 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --no-separator &&
415 git notes show >actual &&
416 test_cmp expect-combine_m_and_F actual
419 test_expect_success 'remove note with "git notes remove"' '
420 git notes remove HEAD^ &&
421 git notes remove &&
422 commit=$(git rev-parse HEAD) &&
423 parent=$(git rev-parse HEAD^) &&
424 cat >expect-rm-remove <<-EOF &&
425 commit $commit
426 Author: A U Thor <author@example.com>
427 Date: Thu Apr 7 15:17:13 2005 -0700
429 ${indent}5th
431 commit $parent
432 Author: A U Thor <author@example.com>
433 Date: Thu Apr 7 15:16:13 2005 -0700
435 ${indent}4th
438 cat expect-multiline >>expect-rm-remove &&
439 git log -4 >actual &&
440 test_cmp expect-rm-remove actual &&
441 test_must_fail git notes show HEAD^
444 test_expect_success 'removing non-existing note should not create new commit' '
445 git rev-parse --verify refs/notes/commits >before_commit &&
446 test_must_fail git notes remove HEAD^ &&
447 git rev-parse --verify refs/notes/commits >after_commit &&
448 test_cmp before_commit after_commit
451 test_expect_success 'removing more than one' '
452 before=$(git rev-parse --verify refs/notes/commits) &&
453 test_when_finished "git update-ref refs/notes/commits $before" &&
455 # We have only two -- add another and make sure it stays
456 git notes add -m "extra" &&
457 git notes list HEAD >after-removal-expect &&
458 git notes remove HEAD^^ HEAD^^^ &&
459 git notes list | sed -e "s/ .*//" >actual &&
460 test_cmp after-removal-expect actual
463 test_expect_success 'removing is atomic' '
464 before=$(git rev-parse --verify refs/notes/commits) &&
465 test_when_finished "git update-ref refs/notes/commits $before" &&
466 test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
467 after=$(git rev-parse --verify refs/notes/commits) &&
468 test "$before" = "$after"
471 test_expect_success 'removing with --ignore-missing' '
472 before=$(git rev-parse --verify refs/notes/commits) &&
473 test_when_finished "git update-ref refs/notes/commits $before" &&
475 # We have only two -- add another and make sure it stays
476 git notes add -m "extra" &&
477 git notes list HEAD >after-removal-expect &&
478 git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
479 git notes list | sed -e "s/ .*//" >actual &&
480 test_cmp after-removal-expect actual
483 test_expect_success 'removing with --ignore-missing but bogus ref' '
484 before=$(git rev-parse --verify refs/notes/commits) &&
485 test_when_finished "git update-ref refs/notes/commits $before" &&
486 test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
487 after=$(git rev-parse --verify refs/notes/commits) &&
488 test "$before" = "$after"
491 test_expect_success 'remove reads from --stdin' '
492 before=$(git rev-parse --verify refs/notes/commits) &&
493 test_when_finished "git update-ref refs/notes/commits $before" &&
495 # We have only two -- add another and make sure it stays
496 git notes add -m "extra" &&
497 git notes list HEAD >after-removal-expect &&
498 git rev-parse HEAD^^ HEAD^^^ >input &&
499 git notes remove --stdin <input &&
500 git notes list | sed -e "s/ .*//" >actual &&
501 test_cmp after-removal-expect actual
504 test_expect_success 'remove --stdin is also atomic' '
505 before=$(git rev-parse --verify refs/notes/commits) &&
506 test_when_finished "git update-ref refs/notes/commits $before" &&
507 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
508 test_must_fail git notes remove --stdin <input &&
509 after=$(git rev-parse --verify refs/notes/commits) &&
510 test "$before" = "$after"
513 test_expect_success 'removing with --stdin --ignore-missing' '
514 before=$(git rev-parse --verify refs/notes/commits) &&
515 test_when_finished "git update-ref refs/notes/commits $before" &&
517 # We have only two -- add another and make sure it stays
518 git notes add -m "extra" &&
519 git notes list HEAD >after-removal-expect &&
520 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
521 git notes remove --ignore-missing --stdin <input &&
522 git notes list | sed -e "s/ .*//" >actual &&
523 test_cmp after-removal-expect actual
526 test_expect_success 'list notes with "git notes list"' '
527 commit_2=$(git rev-parse 2nd) &&
528 commit_3=$(git rev-parse 3rd) &&
529 note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
530 note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
531 sort -t" " -k2 >expect <<-EOF &&
532 $note_2 $commit_2
533 $note_3 $commit_3
535 git notes list >actual &&
536 test_cmp expect actual
539 test_expect_success 'list notes with "git notes"' '
540 git notes >actual &&
541 test_cmp expect actual
544 test_expect_success '"git notes" without subcommand does not take arguments' '
545 test_expect_code 129 git notes HEAD^^ 2>err &&
546 grep "^error: unknown subcommand" err
549 test_expect_success 'list specific note with "git notes list <object>"' '
550 git rev-parse refs/notes/commits:$commit_3 >expect &&
551 git notes list HEAD^^ >actual &&
552 test_cmp expect actual
555 test_expect_success 'listing non-existing notes fails' '
556 test_must_fail git notes list HEAD >actual &&
557 test_must_be_empty actual
560 test_expect_success 'append: specify a separator with an empty arg' '
561 test_when_finished git notes remove HEAD &&
562 cat >expect <<-\EOF &&
563 notes-1
565 notes-2
568 git notes add -m "notes-1" &&
569 git notes append --separator="" -m "notes-2" &&
570 git notes show >actual &&
571 test_cmp expect actual
574 test_expect_success 'append: specify a separator without arg' '
575 test_when_finished git notes remove HEAD &&
576 cat >expect <<-\EOF &&
577 notes-1
579 notes-2
582 git notes add -m "notes-1" &&
583 git notes append --separator -m "notes-2" &&
584 git notes show >actual &&
585 test_cmp expect actual
588 test_expect_success 'append: specify as --no-separator' '
589 test_when_finished git notes remove HEAD &&
590 cat >expect <<-\EOF &&
591 notes-1
592 notes-2
595 git notes add -m "notes-1" &&
596 git notes append --no-separator -m "notes-2" &&
597 git notes show >actual &&
598 test_cmp expect actual
601 test_expect_success 'append: specify separator with line break' '
602 test_when_finished git notes remove HEAD &&
603 cat >expect <<-\EOF &&
604 notes-1
605 -------
606 notes-2
609 git notes add -m "notes-1" &&
610 git notes append --separator="-------$LF" -m "notes-2" &&
611 git notes show >actual &&
612 test_cmp expect actual
615 test_expect_success 'append: specify separator without line break' '
616 test_when_finished git notes remove HEAD &&
617 cat >expect <<-\EOF &&
618 notes-1
619 -------
620 notes-2
623 git notes add -m "notes-1" &&
624 git notes append --separator="-------" -m "notes-2" &&
625 git notes show >actual &&
626 test_cmp expect actual
629 test_expect_success 'append: specify separator with multiple messages' '
630 test_when_finished git notes remove HEAD &&
631 cat >expect <<-\EOF &&
632 notes-1
633 -------
634 notes-2
635 -------
636 notes-3
639 git notes add -m "notes-1" &&
640 git notes append --separator="-------" -m "notes-2" -m "notes-3" &&
641 git notes show >actual &&
642 test_cmp expect actual
645 test_expect_success 'append note with combination of -m and -F and --separator' '
646 test_when_finished git notes remove HEAD &&
647 cat >expect-combine_m_and_F <<-\EOF &&
648 m-notes-1
649 -------
650 f-notes-1
651 -------
652 m-notes-2
653 -------
654 f-notes-2
655 -------
656 m-notes-3
659 echo "f-notes-1" >note_a &&
660 echo "f-notes-2" >note_b &&
661 git notes append -m "m-notes-1" -F note_a -m "m-notes-2" -F note_b -m "m-notes-3" --separator="-------" &&
662 git notes show >actual &&
663 test_cmp expect-combine_m_and_F actual
666 test_expect_success 'append to existing note with "git notes append"' '
667 cat >expect <<-EOF &&
668 Initial set of notes
670 More notes appended with git notes append
672 git notes add -m "Initial set of notes" &&
673 git notes append -m "More notes appended with git notes append" &&
674 git notes show >actual &&
675 test_cmp expect actual
678 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
679 commit_5=$(git rev-parse 5th) &&
680 note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
681 sort -t" " -k2 >expect_list <<-EOF &&
682 $note_2 $commit_2
683 $note_3 $commit_3
684 $note_5 $commit_5
686 git notes list >actual &&
687 test_cmp expect_list actual
690 test_expect_success 'appending empty string does not change existing note' '
691 git notes append -m "" &&
692 git notes show >actual &&
693 test_cmp expect actual
696 test_expect_success 'git notes append == add when there is no existing note' '
697 git notes remove HEAD &&
698 test_must_fail git notes list HEAD &&
699 git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
700 git notes show >actual &&
701 test_cmp expect actual
704 test_expect_success 'appending empty string to non-existing note does not create note' '
705 git notes remove HEAD &&
706 test_must_fail git notes list HEAD &&
707 git notes append -m "" &&
708 test_must_fail git notes list HEAD
711 test_expect_success 'create other note on a different notes ref (setup)' '
712 test_commit 6th &&
713 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
714 commit=$(git rev-parse HEAD) &&
715 cat >expect-not-other <<-EOF &&
716 commit $commit
717 Author: A U Thor <author@example.com>
718 Date: Thu Apr 7 15:18:13 2005 -0700
720 ${indent}6th
722 cp expect-not-other expect-other &&
723 cat >>expect-other <<-EOF
725 Notes (other):
726 ${indent}other note
730 test_expect_success 'Do not show note on other ref by default' '
731 git log -1 >actual &&
732 test_cmp expect-not-other actual
735 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
736 GIT_NOTES_REF="refs/notes/other" git log -1 >actual &&
737 test_cmp expect-other actual
740 test_expect_success 'Do show note when ref is given in core.notesRef config' '
741 test_config core.notesRef "refs/notes/other" &&
742 git log -1 >actual &&
743 test_cmp expect-other actual
746 test_expect_success 'Do not show note when core.notesRef is overridden' '
747 test_config core.notesRef "refs/notes/other" &&
748 GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual &&
749 test_cmp expect-not-other actual
752 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
753 commit=$(git rev-parse HEAD) &&
754 parent=$(git rev-parse HEAD^) &&
755 cat >expect-both <<-EOF &&
756 commit $commit
757 Author: A U Thor <author@example.com>
758 Date: Thu Apr 7 15:18:13 2005 -0700
760 ${indent}6th
762 Notes:
763 ${indent}order test
765 Notes (other):
766 ${indent}other note
768 commit $parent
769 Author: A U Thor <author@example.com>
770 Date: Thu Apr 7 15:17:13 2005 -0700
772 ${indent}5th
774 Notes:
775 ${indent}replacement for deleted note
777 GIT_NOTES_REF=refs/notes/commits git notes add \
778 -m"replacement for deleted note" HEAD^ &&
779 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
780 test_unconfig core.notesRef &&
781 test_config notes.displayRef "refs/notes/*" &&
782 git log -2 >actual &&
783 test_cmp expect-both actual
786 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
787 test_config core.notesRef refs/notes/commits &&
788 test_config notes.displayRef refs/notes/other &&
789 git log -2 >actual &&
790 test_cmp expect-both actual
793 test_expect_success 'notes.displayRef can be given more than once' '
794 test_unconfig core.notesRef &&
795 test_config notes.displayRef refs/notes/commits &&
796 git config --add notes.displayRef refs/notes/other &&
797 git log -2 >actual &&
798 test_cmp expect-both actual
801 test_expect_success 'notes.displayRef respects order' '
802 commit=$(git rev-parse HEAD) &&
803 cat >expect-both-reversed <<-EOF &&
804 commit $commit
805 Author: A U Thor <author@example.com>
806 Date: Thu Apr 7 15:18:13 2005 -0700
808 ${indent}6th
810 Notes (other):
811 ${indent}other note
813 Notes:
814 ${indent}order test
816 test_config core.notesRef refs/notes/other &&
817 test_config notes.displayRef refs/notes/commits &&
818 git log -1 >actual &&
819 test_cmp expect-both-reversed actual
822 test_expect_success 'notes.displayRef with no value handled gracefully' '
823 test_must_fail git -c notes.displayRef log -0 --notes &&
824 test_must_fail git -c notes.displayRef diff-tree --notes HEAD
827 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
828 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
829 git log -2 >actual &&
830 test_cmp expect-both actual
833 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
834 commit=$(git rev-parse HEAD) &&
835 parent=$(git rev-parse HEAD^) &&
836 cat >expect-none <<-EOF &&
837 commit $commit
838 Author: A U Thor <author@example.com>
839 Date: Thu Apr 7 15:18:13 2005 -0700
841 ${indent}6th
843 commit $parent
844 Author: A U Thor <author@example.com>
845 Date: Thu Apr 7 15:17:13 2005 -0700
847 ${indent}5th
849 test_config notes.displayRef "refs/notes/*" &&
850 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual &&
851 test_cmp expect-none actual
854 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
855 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual &&
856 test_cmp expect-both actual
859 test_expect_success '--no-standard-notes' '
860 commit=$(git rev-parse HEAD) &&
861 cat >expect-commits <<-EOF &&
862 commit $commit
863 Author: A U Thor <author@example.com>
864 Date: Thu Apr 7 15:18:13 2005 -0700
866 ${indent}6th
868 Notes:
869 ${indent}order test
871 git log --no-standard-notes --show-notes=commits -1 >actual &&
872 test_cmp expect-commits actual
875 test_expect_success '--standard-notes' '
876 test_config notes.displayRef "refs/notes/*" &&
877 git log --no-standard-notes --show-notes=commits \
878 --standard-notes -2 >actual &&
879 test_cmp expect-both actual
882 test_expect_success '--show-notes=ref accumulates' '
883 git log --show-notes=other --show-notes=commits \
884 --no-standard-notes -1 >actual &&
885 test_cmp expect-both-reversed actual
888 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
889 test_config core.notesRef refs/notes/other &&
890 echo "Note on a tree" >expect &&
891 git notes add -m "Note on a tree" HEAD: &&
892 git notes show HEAD: >actual &&
893 test_cmp expect actual &&
894 echo "Note on a blob" >expect &&
895 git ls-tree --name-only HEAD >files &&
896 filename=$(head -n1 files) &&
897 git notes add -m "Note on a blob" HEAD:$filename &&
898 git notes show HEAD:$filename >actual &&
899 test_cmp expect actual &&
900 echo "Note on a tag" >expect &&
901 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
902 git notes add -m "Note on a tag" foobar &&
903 git notes show foobar >actual &&
904 test_cmp expect actual
907 test_expect_success 'create note from other note with "git notes add -C"' '
908 test_commit 7th &&
909 commit=$(git rev-parse HEAD) &&
910 cat >expect <<-EOF &&
911 commit $commit
912 Author: A U Thor <author@example.com>
913 Date: Thu Apr 7 15:19:13 2005 -0700
915 ${indent}7th
917 Notes:
918 ${indent}order test
920 note=$(git notes list HEAD^) &&
921 git notes add -C $note &&
922 git log -1 >actual &&
923 test_cmp expect actual &&
924 git notes list HEAD^ >expect &&
925 git notes list HEAD >actual &&
926 test_cmp expect actual
929 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
930 test_commit 8th &&
931 test_must_fail git notes add -C deadbeef &&
932 test_must_fail git notes list HEAD
935 test_expect_success 'create note from non-blob with "git notes add -C" fails' '
936 commit=$(git rev-parse --verify HEAD) &&
937 tree=$(git rev-parse --verify HEAD:) &&
938 test_must_fail git notes add -C $commit &&
939 test_must_fail git notes add -C $tree &&
940 test_must_fail git notes list HEAD
943 test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
944 commit=$(git rev-parse HEAD) &&
945 cat >expect <<-EOF &&
946 commit $commit
947 Author: A U Thor <author@example.com>
948 Date: Thu Apr 7 15:20:13 2005 -0700
950 ${indent}8th
952 Notes:
953 ${indent}This is a blob object
955 echo "This is a blob object" | git hash-object -w --stdin >blob &&
956 git notes add -C $(cat blob) &&
957 git log -1 >actual &&
958 test_cmp expect actual &&
959 git notes list HEAD >actual &&
960 test_cmp blob actual
963 test_expect_success 'create note from blob with "-C", also specify "-m", "-F" and "--separator"' '
964 # 8th will be reuseed in following tests, so rollback when the test is done
965 test_when_finished "git notes remove && git notes add -C $(cat blob)" &&
966 commit=$(git rev-parse HEAD) &&
967 cat >expect <<-EOF &&
968 commit $commit
969 Author: A U Thor <author@example.com>
970 Date: Thu Apr 7 15:20:13 2005 -0700
972 ${indent}8th
974 Notes:
975 ${indent}This is a blob object
976 ${indent}-------
977 ${indent}This is created by -m
978 ${indent}-------
979 ${indent}This is created by -F
982 git notes remove &&
983 echo "This is a blob object" | git hash-object -w --stdin >blob &&
984 echo "This is created by -F" >note_a &&
985 git notes add -C $(cat blob) -m "This is created by -m" -F note_a --separator="-------" &&
986 git log -1 >actual &&
987 test_cmp expect actual
990 test_expect_success 'create note from other note with "git notes add -c"' '
991 test_commit 9th &&
992 commit=$(git rev-parse HEAD) &&
993 cat >expect <<-EOF &&
994 commit $commit
995 Author: A U Thor <author@example.com>
996 Date: Thu Apr 7 15:21:13 2005 -0700
998 ${indent}9th
1000 Notes:
1001 ${indent}yet another note
1003 note=$(git notes list HEAD^^) &&
1004 MSG="yet another note" git notes add -c $note &&
1005 git log -1 >actual &&
1006 test_cmp expect actual
1009 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
1010 test_commit 10th &&
1011 test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
1012 test_must_fail git notes list HEAD
1015 test_expect_success 'append to note from other note with "git notes append -C"' '
1016 commit=$(git rev-parse HEAD^) &&
1017 cat >expect <<-EOF &&
1018 commit $commit
1019 Author: A U Thor <author@example.com>
1020 Date: Thu Apr 7 15:21:13 2005 -0700
1022 ${indent}9th
1024 Notes:
1025 ${indent}yet another note
1026 ${indent}
1027 ${indent}yet another note
1029 note=$(git notes list HEAD^) &&
1030 git notes append -C $note HEAD^ &&
1031 git log -1 HEAD^ >actual &&
1032 test_cmp expect actual
1035 test_expect_success 'create note from other note with "git notes append -c"' '
1036 commit=$(git rev-parse HEAD) &&
1037 cat >expect <<-EOF &&
1038 commit $commit
1039 Author: A U Thor <author@example.com>
1040 Date: Thu Apr 7 15:22:13 2005 -0700
1042 ${indent}10th
1044 Notes:
1045 ${indent}other note
1047 note=$(git notes list HEAD^) &&
1048 MSG="other note" git notes append -c $note &&
1049 git log -1 >actual &&
1050 test_cmp expect actual
1053 test_expect_success 'append to note from other note with "git notes append -c"' '
1054 commit=$(git rev-parse HEAD) &&
1055 cat >expect <<-EOF &&
1056 commit $commit
1057 Author: A U Thor <author@example.com>
1058 Date: Thu Apr 7 15:22:13 2005 -0700
1060 ${indent}10th
1062 Notes:
1063 ${indent}other note
1064 ${indent}
1065 ${indent}yet another note
1067 note=$(git notes list HEAD) &&
1068 MSG="yet another note" git notes append -c $note &&
1069 git log -1 >actual &&
1070 test_cmp expect actual
1073 test_expect_success 'copy note with "git notes copy"' '
1074 commit=$(git rev-parse 4th) &&
1075 cat >expect <<-EOF &&
1076 commit $commit
1077 Author: A U Thor <author@example.com>
1078 Date: Thu Apr 7 15:16:13 2005 -0700
1080 ${indent}4th
1082 Notes:
1083 ${indent}This is a blob object
1085 git notes copy 8th 4th &&
1086 git log 3rd..4th >actual &&
1087 test_cmp expect actual &&
1088 git notes list 4th >expect &&
1089 git notes list 8th >actual &&
1090 test_cmp expect actual
1093 test_expect_success 'copy note with "git notes copy" with default' '
1094 test_commit 11th &&
1095 commit=$(git rev-parse HEAD) &&
1096 cat >expect <<-EOF &&
1097 commit $commit
1098 Author: A U Thor <author@example.com>
1099 Date: Thu Apr 7 15:23:13 2005 -0700
1101 ${indent}11th
1103 Notes:
1104 ${indent}other note
1105 ${indent}
1106 ${indent}yet another note
1108 git notes copy HEAD^ &&
1109 git log -1 >actual &&
1110 test_cmp expect actual &&
1111 git notes list HEAD^ >expect &&
1112 git notes list HEAD >actual &&
1113 test_cmp expect actual
1116 test_expect_success 'prevent overwrite with "git notes copy"' '
1117 test_must_fail git notes copy HEAD~2 HEAD &&
1118 cat >expect <<-EOF &&
1119 commit $commit
1120 Author: A U Thor <author@example.com>
1121 Date: Thu Apr 7 15:23:13 2005 -0700
1123 ${indent}11th
1125 Notes:
1126 ${indent}other note
1127 ${indent}
1128 ${indent}yet another note
1130 git log -1 >actual &&
1131 test_cmp expect actual &&
1132 git notes list HEAD^ >expect &&
1133 git notes list HEAD >actual &&
1134 test_cmp expect actual
1137 test_expect_success 'allow overwrite with "git notes copy -f"' '
1138 commit=$(git rev-parse HEAD) &&
1139 cat >expect <<-EOF &&
1140 commit $commit
1141 Author: A U Thor <author@example.com>
1142 Date: Thu Apr 7 15:23:13 2005 -0700
1144 ${indent}11th
1146 Notes:
1147 ${indent}This is a blob object
1149 git notes copy -f HEAD~3 HEAD &&
1150 git log -1 >actual &&
1151 test_cmp expect actual &&
1152 git notes list HEAD~3 >expect &&
1153 git notes list HEAD >actual &&
1154 test_cmp expect actual
1157 test_expect_success 'allow overwrite with "git notes copy -f" with default' '
1158 commit=$(git rev-parse HEAD) &&
1159 cat >expect <<-EOF &&
1160 commit $commit
1161 Author: A U Thor <author@example.com>
1162 Date: Thu Apr 7 15:23:13 2005 -0700
1164 ${indent}11th
1166 Notes:
1167 ${indent}yet another note
1168 ${indent}
1169 ${indent}yet another note
1171 git notes copy -f HEAD~2 &&
1172 git log -1 >actual &&
1173 test_cmp expect actual &&
1174 git notes list HEAD~2 >expect &&
1175 git notes list HEAD >actual &&
1176 test_cmp expect actual
1179 test_expect_success 'cannot copy note from object without notes' '
1180 test_commit 12th &&
1181 test_commit 13th &&
1182 test_must_fail git notes copy HEAD^ HEAD
1185 test_expect_success 'git notes copy --stdin' '
1186 commit=$(git rev-parse HEAD) &&
1187 parent=$(git rev-parse HEAD^) &&
1188 cat >expect <<-EOF &&
1189 commit $commit
1190 Author: A U Thor <author@example.com>
1191 Date: Thu Apr 7 15:25:13 2005 -0700
1193 ${indent}13th
1195 Notes:
1196 ${indent}yet another note
1197 ${indent}
1198 ${indent}yet another note
1200 commit $parent
1201 Author: A U Thor <author@example.com>
1202 Date: Thu Apr 7 15:24:13 2005 -0700
1204 ${indent}12th
1206 Notes:
1207 ${indent}other note
1208 ${indent}
1209 ${indent}yet another note
1211 from=$(git rev-parse HEAD~3) &&
1212 to=$(git rev-parse HEAD^) &&
1213 echo "$from" "$to" >copy &&
1214 from=$(git rev-parse HEAD~2) &&
1215 to=$(git rev-parse HEAD) &&
1216 echo "$from" "$to" >>copy &&
1217 git notes copy --stdin <copy &&
1218 git log -2 >actual &&
1219 test_cmp expect actual &&
1220 git notes list HEAD~2 >expect &&
1221 git notes list HEAD >actual &&
1222 test_cmp expect actual &&
1223 git notes list HEAD~3 >expect &&
1224 git notes list HEAD^ >actual &&
1225 test_cmp expect actual
1228 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
1229 test_commit 14th &&
1230 test_commit 15th &&
1231 commit=$(git rev-parse HEAD) &&
1232 parent=$(git rev-parse HEAD^) &&
1233 cat >expect <<-EOF &&
1234 commit $commit
1235 Author: A U Thor <author@example.com>
1236 Date: Thu Apr 7 15:27:13 2005 -0700
1238 ${indent}15th
1240 commit $parent
1241 Author: A U Thor <author@example.com>
1242 Date: Thu Apr 7 15:26:13 2005 -0700
1244 ${indent}14th
1246 from=$(git rev-parse HEAD~3) &&
1247 to=$(git rev-parse HEAD^) &&
1248 echo "$from" "$to" >copy &&
1249 from=$(git rev-parse HEAD~2) &&
1250 to=$(git rev-parse HEAD) &&
1251 echo "$from" "$to" >>copy &&
1252 git notes copy --for-rewrite=foo <copy &&
1253 git log -2 >actual &&
1254 test_cmp expect actual
1257 test_expect_success 'git notes copy --for-rewrite (enabled)' '
1258 commit=$(git rev-parse HEAD) &&
1259 parent=$(git rev-parse HEAD^) &&
1260 cat >expect <<-EOF &&
1261 commit $commit
1262 Author: A U Thor <author@example.com>
1263 Date: Thu Apr 7 15:27:13 2005 -0700
1265 ${indent}15th
1267 Notes:
1268 ${indent}yet another note
1269 ${indent}
1270 ${indent}yet another note
1272 commit $parent
1273 Author: A U Thor <author@example.com>
1274 Date: Thu Apr 7 15:26:13 2005 -0700
1276 ${indent}14th
1278 Notes:
1279 ${indent}other note
1280 ${indent}
1281 ${indent}yet another note
1283 test_config notes.rewriteMode overwrite &&
1284 test_config notes.rewriteRef "refs/notes/*" &&
1285 from=$(git rev-parse HEAD~3) &&
1286 to=$(git rev-parse HEAD^) &&
1287 echo "$from" "$to" >copy &&
1288 from=$(git rev-parse HEAD~2) &&
1289 to=$(git rev-parse HEAD) &&
1290 echo "$from" "$to" >>copy &&
1291 git notes copy --for-rewrite=foo <copy &&
1292 git log -2 >actual &&
1293 test_cmp expect actual
1296 test_expect_success 'git notes copy --for-rewrite (disabled)' '
1297 test_config notes.rewrite.bar false &&
1298 from=$(git rev-parse HEAD~3) &&
1299 to=$(git rev-parse HEAD) &&
1300 echo "$from" "$to" >copy &&
1301 git notes copy --for-rewrite=bar <copy &&
1302 git log -2 >actual &&
1303 test_cmp expect actual
1306 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
1307 commit=$(git rev-parse HEAD) &&
1308 cat >expect <<-EOF &&
1309 commit $commit
1310 Author: A U Thor <author@example.com>
1311 Date: Thu Apr 7 15:27:13 2005 -0700
1313 ${indent}15th
1315 Notes:
1316 ${indent}a fresh note
1318 git notes add -f -m"a fresh note" HEAD^ &&
1319 test_config notes.rewriteMode overwrite &&
1320 test_config notes.rewriteRef "refs/notes/*" &&
1321 from=$(git rev-parse HEAD^) &&
1322 to=$(git rev-parse HEAD) &&
1323 echo "$from" "$to" >copy &&
1324 git notes copy --for-rewrite=foo <copy &&
1325 git log -1 >actual &&
1326 test_cmp expect actual
1329 test_expect_success 'git notes copy --for-rewrite (ignore)' '
1330 test_config notes.rewriteMode ignore &&
1331 test_config notes.rewriteRef "refs/notes/*" &&
1332 from=$(git rev-parse HEAD^) &&
1333 to=$(git rev-parse HEAD) &&
1334 echo "$from" "$to" >copy &&
1335 git notes copy --for-rewrite=foo <copy &&
1336 git log -1 >actual &&
1337 test_cmp expect actual
1340 test_expect_success 'git notes copy --for-rewrite (append)' '
1341 commit=$(git rev-parse HEAD) &&
1342 cat >expect <<-EOF &&
1343 commit $commit
1344 Author: A U Thor <author@example.com>
1345 Date: Thu Apr 7 15:27:13 2005 -0700
1347 ${indent}15th
1349 Notes:
1350 ${indent}a fresh note
1351 ${indent}
1352 ${indent}another fresh note
1354 git notes add -f -m"another fresh note" HEAD^ &&
1355 test_config notes.rewriteMode concatenate &&
1356 test_config notes.rewriteRef "refs/notes/*" &&
1357 from=$(git rev-parse HEAD^) &&
1358 to=$(git rev-parse HEAD) &&
1359 echo "$from" "$to" >copy &&
1360 git notes copy --for-rewrite=foo <copy &&
1361 git log -1 >actual &&
1362 test_cmp expect actual
1365 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1366 commit=$(git rev-parse HEAD) &&
1367 cat >expect <<-EOF &&
1368 commit $commit
1369 Author: A U Thor <author@example.com>
1370 Date: Thu Apr 7 15:27:13 2005 -0700
1372 ${indent}15th
1374 Notes:
1375 ${indent}a fresh note
1376 ${indent}
1377 ${indent}another fresh note
1378 ${indent}
1379 ${indent}append 1
1380 ${indent}
1381 ${indent}append 2
1383 git notes add -f -m"append 1" HEAD^ &&
1384 git notes add -f -m"append 2" HEAD^^ &&
1385 test_config notes.rewriteMode concatenate &&
1386 test_config notes.rewriteRef "refs/notes/*" &&
1387 from=$(git rev-parse HEAD^) &&
1388 to=$(git rev-parse HEAD) &&
1389 echo "$from" "$to" >copy &&
1390 from=$(git rev-parse HEAD^^) &&
1391 to=$(git rev-parse HEAD) &&
1392 echo "$from" "$to" >>copy &&
1393 git notes copy --for-rewrite=foo <copy &&
1394 git log -1 >actual &&
1395 test_cmp expect actual
1398 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1399 git notes remove HEAD^ &&
1400 test_config notes.rewriteMode concatenate &&
1401 test_config notes.rewriteRef "refs/notes/*" &&
1402 from=$(git rev-parse HEAD^) &&
1403 to=$(git rev-parse HEAD) &&
1404 echo "$from" "$to" >copy &&
1405 git notes copy --for-rewrite=foo <copy &&
1406 git log -1 >actual &&
1407 test_cmp expect actual
1410 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1411 commit=$(git rev-parse HEAD) &&
1412 cat >expect <<-EOF &&
1413 commit $commit
1414 Author: A U Thor <author@example.com>
1415 Date: Thu Apr 7 15:27:13 2005 -0700
1417 ${indent}15th
1419 Notes:
1420 ${indent}replacement note 1
1422 test_config notes.rewriteMode concatenate &&
1423 test_config notes.rewriteRef "refs/notes/*" &&
1424 git notes add -f -m"replacement note 1" HEAD^ &&
1425 from=$(git rev-parse HEAD^) &&
1426 to=$(git rev-parse HEAD) &&
1427 echo "$from" "$to" >copy &&
1428 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
1429 git log -1 >actual &&
1430 test_cmp expect actual
1433 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1434 commit=$(git rev-parse HEAD) &&
1435 cat >expect <<-EOF &&
1436 commit $commit
1437 Author: A U Thor <author@example.com>
1438 Date: Thu Apr 7 15:27:13 2005 -0700
1440 ${indent}15th
1442 Notes:
1443 ${indent}replacement note 2
1445 git notes add -f -m"replacement note 2" HEAD^ &&
1446 test_config notes.rewriteMode overwrite &&
1447 test_unconfig notes.rewriteRef &&
1448 from=$(git rev-parse HEAD^) &&
1449 to=$(git rev-parse HEAD) &&
1450 echo "$from" "$to" >copy &&
1451 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1452 git notes copy --for-rewrite=foo <copy &&
1453 git log -1 >actual &&
1454 test_cmp expect actual
1457 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1458 git notes add -f -m"replacement note 3" HEAD^ &&
1459 test_config notes.rewriteMode overwrite &&
1460 test_config notes.rewriteRef refs/notes/other &&
1461 from=$(git rev-parse HEAD^) &&
1462 to=$(git rev-parse HEAD) &&
1463 echo "$from" "$to" >copy &&
1464 GIT_NOTES_REWRITE_REF=refs/notes/commits \
1465 git notes copy --for-rewrite=foo <copy &&
1466 git log -1 >actual &&
1467 grep "replacement note 3" actual
1470 test_expect_success 'git notes copy diagnoses too many or too few arguments' '
1471 test_must_fail git notes copy 2>error &&
1472 test_grep "too few arguments" error &&
1473 test_must_fail git notes copy one two three 2>error &&
1474 test_grep "too many arguments" error
1477 test_expect_success 'git notes get-ref expands refs/heads/main to refs/notes/refs/heads/main' '
1478 test_unconfig core.notesRef &&
1479 sane_unset GIT_NOTES_REF &&
1480 echo refs/notes/refs/heads/main >expect &&
1481 git notes --ref=refs/heads/main get-ref >actual &&
1482 test_cmp expect actual
1485 test_expect_success 'git notes get-ref (no overrides)' '
1486 test_unconfig core.notesRef &&
1487 sane_unset GIT_NOTES_REF &&
1488 echo refs/notes/commits >expect &&
1489 git notes get-ref >actual &&
1490 test_cmp expect actual
1493 test_expect_success 'git notes get-ref (core.notesRef)' '
1494 test_config core.notesRef refs/notes/foo &&
1495 echo refs/notes/foo >expect &&
1496 git notes get-ref >actual &&
1497 test_cmp expect actual
1500 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1501 echo refs/notes/bar >expect &&
1502 GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
1503 test_cmp expect actual
1506 test_expect_success 'git notes get-ref (--ref)' '
1507 echo refs/notes/baz >expect &&
1508 GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
1509 test_cmp expect actual
1512 test_expect_success 'setup testing of empty notes' '
1513 test_unconfig core.notesRef &&
1514 test_commit 16th &&
1515 empty_blob=$(git hash-object -w /dev/null) &&
1516 echo "$empty_blob" >expect_empty
1519 while read cmd
1521 test_expect_success "'git notes $cmd' removes empty note" "
1522 test_might_fail git notes remove HEAD &&
1523 MSG= git notes $cmd &&
1524 test_must_fail git notes list HEAD
1527 test_expect_success "'git notes $cmd --allow-empty' stores empty note" "
1528 test_might_fail git notes remove HEAD &&
1529 MSG= git notes $cmd --allow-empty &&
1530 git notes list HEAD >actual &&
1531 test_cmp expect_empty actual
1533 done <<\EOF
1535 add -F /dev/null
1536 add -m ""
1537 add -c "$empty_blob"
1538 add -C "$empty_blob"
1539 append
1540 append -F /dev/null
1541 append -m ""
1542 append -c "$empty_blob"
1543 append -C "$empty_blob"
1544 edit
1547 test_expect_success 'empty notes are displayed by git log' '
1548 test_commit 17th &&
1549 git log -1 >expect &&
1550 cat >>expect <<-EOF &&
1552 Notes:
1554 git notes add -C "$empty_blob" --allow-empty &&
1555 git log -1 >actual &&
1556 test_cmp expect actual
1559 test_done