Merge branch 'js/var-git-shell-path'
[git/debian.git] / t / t3301-notes.sh
blob536bd11ff4769f40c50392fb9e684d06b1e6ba83
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test commit notes'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 write_script fake_editor <<\EOF
12 echo "$MSG" >"$1"
13 echo "$MSG" >&2
14 EOF
15 GIT_EDITOR=./fake_editor
16 export GIT_EDITOR
18 indent=" "
20 test_expect_success 'cannot annotate non-existing HEAD' '
21 test_must_fail env MSG=3 git notes add
24 test_expect_success 'setup' '
25 test_commit 1st &&
26 test_commit 2nd
29 test_expect_success 'need valid notes ref' '
30 test_must_fail env MSG=1 GIT_NOTES_REF=/ git notes show &&
31 test_must_fail env MSG=2 GIT_NOTES_REF=/ git notes show
34 test_expect_success 'refusing to add notes in refs/heads/' '
35 test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add
38 test_expect_success 'refusing to edit notes in refs/remotes/' '
39 test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit
42 # 1 indicates caught gracefully by die, 128 means git-show barked
43 test_expect_success 'handle empty notes gracefully' '
44 test_expect_code 1 git notes show
47 test_expect_success 'show non-existent notes entry with %N' '
48 test_write_lines A B >expect &&
49 git show -s --format="A%n%NB" >actual &&
50 test_cmp expect actual
53 test_expect_success 'create notes' '
54 MSG=b4 git notes add &&
55 test_path_is_missing .git/NOTES_EDITMSG &&
56 git ls-tree -r refs/notes/commits >actual &&
57 test_line_count = 1 actual &&
58 echo b4 >expect &&
59 git notes show >actual &&
60 test_cmp expect actual &&
61 git show HEAD^ &&
62 test_must_fail git notes show HEAD^
65 test_expect_success 'show notes entry with %N' '
66 test_write_lines A b4 B >expect &&
67 git show -s --format="A%n%NB" >actual &&
68 test_cmp expect actual
71 test_expect_success 'create reflog entry' '
72 ref=$(git rev-parse --short refs/notes/commits) &&
73 cat <<-EOF >expect &&
74 $ref refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
75 EOF
76 git reflog show refs/notes/commits >actual &&
77 test_cmp expect actual
80 test_expect_success 'edit existing notes' '
81 MSG=b3 git notes edit &&
82 test_path_is_missing .git/NOTES_EDITMSG &&
83 git ls-tree -r refs/notes/commits >actual &&
84 test_line_count = 1 actual &&
85 echo b3 >expect &&
86 git notes show >actual &&
87 test_cmp expect actual &&
88 git show HEAD^ &&
89 test_must_fail git notes show HEAD^
92 test_expect_success 'show notes from treeish' '
93 echo b3 >expect &&
94 git notes --ref commits^{tree} show >actual &&
95 test_cmp expect actual &&
97 echo b4 >expect &&
98 git notes --ref commits@{1} show >actual &&
99 test_cmp expect actual
102 test_expect_success 'cannot edit notes from non-ref' '
103 test_must_fail git notes --ref commits^{tree} edit &&
104 test_must_fail git notes --ref commits@{1} edit
107 test_expect_success 'cannot "git notes add -m" where notes already exists' '
108 test_must_fail git notes add -m "b2" &&
109 test_path_is_missing .git/NOTES_EDITMSG &&
110 git ls-tree -r refs/notes/commits >actual &&
111 test_line_count = 1 actual &&
112 echo b3 >expect &&
113 git notes show >actual &&
114 test_cmp expect actual &&
115 git show HEAD^ &&
116 test_must_fail git notes show HEAD^
119 test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
120 git notes add -f -m "b1" &&
121 test_path_is_missing .git/NOTES_EDITMSG &&
122 git ls-tree -r refs/notes/commits >actual &&
123 test_line_count = 1 actual &&
124 echo b1 >expect &&
125 git notes show >actual &&
126 test_cmp expect actual &&
127 git show HEAD^ &&
128 test_must_fail git notes show HEAD^
131 test_expect_success 'add w/no options on existing note morphs into edit' '
132 MSG=b2 git notes add &&
133 test_path_is_missing .git/NOTES_EDITMSG &&
134 git ls-tree -r refs/notes/commits >actual &&
135 test_line_count = 1 actual &&
136 echo b2 >expect &&
137 git notes show >actual &&
138 test_cmp expect actual &&
139 git show HEAD^ &&
140 test_must_fail git notes show HEAD^
143 test_expect_success 'can overwrite existing note with "git notes add -f"' '
144 MSG=b1 git notes add -f &&
145 test_path_is_missing .git/NOTES_EDITMSG &&
146 git ls-tree -r refs/notes/commits >actual &&
147 test_line_count = 1 actual &&
148 echo b1 >expect &&
149 git notes show >actual &&
150 test_cmp expect actual &&
151 git show HEAD^ &&
152 test_must_fail git notes show HEAD^
155 test_expect_success 'show notes' '
156 commit=$(git rev-parse HEAD) &&
157 cat >expect <<-EOF &&
158 commit $commit
159 Author: A U Thor <author@example.com>
160 Date: Thu Apr 7 15:14:13 2005 -0700
162 ${indent}2nd
164 Notes:
165 ${indent}b1
167 git cat-file commit HEAD >commits &&
168 ! grep b1 commits &&
169 git log -1 >actual &&
170 test_cmp expect actual
173 test_expect_success 'show multi-line notes' '
174 test_commit 3rd &&
175 MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
176 commit=$(git rev-parse HEAD) &&
177 cat >expect-multiline <<-EOF &&
178 commit $commit
179 Author: A U Thor <author@example.com>
180 Date: Thu Apr 7 15:15:13 2005 -0700
182 ${indent}3rd
184 Notes:
185 ${indent}b3
186 ${indent}c3c3c3c3
187 ${indent}d3d3d3
190 cat expect >>expect-multiline &&
191 git log -2 >actual &&
192 test_cmp expect-multiline actual
195 test_expect_success 'show -F notes' '
196 test_commit 4th &&
197 echo "xyzzy" >note5 &&
198 git notes add -F note5 &&
199 commit=$(git rev-parse HEAD) &&
200 cat >expect-F <<-EOF &&
201 commit $commit
202 Author: A U Thor <author@example.com>
203 Date: Thu Apr 7 15:16:13 2005 -0700
205 ${indent}4th
207 Notes:
208 ${indent}xyzzy
211 cat expect-multiline >>expect-F &&
212 git log -3 >actual &&
213 test_cmp expect-F actual
216 test_expect_success 'Re-adding -F notes without -f fails' '
217 echo "zyxxy" >note5 &&
218 test_must_fail git notes add -F note5 &&
219 git log -3 >actual &&
220 test_cmp expect-F actual
223 test_expect_success 'git log --pretty=raw does not show notes' '
224 commit=$(git rev-parse HEAD) &&
225 tree=$(git rev-parse HEAD^{tree}) &&
226 parent=$(git rev-parse HEAD^) &&
227 cat >expect <<-EOF &&
228 commit $commit
229 tree $tree
230 parent $parent
231 author A U Thor <author@example.com> 1112912173 -0700
232 committer C O Mitter <committer@example.com> 1112912173 -0700
234 ${indent}4th
236 git log -1 --pretty=raw >actual &&
237 test_cmp expect actual
240 test_expect_success 'git log --show-notes' '
241 cat >>expect <<-EOF &&
243 Notes:
244 ${indent}xyzzy
246 git log -1 --pretty=raw --show-notes >actual &&
247 test_cmp expect actual
250 test_expect_success 'git log --no-notes' '
251 git log -1 --no-notes >actual &&
252 ! grep xyzzy actual
255 test_expect_success 'git format-patch does not show notes' '
256 git format-patch -1 --stdout >actual &&
257 ! grep xyzzy actual
260 test_expect_success 'git format-patch --show-notes does show notes' '
261 git format-patch --show-notes -1 --stdout >actual &&
262 grep xyzzy actual
265 for pretty in \
266 "" --pretty --pretty=raw --pretty=short --pretty=medium \
267 --pretty=full --pretty=fuller --pretty=format:%s --oneline
269 case "$pretty" in
270 "") p= not= negate="" ;;
271 ?*) p="$pretty" not=" not" negate="!" ;;
272 esac
273 test_expect_success "git show $pretty does$not show notes" '
274 git show $p >actual &&
275 eval "$negate grep xyzzy actual"
277 done
279 test_expect_success 'setup alternate notes ref' '
280 git notes --ref=alternate add -m alternate
283 test_expect_success 'git log --notes shows default notes' '
284 git log -1 --notes >actual &&
285 grep xyzzy actual &&
286 ! grep alternate actual
289 test_expect_success 'git log --notes=X shows only X' '
290 git log -1 --notes=alternate >actual &&
291 ! grep xyzzy actual &&
292 grep alternate actual
295 test_expect_success 'git log --notes --notes=X shows both' '
296 git log -1 --notes --notes=alternate >actual &&
297 grep xyzzy actual &&
298 grep alternate actual
301 test_expect_success 'git log --no-notes resets default state' '
302 git log -1 --notes --notes=alternate \
303 --no-notes --notes=alternate \
304 >actual &&
305 ! grep xyzzy actual &&
306 grep alternate actual
309 test_expect_success 'git log --no-notes resets ref list' '
310 git log -1 --notes --notes=alternate \
311 --no-notes --notes \
312 >actual &&
313 grep xyzzy actual &&
314 ! grep alternate actual
317 test_expect_success 'show -m notes' '
318 test_commit 5th &&
319 git notes add -m spam -m "foo${LF}bar${LF}baz" &&
320 commit=$(git rev-parse HEAD) &&
321 cat >expect-m <<-EOF &&
322 commit $commit
323 Author: A U Thor <author@example.com>
324 Date: Thu Apr 7 15:17:13 2005 -0700
326 ${indent}5th
328 Notes:
329 ${indent}spam
330 ${indent}
331 ${indent}foo
332 ${indent}bar
333 ${indent}baz
336 cat expect-F >>expect-m &&
337 git log -4 >actual &&
338 test_cmp expect-m actual
341 test_expect_success 'remove note with add -f -F /dev/null' '
342 git notes add -f -F /dev/null &&
343 commit=$(git rev-parse HEAD) &&
344 cat >expect-rm-F <<-EOF &&
345 commit $commit
346 Author: A U Thor <author@example.com>
347 Date: Thu Apr 7 15:17:13 2005 -0700
349 ${indent}5th
352 cat expect-F >>expect-rm-F &&
353 git log -4 >actual &&
354 test_cmp expect-rm-F actual &&
355 test_must_fail git notes show
358 test_expect_success 'do not create empty note with -m ""' '
359 git notes add -m "" &&
360 git log -4 >actual &&
361 test_cmp expect-rm-F actual &&
362 test_must_fail git notes show
365 test_expect_success 'create note with combination of -m and -F' '
366 test_when_finished git notes remove HEAD &&
367 cat >expect-combine_m_and_F <<-EOF &&
370 xyzzy
374 zyxxy
378 echo "xyzzy" >note_a &&
379 echo "zyxxy" >note_b &&
380 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
381 git notes show >actual &&
382 test_cmp expect-combine_m_and_F actual
385 test_expect_success 'create note with combination of -m and -F and --separator' '
386 test_when_finished git notes remove HEAD &&
387 cat >expect-combine_m_and_F <<-\EOF &&
389 -------
390 xyzzy
391 -------
393 -------
394 zyxxy
395 -------
398 echo "xyzzy" >note_a &&
399 echo "zyxxy" >note_b &&
400 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --separator="-------" &&
401 git notes show >actual &&
402 test_cmp expect-combine_m_and_F actual
405 test_expect_success 'create note with combination of -m and -F and --no-separator' '
406 cat >expect-combine_m_and_F <<-\EOF &&
408 xyzzy
410 zyxxy
413 echo "xyzzy" >note_a &&
414 echo "zyxxy" >note_b &&
415 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --no-separator &&
416 git notes show >actual &&
417 test_cmp expect-combine_m_and_F actual
420 test_expect_success 'remove note with "git notes remove"' '
421 git notes remove HEAD^ &&
422 git notes remove &&
423 commit=$(git rev-parse HEAD) &&
424 parent=$(git rev-parse HEAD^) &&
425 cat >expect-rm-remove <<-EOF &&
426 commit $commit
427 Author: A U Thor <author@example.com>
428 Date: Thu Apr 7 15:17:13 2005 -0700
430 ${indent}5th
432 commit $parent
433 Author: A U Thor <author@example.com>
434 Date: Thu Apr 7 15:16:13 2005 -0700
436 ${indent}4th
439 cat expect-multiline >>expect-rm-remove &&
440 git log -4 >actual &&
441 test_cmp expect-rm-remove actual &&
442 test_must_fail git notes show HEAD^
445 test_expect_success 'removing non-existing note should not create new commit' '
446 git rev-parse --verify refs/notes/commits >before_commit &&
447 test_must_fail git notes remove HEAD^ &&
448 git rev-parse --verify refs/notes/commits >after_commit &&
449 test_cmp before_commit after_commit
452 test_expect_success 'removing more than one' '
453 before=$(git rev-parse --verify refs/notes/commits) &&
454 test_when_finished "git update-ref refs/notes/commits $before" &&
456 # We have only two -- add another and make sure it stays
457 git notes add -m "extra" &&
458 git notes list HEAD >after-removal-expect &&
459 git notes remove HEAD^^ HEAD^^^ &&
460 git notes list | sed -e "s/ .*//" >actual &&
461 test_cmp after-removal-expect actual
464 test_expect_success 'removing is atomic' '
465 before=$(git rev-parse --verify refs/notes/commits) &&
466 test_when_finished "git update-ref refs/notes/commits $before" &&
467 test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
468 after=$(git rev-parse --verify refs/notes/commits) &&
469 test "$before" = "$after"
472 test_expect_success 'removing with --ignore-missing' '
473 before=$(git rev-parse --verify refs/notes/commits) &&
474 test_when_finished "git update-ref refs/notes/commits $before" &&
476 # We have only two -- add another and make sure it stays
477 git notes add -m "extra" &&
478 git notes list HEAD >after-removal-expect &&
479 git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
480 git notes list | sed -e "s/ .*//" >actual &&
481 test_cmp after-removal-expect actual
484 test_expect_success 'removing with --ignore-missing but bogus ref' '
485 before=$(git rev-parse --verify refs/notes/commits) &&
486 test_when_finished "git update-ref refs/notes/commits $before" &&
487 test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
488 after=$(git rev-parse --verify refs/notes/commits) &&
489 test "$before" = "$after"
492 test_expect_success 'remove reads from --stdin' '
493 before=$(git rev-parse --verify refs/notes/commits) &&
494 test_when_finished "git update-ref refs/notes/commits $before" &&
496 # We have only two -- add another and make sure it stays
497 git notes add -m "extra" &&
498 git notes list HEAD >after-removal-expect &&
499 git rev-parse HEAD^^ HEAD^^^ >input &&
500 git notes remove --stdin <input &&
501 git notes list | sed -e "s/ .*//" >actual &&
502 test_cmp after-removal-expect actual
505 test_expect_success 'remove --stdin is also atomic' '
506 before=$(git rev-parse --verify refs/notes/commits) &&
507 test_when_finished "git update-ref refs/notes/commits $before" &&
508 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
509 test_must_fail git notes remove --stdin <input &&
510 after=$(git rev-parse --verify refs/notes/commits) &&
511 test "$before" = "$after"
514 test_expect_success 'removing with --stdin --ignore-missing' '
515 before=$(git rev-parse --verify refs/notes/commits) &&
516 test_when_finished "git update-ref refs/notes/commits $before" &&
518 # We have only two -- add another and make sure it stays
519 git notes add -m "extra" &&
520 git notes list HEAD >after-removal-expect &&
521 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
522 git notes remove --ignore-missing --stdin <input &&
523 git notes list | sed -e "s/ .*//" >actual &&
524 test_cmp after-removal-expect actual
527 test_expect_success 'list notes with "git notes list"' '
528 commit_2=$(git rev-parse 2nd) &&
529 commit_3=$(git rev-parse 3rd) &&
530 note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
531 note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
532 sort -t" " -k2 >expect <<-EOF &&
533 $note_2 $commit_2
534 $note_3 $commit_3
536 git notes list >actual &&
537 test_cmp expect actual
540 test_expect_success 'list notes with "git notes"' '
541 git notes >actual &&
542 test_cmp expect actual
545 test_expect_success '"git notes" without subcommand does not take arguments' '
546 test_expect_code 129 git notes HEAD^^ 2>err &&
547 grep "^error: unknown subcommand" err
550 test_expect_success 'list specific note with "git notes list <object>"' '
551 git rev-parse refs/notes/commits:$commit_3 >expect &&
552 git notes list HEAD^^ >actual &&
553 test_cmp expect actual
556 test_expect_success 'listing non-existing notes fails' '
557 test_must_fail git notes list HEAD >actual &&
558 test_must_be_empty actual
561 test_expect_success 'append: specify a separator with an empty arg' '
562 test_when_finished git notes remove HEAD &&
563 cat >expect <<-\EOF &&
564 notes-1
566 notes-2
569 git notes add -m "notes-1" &&
570 git notes append --separator="" -m "notes-2" &&
571 git notes show >actual &&
572 test_cmp expect actual
575 test_expect_success 'append: specify a separator without arg' '
576 test_when_finished git notes remove HEAD &&
577 cat >expect <<-\EOF &&
578 notes-1
580 notes-2
583 git notes add -m "notes-1" &&
584 git notes append --separator -m "notes-2" &&
585 git notes show >actual &&
586 test_cmp expect actual
589 test_expect_success 'append: specify as --no-separator' '
590 test_when_finished git notes remove HEAD &&
591 cat >expect <<-\EOF &&
592 notes-1
593 notes-2
596 git notes add -m "notes-1" &&
597 git notes append --no-separator -m "notes-2" &&
598 git notes show >actual &&
599 test_cmp expect actual
602 test_expect_success 'append: specify separator with line break' '
603 test_when_finished git notes remove HEAD &&
604 cat >expect <<-\EOF &&
605 notes-1
606 -------
607 notes-2
610 git notes add -m "notes-1" &&
611 git notes append --separator="-------$LF" -m "notes-2" &&
612 git notes show >actual &&
613 test_cmp expect actual
616 test_expect_success 'append: specify separator without line break' '
617 test_when_finished git notes remove HEAD &&
618 cat >expect <<-\EOF &&
619 notes-1
620 -------
621 notes-2
624 git notes add -m "notes-1" &&
625 git notes append --separator="-------" -m "notes-2" &&
626 git notes show >actual &&
627 test_cmp expect actual
630 test_expect_success 'append: specify separator with multiple messages' '
631 test_when_finished git notes remove HEAD &&
632 cat >expect <<-\EOF &&
633 notes-1
634 -------
635 notes-2
636 -------
637 notes-3
640 git notes add -m "notes-1" &&
641 git notes append --separator="-------" -m "notes-2" -m "notes-3" &&
642 git notes show >actual &&
643 test_cmp expect actual
646 test_expect_success 'append note with combination of -m and -F and --separator' '
647 test_when_finished git notes remove HEAD &&
648 cat >expect-combine_m_and_F <<-\EOF &&
649 m-notes-1
650 -------
651 f-notes-1
652 -------
653 m-notes-2
654 -------
655 f-notes-2
656 -------
657 m-notes-3
660 echo "f-notes-1" >note_a &&
661 echo "f-notes-2" >note_b &&
662 git notes append -m "m-notes-1" -F note_a -m "m-notes-2" -F note_b -m "m-notes-3" --separator="-------" &&
663 git notes show >actual &&
664 test_cmp expect-combine_m_and_F actual
667 test_expect_success 'append to existing note with "git notes append"' '
668 cat >expect <<-EOF &&
669 Initial set of notes
671 More notes appended with git notes append
673 git notes add -m "Initial set of notes" &&
674 git notes append -m "More notes appended with git notes append" &&
675 git notes show >actual &&
676 test_cmp expect actual
679 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
680 commit_5=$(git rev-parse 5th) &&
681 note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
682 sort -t" " -k2 >expect_list <<-EOF &&
683 $note_2 $commit_2
684 $note_3 $commit_3
685 $note_5 $commit_5
687 git notes list >actual &&
688 test_cmp expect_list actual
691 test_expect_success 'appending empty string does not change existing note' '
692 git notes append -m "" &&
693 git notes show >actual &&
694 test_cmp expect actual
697 test_expect_success 'git notes append == add when there is no existing note' '
698 git notes remove HEAD &&
699 test_must_fail git notes list HEAD &&
700 git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
701 git notes show >actual &&
702 test_cmp expect actual
705 test_expect_success 'appending empty string to non-existing note does not create note' '
706 git notes remove HEAD &&
707 test_must_fail git notes list HEAD &&
708 git notes append -m "" &&
709 test_must_fail git notes list HEAD
712 test_expect_success 'create other note on a different notes ref (setup)' '
713 test_commit 6th &&
714 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
715 commit=$(git rev-parse HEAD) &&
716 cat >expect-not-other <<-EOF &&
717 commit $commit
718 Author: A U Thor <author@example.com>
719 Date: Thu Apr 7 15:18:13 2005 -0700
721 ${indent}6th
723 cp expect-not-other expect-other &&
724 cat >>expect-other <<-EOF
726 Notes (other):
727 ${indent}other note
731 test_expect_success 'Do not show note on other ref by default' '
732 git log -1 >actual &&
733 test_cmp expect-not-other actual
736 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
737 GIT_NOTES_REF="refs/notes/other" git log -1 >actual &&
738 test_cmp expect-other actual
741 test_expect_success 'Do show note when ref is given in core.notesRef config' '
742 test_config core.notesRef "refs/notes/other" &&
743 git log -1 >actual &&
744 test_cmp expect-other actual
747 test_expect_success 'Do not show note when core.notesRef is overridden' '
748 test_config core.notesRef "refs/notes/other" &&
749 GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual &&
750 test_cmp expect-not-other actual
753 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
754 commit=$(git rev-parse HEAD) &&
755 parent=$(git rev-parse HEAD^) &&
756 cat >expect-both <<-EOF &&
757 commit $commit
758 Author: A U Thor <author@example.com>
759 Date: Thu Apr 7 15:18:13 2005 -0700
761 ${indent}6th
763 Notes:
764 ${indent}order test
766 Notes (other):
767 ${indent}other note
769 commit $parent
770 Author: A U Thor <author@example.com>
771 Date: Thu Apr 7 15:17:13 2005 -0700
773 ${indent}5th
775 Notes:
776 ${indent}replacement for deleted note
778 GIT_NOTES_REF=refs/notes/commits git notes add \
779 -m"replacement for deleted note" HEAD^ &&
780 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
781 test_unconfig core.notesRef &&
782 test_config notes.displayRef "refs/notes/*" &&
783 git log -2 >actual &&
784 test_cmp expect-both actual
787 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
788 test_config core.notesRef refs/notes/commits &&
789 test_config notes.displayRef refs/notes/other &&
790 git log -2 >actual &&
791 test_cmp expect-both actual
794 test_expect_success 'notes.displayRef can be given more than once' '
795 test_unconfig core.notesRef &&
796 test_config notes.displayRef refs/notes/commits &&
797 git config --add notes.displayRef refs/notes/other &&
798 git log -2 >actual &&
799 test_cmp expect-both actual
802 test_expect_success 'notes.displayRef respects order' '
803 commit=$(git rev-parse HEAD) &&
804 cat >expect-both-reversed <<-EOF &&
805 commit $commit
806 Author: A U Thor <author@example.com>
807 Date: Thu Apr 7 15:18:13 2005 -0700
809 ${indent}6th
811 Notes (other):
812 ${indent}other note
814 Notes:
815 ${indent}order test
817 test_config core.notesRef refs/notes/other &&
818 test_config notes.displayRef refs/notes/commits &&
819 git log -1 >actual &&
820 test_cmp expect-both-reversed actual
823 test_expect_success 'notes.displayRef with no value handled gracefully' '
824 test_must_fail git -c notes.displayRef log -0 --notes &&
825 test_must_fail git -c notes.displayRef diff-tree --notes HEAD
828 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
829 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
830 git log -2 >actual &&
831 test_cmp expect-both actual
834 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
835 commit=$(git rev-parse HEAD) &&
836 parent=$(git rev-parse HEAD^) &&
837 cat >expect-none <<-EOF &&
838 commit $commit
839 Author: A U Thor <author@example.com>
840 Date: Thu Apr 7 15:18:13 2005 -0700
842 ${indent}6th
844 commit $parent
845 Author: A U Thor <author@example.com>
846 Date: Thu Apr 7 15:17:13 2005 -0700
848 ${indent}5th
850 test_config notes.displayRef "refs/notes/*" &&
851 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual &&
852 test_cmp expect-none actual
855 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
856 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual &&
857 test_cmp expect-both actual
860 test_expect_success '--no-standard-notes' '
861 commit=$(git rev-parse HEAD) &&
862 cat >expect-commits <<-EOF &&
863 commit $commit
864 Author: A U Thor <author@example.com>
865 Date: Thu Apr 7 15:18:13 2005 -0700
867 ${indent}6th
869 Notes:
870 ${indent}order test
872 git log --no-standard-notes --show-notes=commits -1 >actual &&
873 test_cmp expect-commits actual
876 test_expect_success '--standard-notes' '
877 test_config notes.displayRef "refs/notes/*" &&
878 git log --no-standard-notes --show-notes=commits \
879 --standard-notes -2 >actual &&
880 test_cmp expect-both actual
883 test_expect_success '--show-notes=ref accumulates' '
884 git log --show-notes=other --show-notes=commits \
885 --no-standard-notes -1 >actual &&
886 test_cmp expect-both-reversed actual
889 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
890 test_config core.notesRef refs/notes/other &&
891 echo "Note on a tree" >expect &&
892 git notes add -m "Note on a tree" HEAD: &&
893 git notes show HEAD: >actual &&
894 test_cmp expect actual &&
895 echo "Note on a blob" >expect &&
896 git ls-tree --name-only HEAD >files &&
897 filename=$(head -n1 files) &&
898 git notes add -m "Note on a blob" HEAD:$filename &&
899 git notes show HEAD:$filename >actual &&
900 test_cmp expect actual &&
901 echo "Note on a tag" >expect &&
902 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
903 git notes add -m "Note on a tag" foobar &&
904 git notes show foobar >actual &&
905 test_cmp expect actual
908 test_expect_success 'create note from other note with "git notes add -C"' '
909 test_commit 7th &&
910 commit=$(git rev-parse HEAD) &&
911 cat >expect <<-EOF &&
912 commit $commit
913 Author: A U Thor <author@example.com>
914 Date: Thu Apr 7 15:19:13 2005 -0700
916 ${indent}7th
918 Notes:
919 ${indent}order test
921 note=$(git notes list HEAD^) &&
922 git notes add -C $note &&
923 git log -1 >actual &&
924 test_cmp expect actual &&
925 git notes list HEAD^ >expect &&
926 git notes list HEAD >actual &&
927 test_cmp expect actual
930 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
931 test_commit 8th &&
932 test_must_fail git notes add -C deadbeef &&
933 test_must_fail git notes list HEAD
936 test_expect_success 'create note from non-blob with "git notes add -C" fails' '
937 commit=$(git rev-parse --verify HEAD) &&
938 tree=$(git rev-parse --verify HEAD:) &&
939 test_must_fail git notes add -C $commit &&
940 test_must_fail git notes add -C $tree &&
941 test_must_fail git notes list HEAD
944 test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
945 commit=$(git rev-parse HEAD) &&
946 cat >expect <<-EOF &&
947 commit $commit
948 Author: A U Thor <author@example.com>
949 Date: Thu Apr 7 15:20:13 2005 -0700
951 ${indent}8th
953 Notes:
954 ${indent}This is a blob object
956 echo "This is a blob object" | git hash-object -w --stdin >blob &&
957 git notes add -C $(cat blob) &&
958 git log -1 >actual &&
959 test_cmp expect actual &&
960 git notes list HEAD >actual &&
961 test_cmp blob actual
964 test_expect_success 'create note from blob with "-C", also specify "-m", "-F" and "--separator"' '
965 # 8th will be reuseed in following tests, so rollback when the test is done
966 test_when_finished "git notes remove && git notes add -C $(cat blob)" &&
967 commit=$(git rev-parse HEAD) &&
968 cat >expect <<-EOF &&
969 commit $commit
970 Author: A U Thor <author@example.com>
971 Date: Thu Apr 7 15:20:13 2005 -0700
973 ${indent}8th
975 Notes:
976 ${indent}This is a blob object
977 ${indent}-------
978 ${indent}This is created by -m
979 ${indent}-------
980 ${indent}This is created by -F
983 git notes remove &&
984 echo "This is a blob object" | git hash-object -w --stdin >blob &&
985 echo "This is created by -F" >note_a &&
986 git notes add -C $(cat blob) -m "This is created by -m" -F note_a --separator="-------" &&
987 git log -1 >actual &&
988 test_cmp expect actual
991 test_expect_success 'create note from other note with "git notes add -c"' '
992 test_commit 9th &&
993 commit=$(git rev-parse HEAD) &&
994 cat >expect <<-EOF &&
995 commit $commit
996 Author: A U Thor <author@example.com>
997 Date: Thu Apr 7 15:21:13 2005 -0700
999 ${indent}9th
1001 Notes:
1002 ${indent}yet another note
1004 note=$(git notes list HEAD^^) &&
1005 MSG="yet another note" git notes add -c $note &&
1006 git log -1 >actual &&
1007 test_cmp expect actual
1010 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
1011 test_commit 10th &&
1012 test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
1013 test_must_fail git notes list HEAD
1016 test_expect_success 'append to note from other note with "git notes append -C"' '
1017 commit=$(git rev-parse HEAD^) &&
1018 cat >expect <<-EOF &&
1019 commit $commit
1020 Author: A U Thor <author@example.com>
1021 Date: Thu Apr 7 15:21:13 2005 -0700
1023 ${indent}9th
1025 Notes:
1026 ${indent}yet another note
1027 ${indent}
1028 ${indent}yet another note
1030 note=$(git notes list HEAD^) &&
1031 git notes append -C $note HEAD^ &&
1032 git log -1 HEAD^ >actual &&
1033 test_cmp expect actual
1036 test_expect_success 'create note from other note with "git notes append -c"' '
1037 commit=$(git rev-parse HEAD) &&
1038 cat >expect <<-EOF &&
1039 commit $commit
1040 Author: A U Thor <author@example.com>
1041 Date: Thu Apr 7 15:22:13 2005 -0700
1043 ${indent}10th
1045 Notes:
1046 ${indent}other note
1048 note=$(git notes list HEAD^) &&
1049 MSG="other note" git notes append -c $note &&
1050 git log -1 >actual &&
1051 test_cmp expect actual
1054 test_expect_success 'append to note from other note with "git notes append -c"' '
1055 commit=$(git rev-parse HEAD) &&
1056 cat >expect <<-EOF &&
1057 commit $commit
1058 Author: A U Thor <author@example.com>
1059 Date: Thu Apr 7 15:22:13 2005 -0700
1061 ${indent}10th
1063 Notes:
1064 ${indent}other note
1065 ${indent}
1066 ${indent}yet another note
1068 note=$(git notes list HEAD) &&
1069 MSG="yet another note" git notes append -c $note &&
1070 git log -1 >actual &&
1071 test_cmp expect actual
1074 test_expect_success 'copy note with "git notes copy"' '
1075 commit=$(git rev-parse 4th) &&
1076 cat >expect <<-EOF &&
1077 commit $commit
1078 Author: A U Thor <author@example.com>
1079 Date: Thu Apr 7 15:16:13 2005 -0700
1081 ${indent}4th
1083 Notes:
1084 ${indent}This is a blob object
1086 git notes copy 8th 4th &&
1087 git log 3rd..4th >actual &&
1088 test_cmp expect actual &&
1089 git notes list 4th >expect &&
1090 git notes list 8th >actual &&
1091 test_cmp expect actual
1094 test_expect_success 'copy note with "git notes copy" with default' '
1095 test_commit 11th &&
1096 commit=$(git rev-parse HEAD) &&
1097 cat >expect <<-EOF &&
1098 commit $commit
1099 Author: A U Thor <author@example.com>
1100 Date: Thu Apr 7 15:23:13 2005 -0700
1102 ${indent}11th
1104 Notes:
1105 ${indent}other note
1106 ${indent}
1107 ${indent}yet another note
1109 git notes copy HEAD^ &&
1110 git log -1 >actual &&
1111 test_cmp expect actual &&
1112 git notes list HEAD^ >expect &&
1113 git notes list HEAD >actual &&
1114 test_cmp expect actual
1117 test_expect_success 'prevent overwrite with "git notes copy"' '
1118 test_must_fail git notes copy HEAD~2 HEAD &&
1119 cat >expect <<-EOF &&
1120 commit $commit
1121 Author: A U Thor <author@example.com>
1122 Date: Thu Apr 7 15:23:13 2005 -0700
1124 ${indent}11th
1126 Notes:
1127 ${indent}other note
1128 ${indent}
1129 ${indent}yet another note
1131 git log -1 >actual &&
1132 test_cmp expect actual &&
1133 git notes list HEAD^ >expect &&
1134 git notes list HEAD >actual &&
1135 test_cmp expect actual
1138 test_expect_success 'allow overwrite with "git notes copy -f"' '
1139 commit=$(git rev-parse HEAD) &&
1140 cat >expect <<-EOF &&
1141 commit $commit
1142 Author: A U Thor <author@example.com>
1143 Date: Thu Apr 7 15:23:13 2005 -0700
1145 ${indent}11th
1147 Notes:
1148 ${indent}This is a blob object
1150 git notes copy -f HEAD~3 HEAD &&
1151 git log -1 >actual &&
1152 test_cmp expect actual &&
1153 git notes list HEAD~3 >expect &&
1154 git notes list HEAD >actual &&
1155 test_cmp expect actual
1158 test_expect_success 'allow overwrite with "git notes copy -f" with default' '
1159 commit=$(git rev-parse HEAD) &&
1160 cat >expect <<-EOF &&
1161 commit $commit
1162 Author: A U Thor <author@example.com>
1163 Date: Thu Apr 7 15:23:13 2005 -0700
1165 ${indent}11th
1167 Notes:
1168 ${indent}yet another note
1169 ${indent}
1170 ${indent}yet another note
1172 git notes copy -f HEAD~2 &&
1173 git log -1 >actual &&
1174 test_cmp expect actual &&
1175 git notes list HEAD~2 >expect &&
1176 git notes list HEAD >actual &&
1177 test_cmp expect actual
1180 test_expect_success 'cannot copy note from object without notes' '
1181 test_commit 12th &&
1182 test_commit 13th &&
1183 test_must_fail git notes copy HEAD^ HEAD
1186 test_expect_success 'git notes copy --stdin' '
1187 commit=$(git rev-parse HEAD) &&
1188 parent=$(git rev-parse HEAD^) &&
1189 cat >expect <<-EOF &&
1190 commit $commit
1191 Author: A U Thor <author@example.com>
1192 Date: Thu Apr 7 15:25:13 2005 -0700
1194 ${indent}13th
1196 Notes:
1197 ${indent}yet another note
1198 ${indent}
1199 ${indent}yet another note
1201 commit $parent
1202 Author: A U Thor <author@example.com>
1203 Date: Thu Apr 7 15:24:13 2005 -0700
1205 ${indent}12th
1207 Notes:
1208 ${indent}other note
1209 ${indent}
1210 ${indent}yet another note
1212 from=$(git rev-parse HEAD~3) &&
1213 to=$(git rev-parse HEAD^) &&
1214 echo "$from" "$to" >copy &&
1215 from=$(git rev-parse HEAD~2) &&
1216 to=$(git rev-parse HEAD) &&
1217 echo "$from" "$to" >>copy &&
1218 git notes copy --stdin <copy &&
1219 git log -2 >actual &&
1220 test_cmp expect actual &&
1221 git notes list HEAD~2 >expect &&
1222 git notes list HEAD >actual &&
1223 test_cmp expect actual &&
1224 git notes list HEAD~3 >expect &&
1225 git notes list HEAD^ >actual &&
1226 test_cmp expect actual
1229 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
1230 test_commit 14th &&
1231 test_commit 15th &&
1232 commit=$(git rev-parse HEAD) &&
1233 parent=$(git rev-parse HEAD^) &&
1234 cat >expect <<-EOF &&
1235 commit $commit
1236 Author: A U Thor <author@example.com>
1237 Date: Thu Apr 7 15:27:13 2005 -0700
1239 ${indent}15th
1241 commit $parent
1242 Author: A U Thor <author@example.com>
1243 Date: Thu Apr 7 15:26:13 2005 -0700
1245 ${indent}14th
1247 from=$(git rev-parse HEAD~3) &&
1248 to=$(git rev-parse HEAD^) &&
1249 echo "$from" "$to" >copy &&
1250 from=$(git rev-parse HEAD~2) &&
1251 to=$(git rev-parse HEAD) &&
1252 echo "$from" "$to" >>copy &&
1253 git notes copy --for-rewrite=foo <copy &&
1254 git log -2 >actual &&
1255 test_cmp expect actual
1258 test_expect_success 'git notes copy --for-rewrite (enabled)' '
1259 commit=$(git rev-parse HEAD) &&
1260 parent=$(git rev-parse HEAD^) &&
1261 cat >expect <<-EOF &&
1262 commit $commit
1263 Author: A U Thor <author@example.com>
1264 Date: Thu Apr 7 15:27:13 2005 -0700
1266 ${indent}15th
1268 Notes:
1269 ${indent}yet another note
1270 ${indent}
1271 ${indent}yet another note
1273 commit $parent
1274 Author: A U Thor <author@example.com>
1275 Date: Thu Apr 7 15:26:13 2005 -0700
1277 ${indent}14th
1279 Notes:
1280 ${indent}other note
1281 ${indent}
1282 ${indent}yet another note
1284 test_config notes.rewriteMode overwrite &&
1285 test_config notes.rewriteRef "refs/notes/*" &&
1286 from=$(git rev-parse HEAD~3) &&
1287 to=$(git rev-parse HEAD^) &&
1288 echo "$from" "$to" >copy &&
1289 from=$(git rev-parse HEAD~2) &&
1290 to=$(git rev-parse HEAD) &&
1291 echo "$from" "$to" >>copy &&
1292 git notes copy --for-rewrite=foo <copy &&
1293 git log -2 >actual &&
1294 test_cmp expect actual
1297 test_expect_success 'git notes copy --for-rewrite (disabled)' '
1298 test_config notes.rewrite.bar false &&
1299 from=$(git rev-parse HEAD~3) &&
1300 to=$(git rev-parse HEAD) &&
1301 echo "$from" "$to" >copy &&
1302 git notes copy --for-rewrite=bar <copy &&
1303 git log -2 >actual &&
1304 test_cmp expect actual
1307 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
1308 commit=$(git rev-parse HEAD) &&
1309 cat >expect <<-EOF &&
1310 commit $commit
1311 Author: A U Thor <author@example.com>
1312 Date: Thu Apr 7 15:27:13 2005 -0700
1314 ${indent}15th
1316 Notes:
1317 ${indent}a fresh note
1319 git notes add -f -m"a fresh note" HEAD^ &&
1320 test_config notes.rewriteMode overwrite &&
1321 test_config notes.rewriteRef "refs/notes/*" &&
1322 from=$(git rev-parse HEAD^) &&
1323 to=$(git rev-parse HEAD) &&
1324 echo "$from" "$to" >copy &&
1325 git notes copy --for-rewrite=foo <copy &&
1326 git log -1 >actual &&
1327 test_cmp expect actual
1330 test_expect_success 'git notes copy --for-rewrite (ignore)' '
1331 test_config notes.rewriteMode ignore &&
1332 test_config notes.rewriteRef "refs/notes/*" &&
1333 from=$(git rev-parse HEAD^) &&
1334 to=$(git rev-parse HEAD) &&
1335 echo "$from" "$to" >copy &&
1336 git notes copy --for-rewrite=foo <copy &&
1337 git log -1 >actual &&
1338 test_cmp expect actual
1341 test_expect_success 'git notes copy --for-rewrite (append)' '
1342 commit=$(git rev-parse HEAD) &&
1343 cat >expect <<-EOF &&
1344 commit $commit
1345 Author: A U Thor <author@example.com>
1346 Date: Thu Apr 7 15:27:13 2005 -0700
1348 ${indent}15th
1350 Notes:
1351 ${indent}a fresh note
1352 ${indent}
1353 ${indent}another fresh note
1355 git notes add -f -m"another fresh note" HEAD^ &&
1356 test_config notes.rewriteMode concatenate &&
1357 test_config notes.rewriteRef "refs/notes/*" &&
1358 from=$(git rev-parse HEAD^) &&
1359 to=$(git rev-parse HEAD) &&
1360 echo "$from" "$to" >copy &&
1361 git notes copy --for-rewrite=foo <copy &&
1362 git log -1 >actual &&
1363 test_cmp expect actual
1366 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1367 commit=$(git rev-parse HEAD) &&
1368 cat >expect <<-EOF &&
1369 commit $commit
1370 Author: A U Thor <author@example.com>
1371 Date: Thu Apr 7 15:27:13 2005 -0700
1373 ${indent}15th
1375 Notes:
1376 ${indent}a fresh note
1377 ${indent}
1378 ${indent}another fresh note
1379 ${indent}
1380 ${indent}append 1
1381 ${indent}
1382 ${indent}append 2
1384 git notes add -f -m"append 1" HEAD^ &&
1385 git notes add -f -m"append 2" HEAD^^ &&
1386 test_config notes.rewriteMode concatenate &&
1387 test_config notes.rewriteRef "refs/notes/*" &&
1388 from=$(git rev-parse HEAD^) &&
1389 to=$(git rev-parse HEAD) &&
1390 echo "$from" "$to" >copy &&
1391 from=$(git rev-parse HEAD^^) &&
1392 to=$(git rev-parse HEAD) &&
1393 echo "$from" "$to" >>copy &&
1394 git notes copy --for-rewrite=foo <copy &&
1395 git log -1 >actual &&
1396 test_cmp expect actual
1399 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1400 git notes remove HEAD^ &&
1401 test_config notes.rewriteMode concatenate &&
1402 test_config notes.rewriteRef "refs/notes/*" &&
1403 from=$(git rev-parse HEAD^) &&
1404 to=$(git rev-parse HEAD) &&
1405 echo "$from" "$to" >copy &&
1406 git notes copy --for-rewrite=foo <copy &&
1407 git log -1 >actual &&
1408 test_cmp expect actual
1411 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1412 commit=$(git rev-parse HEAD) &&
1413 cat >expect <<-EOF &&
1414 commit $commit
1415 Author: A U Thor <author@example.com>
1416 Date: Thu Apr 7 15:27:13 2005 -0700
1418 ${indent}15th
1420 Notes:
1421 ${indent}replacement note 1
1423 test_config notes.rewriteMode concatenate &&
1424 test_config notes.rewriteRef "refs/notes/*" &&
1425 git notes add -f -m"replacement note 1" HEAD^ &&
1426 from=$(git rev-parse HEAD^) &&
1427 to=$(git rev-parse HEAD) &&
1428 echo "$from" "$to" >copy &&
1429 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
1430 git log -1 >actual &&
1431 test_cmp expect actual
1434 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1435 commit=$(git rev-parse HEAD) &&
1436 cat >expect <<-EOF &&
1437 commit $commit
1438 Author: A U Thor <author@example.com>
1439 Date: Thu Apr 7 15:27:13 2005 -0700
1441 ${indent}15th
1443 Notes:
1444 ${indent}replacement note 2
1446 git notes add -f -m"replacement note 2" HEAD^ &&
1447 test_config notes.rewriteMode overwrite &&
1448 test_unconfig notes.rewriteRef &&
1449 from=$(git rev-parse HEAD^) &&
1450 to=$(git rev-parse HEAD) &&
1451 echo "$from" "$to" >copy &&
1452 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1453 git notes copy --for-rewrite=foo <copy &&
1454 git log -1 >actual &&
1455 test_cmp expect actual
1458 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1459 git notes add -f -m"replacement note 3" HEAD^ &&
1460 test_config notes.rewriteMode overwrite &&
1461 test_config notes.rewriteRef refs/notes/other &&
1462 from=$(git rev-parse HEAD^) &&
1463 to=$(git rev-parse HEAD) &&
1464 echo "$from" "$to" >copy &&
1465 GIT_NOTES_REWRITE_REF=refs/notes/commits \
1466 git notes copy --for-rewrite=foo <copy &&
1467 git log -1 >actual &&
1468 grep "replacement note 3" actual
1471 test_expect_success 'git notes copy diagnoses too many or too few arguments' '
1472 test_must_fail git notes copy 2>error &&
1473 test_grep "too few arguments" error &&
1474 test_must_fail git notes copy one two three 2>error &&
1475 test_grep "too many arguments" error
1478 test_expect_success 'git notes get-ref expands refs/heads/main to refs/notes/refs/heads/main' '
1479 test_unconfig core.notesRef &&
1480 sane_unset GIT_NOTES_REF &&
1481 echo refs/notes/refs/heads/main >expect &&
1482 git notes --ref=refs/heads/main get-ref >actual &&
1483 test_cmp expect actual
1486 test_expect_success 'git notes get-ref (no overrides)' '
1487 test_unconfig core.notesRef &&
1488 sane_unset GIT_NOTES_REF &&
1489 echo refs/notes/commits >expect &&
1490 git notes get-ref >actual &&
1491 test_cmp expect actual
1494 test_expect_success 'git notes get-ref (core.notesRef)' '
1495 test_config core.notesRef refs/notes/foo &&
1496 echo refs/notes/foo >expect &&
1497 git notes get-ref >actual &&
1498 test_cmp expect actual
1501 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1502 echo refs/notes/bar >expect &&
1503 GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
1504 test_cmp expect actual
1507 test_expect_success 'git notes get-ref (--ref)' '
1508 echo refs/notes/baz >expect &&
1509 GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
1510 test_cmp expect actual
1513 test_expect_success 'setup testing of empty notes' '
1514 test_unconfig core.notesRef &&
1515 test_commit 16th &&
1516 empty_blob=$(git hash-object -w /dev/null) &&
1517 echo "$empty_blob" >expect_empty
1520 while read cmd
1522 test_expect_success "'git notes $cmd' removes empty note" "
1523 test_might_fail git notes remove HEAD &&
1524 MSG= git notes $cmd &&
1525 test_must_fail git notes list HEAD
1528 test_expect_success "'git notes $cmd --allow-empty' stores empty note" "
1529 test_might_fail git notes remove HEAD &&
1530 MSG= git notes $cmd --allow-empty &&
1531 git notes list HEAD >actual &&
1532 test_cmp expect_empty actual
1534 done <<\EOF
1536 add -F /dev/null
1537 add -m ""
1538 add -c "$empty_blob"
1539 add -C "$empty_blob"
1540 append
1541 append -F /dev/null
1542 append -m ""
1543 append -c "$empty_blob"
1544 append -C "$empty_blob"
1545 edit
1548 test_expect_success 'empty notes are displayed by git log' '
1549 test_commit 17th &&
1550 git log -1 >expect &&
1551 cat >>expect <<-EOF &&
1553 Notes:
1555 git notes add -C "$empty_blob" --allow-empty &&
1556 git log -1 >actual &&
1557 test_cmp expect actual
1560 test_done