Merge branch 'jc/stash-pop-not-popped'
[git.git] / t / t3301-notes.sh
blob3bb79a47af5e2f619753c61436ec577ec025a8ae
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test commit notes'
8 . ./test-lib.sh
10 cat > fake_editor.sh << \EOF
11 #!/bin/sh
12 echo "$MSG" > "$1"
13 echo "$MSG" >& 2
14 EOF
15 chmod a+x fake_editor.sh
16 GIT_EDITOR=./fake_editor.sh
17 export GIT_EDITOR
19 test_expect_success 'cannot annotate non-existing HEAD' '
20 (MSG=3 && export MSG && test_must_fail git notes add)
23 test_expect_success setup '
24 : > a1 &&
25 git add a1 &&
26 test_tick &&
27 git commit -m 1st &&
28 : > a2 &&
29 git add a2 &&
30 test_tick &&
31 git commit -m 2nd
34 test_expect_success 'need valid notes ref' '
35 (MSG=1 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF &&
36 test_must_fail git notes add) &&
37 (MSG=2 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF &&
38 test_must_fail git notes show)
41 test_expect_success 'refusing to add notes in refs/heads/' '
42 (MSG=1 GIT_NOTES_REF=refs/heads/bogus &&
43 export MSG GIT_NOTES_REF &&
44 test_must_fail git notes add)
47 test_expect_success 'refusing to edit notes in refs/remotes/' '
48 (MSG=1 GIT_NOTES_REF=refs/remotes/bogus &&
49 export MSG GIT_NOTES_REF &&
50 test_must_fail git notes edit)
53 # 1 indicates caught gracefully by die, 128 means git-show barked
54 test_expect_success 'handle empty notes gracefully' '
55 test_expect_code 1 git notes show
58 test_expect_success 'show non-existent notes entry with %N' '
59 for l in A B
61 echo "$l"
62 done >expect &&
63 git show -s --format='A%n%NB' >output &&
64 test_cmp expect output
67 test_expect_success 'create notes' '
68 git config core.notesRef refs/notes/commits &&
69 MSG=b4 git notes add &&
70 test ! -f .git/NOTES_EDITMSG &&
71 test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
72 test b4 = $(git notes show) &&
73 git show HEAD^ &&
74 test_must_fail git notes show HEAD^
77 test_expect_success 'show notes entry with %N' '
78 for l in A b4 B
80 echo "$l"
81 done >expect &&
82 git show -s --format='A%n%NB' >output &&
83 test_cmp expect output
86 cat >expect <<EOF
87 d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add'
88 EOF
90 test_expect_success 'create reflog entry' '
91 git reflog show refs/notes/commits >output &&
92 test_cmp expect output
95 test_expect_success 'edit existing notes' '
96 MSG=b3 git notes edit &&
97 test ! -f .git/NOTES_EDITMSG &&
98 test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
99 test b3 = $(git notes show) &&
100 git show HEAD^ &&
101 test_must_fail git notes show HEAD^
104 test_expect_success 'cannot "git notes add -m" where notes already exists' '
105 test_must_fail git notes add -m "b2" &&
106 test ! -f .git/NOTES_EDITMSG &&
107 test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
108 test b3 = $(git notes show) &&
109 git show HEAD^ &&
110 test_must_fail git notes show HEAD^
113 test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
114 git notes add -f -m "b1" &&
115 test ! -f .git/NOTES_EDITMSG &&
116 test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
117 test b1 = $(git notes show) &&
118 git show HEAD^ &&
119 test_must_fail git notes show HEAD^
122 test_expect_success 'add w/no options on existing note morphs into edit' '
123 MSG=b2 git notes add &&
124 test ! -f .git/NOTES_EDITMSG &&
125 test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
126 test b2 = $(git notes show) &&
127 git show HEAD^ &&
128 test_must_fail git notes show HEAD^
131 test_expect_success 'can overwrite existing note with "git notes add -f"' '
132 MSG=b1 git notes add -f &&
133 test ! -f .git/NOTES_EDITMSG &&
134 test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
135 test b1 = $(git notes show) &&
136 git show HEAD^ &&
137 test_must_fail git notes show HEAD^
140 cat > expect << EOF
141 commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
142 Author: A U Thor <author@example.com>
143 Date: Thu Apr 7 15:14:13 2005 -0700
147 Notes:
151 test_expect_success 'show notes' '
152 ! (git cat-file commit HEAD | grep b1) &&
153 git log -1 > output &&
154 test_cmp expect output
157 test_expect_success 'create multi-line notes (setup)' '
158 : > a3 &&
159 git add a3 &&
160 test_tick &&
161 git commit -m 3rd &&
162 MSG="b3
163 c3c3c3c3
164 d3d3d3" git notes add
167 cat > expect-multiline << EOF
168 commit 1584215f1d29c65e99c6c6848626553fdd07fd75
169 Author: A U Thor <author@example.com>
170 Date: Thu Apr 7 15:15:13 2005 -0700
174 Notes:
176 c3c3c3c3
177 d3d3d3
180 printf "\n" >> expect-multiline
181 cat expect >> expect-multiline
183 test_expect_success 'show multi-line notes' '
184 git log -2 > output &&
185 test_cmp expect-multiline output
187 test_expect_success 'create -F notes (setup)' '
188 : > a4 &&
189 git add a4 &&
190 test_tick &&
191 git commit -m 4th &&
192 echo "xyzzy" > note5 &&
193 git notes add -F note5
196 cat > expect-F << EOF
197 commit 15023535574ded8b1a89052b32673f84cf9582b8
198 Author: A U Thor <author@example.com>
199 Date: Thu Apr 7 15:16:13 2005 -0700
203 Notes:
204 xyzzy
207 printf "\n" >> expect-F
208 cat expect-multiline >> expect-F
210 test_expect_success 'show -F notes' '
211 git log -3 > output &&
212 test_cmp expect-F output
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 > output &&
219 test_cmp expect-F output
222 cat >expect << EOF
223 commit 15023535574ded8b1a89052b32673f84cf9582b8
224 tree e070e3af51011e47b183c33adf9736736a525709
225 parent 1584215f1d29c65e99c6c6848626553fdd07fd75
226 author A U Thor <author@example.com> 1112912173 -0700
227 committer C O Mitter <committer@example.com> 1112912173 -0700
231 test_expect_success 'git log --pretty=raw does not show notes' '
232 git log -1 --pretty=raw >output &&
233 test_cmp expect output
236 cat >>expect <<EOF
238 Notes:
239 xyzzy
241 test_expect_success 'git log --show-notes' '
242 git log -1 --pretty=raw --show-notes >output &&
243 test_cmp expect output
246 test_expect_success 'git log --no-notes' '
247 git log -1 --no-notes >output &&
248 ! grep xyzzy output
251 test_expect_success 'git format-patch does not show notes' '
252 git format-patch -1 --stdout >output &&
253 ! grep xyzzy output
256 test_expect_success 'git format-patch --show-notes does show notes' '
257 git format-patch --show-notes -1 --stdout >output &&
258 grep xyzzy output
261 for pretty in \
262 "" --pretty --pretty=raw --pretty=short --pretty=medium \
263 --pretty=full --pretty=fuller --pretty=format:%s --oneline
265 case "$pretty" in
266 "") p= not= negate="" ;;
267 ?*) p="$pretty" not=" not" negate="!" ;;
268 esac
269 test_expect_success "git show $pretty does$not show notes" '
270 git show $p >output &&
271 eval "$negate grep xyzzy output"
273 done
275 test_expect_success 'setup alternate notes ref' '
276 git notes --ref=alternate add -m alternate
279 test_expect_success 'git log --notes shows default notes' '
280 git log -1 --notes >output &&
281 grep xyzzy output &&
282 ! grep alternate output
285 test_expect_success 'git log --notes=X shows only X' '
286 git log -1 --notes=alternate >output &&
287 ! grep xyzzy output &&
288 grep alternate output
291 test_expect_success 'git log --notes --notes=X shows both' '
292 git log -1 --notes --notes=alternate >output &&
293 grep xyzzy output &&
294 grep alternate output
297 test_expect_success 'git log --no-notes resets default state' '
298 git log -1 --notes --notes=alternate \
299 --no-notes --notes=alternate \
300 >output &&
301 ! grep xyzzy output &&
302 grep alternate output
305 test_expect_success 'git log --no-notes resets ref list' '
306 git log -1 --notes --notes=alternate \
307 --no-notes --notes \
308 >output &&
309 grep xyzzy output &&
310 ! grep alternate output
313 test_expect_success 'create -m notes (setup)' '
314 : > a5 &&
315 git add a5 &&
316 test_tick &&
317 git commit -m 5th &&
318 git notes add -m spam -m "foo
320 baz"
323 whitespace=" "
324 cat > expect-m << EOF
325 commit bd1753200303d0a0344be813e504253b3d98e74d
326 Author: A U Thor <author@example.com>
327 Date: Thu Apr 7 15:17:13 2005 -0700
331 Notes:
332 spam
333 $whitespace
339 printf "\n" >> expect-m
340 cat expect-F >> expect-m
342 test_expect_success 'show -m notes' '
343 git log -4 > output &&
344 test_cmp expect-m output
347 test_expect_success 'remove note with add -f -F /dev/null (setup)' '
348 git notes add -f -F /dev/null
351 cat > expect-rm-F << EOF
352 commit bd1753200303d0a0344be813e504253b3d98e74d
353 Author: A U Thor <author@example.com>
354 Date: Thu Apr 7 15:17:13 2005 -0700
359 printf "\n" >> expect-rm-F
360 cat expect-F >> expect-rm-F
362 test_expect_success 'verify note removal with -F /dev/null' '
363 git log -4 > output &&
364 test_cmp expect-rm-F output &&
365 test_must_fail git notes show
368 test_expect_success 'do not create empty note with -m "" (setup)' '
369 git notes add -m ""
372 test_expect_success 'verify non-creation of note with -m ""' '
373 git log -4 > output &&
374 test_cmp expect-rm-F output &&
375 test_must_fail git notes show
378 cat > expect-combine_m_and_F << EOF
381 xyzzy
385 zyxxy
390 test_expect_success 'create note with combination of -m and -F' '
391 echo "xyzzy" > note_a &&
392 echo "zyxxy" > note_b &&
393 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
394 git notes show > output &&
395 test_cmp expect-combine_m_and_F output
398 test_expect_success 'remove note with "git notes remove" (setup)' '
399 git notes remove HEAD^ &&
400 git notes remove
403 cat > expect-rm-remove << EOF
404 commit bd1753200303d0a0344be813e504253b3d98e74d
405 Author: A U Thor <author@example.com>
406 Date: Thu Apr 7 15:17:13 2005 -0700
410 commit 15023535574ded8b1a89052b32673f84cf9582b8
411 Author: A U Thor <author@example.com>
412 Date: Thu Apr 7 15:16:13 2005 -0700
417 printf "\n" >> expect-rm-remove
418 cat expect-multiline >> expect-rm-remove
420 test_expect_success 'verify note removal with "git notes remove"' '
421 git log -4 > output &&
422 test_cmp expect-rm-remove output &&
423 test_must_fail git notes show HEAD^
426 cat > expect << EOF
427 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
428 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
431 test_expect_success 'removing non-existing note should not create new commit' '
432 git rev-parse --verify refs/notes/commits > before_commit &&
433 test_must_fail git notes remove HEAD^ &&
434 git rev-parse --verify refs/notes/commits > after_commit &&
435 test_cmp before_commit after_commit
438 test_expect_success 'removing more than one' '
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 notes remove HEAD^^ HEAD^^^ &&
446 git notes list | sed -e "s/ .*//" >actual &&
447 test_cmp after-removal-expect actual
450 test_expect_success 'removing is atomic' '
451 before=$(git rev-parse --verify refs/notes/commits) &&
452 test_when_finished "git update-ref refs/notes/commits $before" &&
453 test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
454 after=$(git rev-parse --verify refs/notes/commits) &&
455 test "$before" = "$after"
458 test_expect_success 'removing with --ignore-missing' '
459 before=$(git rev-parse --verify refs/notes/commits) &&
460 test_when_finished "git update-ref refs/notes/commits $before" &&
462 # We have only two -- add another and make sure it stays
463 git notes add -m "extra" &&
464 git notes list HEAD >after-removal-expect &&
465 git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
466 git notes list | sed -e "s/ .*//" >actual &&
467 test_cmp after-removal-expect actual
470 test_expect_success 'removing with --ignore-missing but bogus ref' '
471 before=$(git rev-parse --verify refs/notes/commits) &&
472 test_when_finished "git update-ref refs/notes/commits $before" &&
473 test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
474 after=$(git rev-parse --verify refs/notes/commits) &&
475 test "$before" = "$after"
478 test_expect_success 'remove reads from --stdin' '
479 before=$(git rev-parse --verify refs/notes/commits) &&
480 test_when_finished "git update-ref refs/notes/commits $before" &&
482 # We have only two -- add another and make sure it stays
483 git notes add -m "extra" &&
484 git notes list HEAD >after-removal-expect &&
485 git rev-parse HEAD^^ HEAD^^^ >input &&
486 git notes remove --stdin <input &&
487 git notes list | sed -e "s/ .*//" >actual &&
488 test_cmp after-removal-expect actual
491 test_expect_success 'remove --stdin is also atomic' '
492 before=$(git rev-parse --verify refs/notes/commits) &&
493 test_when_finished "git update-ref refs/notes/commits $before" &&
494 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
495 test_must_fail git notes remove --stdin <input &&
496 after=$(git rev-parse --verify refs/notes/commits) &&
497 test "$before" = "$after"
500 test_expect_success 'removing with --stdin --ignore-missing' '
501 before=$(git rev-parse --verify refs/notes/commits) &&
502 test_when_finished "git update-ref refs/notes/commits $before" &&
504 # We have only two -- add another and make sure it stays
505 git notes add -m "extra" &&
506 git notes list HEAD >after-removal-expect &&
507 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
508 git notes remove --ignore-missing --stdin <input &&
509 git notes list | sed -e "s/ .*//" >actual &&
510 test_cmp after-removal-expect actual
513 test_expect_success 'list notes with "git notes list"' '
514 git notes list > output &&
515 test_cmp expect output
518 test_expect_success 'list notes with "git notes"' '
519 git notes > output &&
520 test_cmp expect output
523 cat > expect << EOF
524 c18dc024e14f08d18d14eea0d747ff692d66d6a3
527 test_expect_success 'list specific note with "git notes list <object>"' '
528 git notes list HEAD^^ > output &&
529 test_cmp expect output
532 cat > expect << EOF
535 test_expect_success 'listing non-existing notes fails' '
536 test_must_fail git notes list HEAD > output &&
537 test_cmp expect output
540 cat > expect << EOF
541 Initial set of notes
543 More notes appended with git notes append
546 test_expect_success 'append to existing note with "git notes append"' '
547 git notes add -m "Initial set of notes" &&
548 git notes append -m "More notes appended with git notes append" &&
549 git notes show > output &&
550 test_cmp expect output
553 cat > expect_list << EOF
554 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
555 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
556 4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
559 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
560 git notes list > output &&
561 test_cmp expect_list output
564 test_expect_success 'appending empty string does not change existing note' '
565 git notes append -m "" &&
566 git notes show > output &&
567 test_cmp expect output
570 test_expect_success 'git notes append == add when there is no existing note' '
571 git notes remove HEAD &&
572 test_must_fail git notes list HEAD &&
573 git notes append -m "Initial set of notes
575 More notes appended with git notes append" &&
576 git notes show > output &&
577 test_cmp expect output
580 test_expect_success 'appending empty string to non-existing note does not create note' '
581 git notes remove HEAD &&
582 test_must_fail git notes list HEAD &&
583 git notes append -m "" &&
584 test_must_fail git notes list HEAD
587 test_expect_success 'create other note on a different notes ref (setup)' '
588 : > a6 &&
589 git add a6 &&
590 test_tick &&
591 git commit -m 6th &&
592 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
595 cat > expect-other << EOF
596 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
597 Author: A U Thor <author@example.com>
598 Date: Thu Apr 7 15:18:13 2005 -0700
602 Notes (other):
603 other note
606 cat > expect-not-other << EOF
607 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
608 Author: A U Thor <author@example.com>
609 Date: Thu Apr 7 15:18:13 2005 -0700
614 test_expect_success 'Do not show note on other ref by default' '
615 git log -1 > output &&
616 test_cmp expect-not-other output
619 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
620 GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
621 test_cmp expect-other output
624 test_expect_success 'Do show note when ref is given in core.notesRef config' '
625 git config core.notesRef "refs/notes/other" &&
626 git log -1 > output &&
627 test_cmp expect-other output
630 test_expect_success 'Do not show note when core.notesRef is overridden' '
631 GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
632 test_cmp expect-not-other output
635 cat > expect-both << EOF
636 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
637 Author: A U Thor <author@example.com>
638 Date: Thu Apr 7 15:18:13 2005 -0700
642 Notes:
643 order test
645 Notes (other):
646 other note
648 commit bd1753200303d0a0344be813e504253b3d98e74d
649 Author: A U Thor <author@example.com>
650 Date: Thu Apr 7 15:17:13 2005 -0700
654 Notes:
655 replacement for deleted note
658 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
659 GIT_NOTES_REF=refs/notes/commits git notes add \
660 -m"replacement for deleted note" HEAD^ &&
661 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
662 git config --unset core.notesRef &&
663 git config notes.displayRef "refs/notes/*" &&
664 git log -2 > output &&
665 test_cmp expect-both output
668 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
669 git config core.notesRef refs/notes/commits &&
670 git config notes.displayRef refs/notes/other &&
671 git log -2 > output &&
672 test_cmp expect-both output
675 test_expect_success 'notes.displayRef can be given more than once' '
676 git config --unset core.notesRef &&
677 git config notes.displayRef refs/notes/commits &&
678 git config --add notes.displayRef refs/notes/other &&
679 git log -2 > output &&
680 test_cmp expect-both output
683 cat > expect-both-reversed << EOF
684 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
685 Author: A U Thor <author@example.com>
686 Date: Thu Apr 7 15:18:13 2005 -0700
690 Notes (other):
691 other note
693 Notes:
694 order test
697 test_expect_success 'notes.displayRef respects order' '
698 git config core.notesRef refs/notes/other &&
699 git config --unset-all notes.displayRef &&
700 git config notes.displayRef refs/notes/commits &&
701 git log -1 > output &&
702 test_cmp expect-both-reversed output
705 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
706 git config --unset-all core.notesRef &&
707 git config --unset-all notes.displayRef &&
708 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
709 git log -2 > output &&
710 test_cmp expect-both output
713 cat > expect-none << EOF
714 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
715 Author: A U Thor <author@example.com>
716 Date: Thu Apr 7 15:18:13 2005 -0700
720 commit bd1753200303d0a0344be813e504253b3d98e74d
721 Author: A U Thor <author@example.com>
722 Date: Thu Apr 7 15:17:13 2005 -0700
727 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
728 git config notes.displayRef "refs/notes/*" &&
729 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
730 test_cmp expect-none output
733 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
734 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
735 test_cmp expect-both output
738 cat > expect-commits << EOF
739 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
740 Author: A U Thor <author@example.com>
741 Date: Thu Apr 7 15:18:13 2005 -0700
745 Notes:
746 order test
749 test_expect_success '--no-standard-notes' '
750 git log --no-standard-notes --show-notes=commits -1 > output &&
751 test_cmp expect-commits output
754 test_expect_success '--standard-notes' '
755 git log --no-standard-notes --show-notes=commits \
756 --standard-notes -2 > output &&
757 test_cmp expect-both output
760 test_expect_success '--show-notes=ref accumulates' '
761 git log --show-notes=other --show-notes=commits \
762 --no-standard-notes -1 > output &&
763 test_cmp expect-both-reversed output
766 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
767 git config core.notesRef refs/notes/other &&
768 echo "Note on a tree" > expect &&
769 git notes add -m "Note on a tree" HEAD: &&
770 git notes show HEAD: > actual &&
771 test_cmp expect actual &&
772 echo "Note on a blob" > expect &&
773 filename=$(git ls-tree --name-only HEAD | head -n1) &&
774 git notes add -m "Note on a blob" HEAD:$filename &&
775 git notes show HEAD:$filename > actual &&
776 test_cmp expect actual &&
777 echo "Note on a tag" > expect &&
778 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
779 git notes add -m "Note on a tag" foobar &&
780 git notes show foobar > actual &&
781 test_cmp expect actual
784 cat > expect << EOF
785 commit 2ede89468182a62d0bde2583c736089bcf7d7e92
786 Author: A U Thor <author@example.com>
787 Date: Thu Apr 7 15:19:13 2005 -0700
791 Notes (other):
792 other note
795 test_expect_success 'create note from other note with "git notes add -C"' '
796 : > a7 &&
797 git add a7 &&
798 test_tick &&
799 git commit -m 7th &&
800 git notes add -C $(git notes list HEAD^) &&
801 git log -1 > actual &&
802 test_cmp expect actual &&
803 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
806 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
807 : > a8 &&
808 git add a8 &&
809 test_tick &&
810 git commit -m 8th &&
811 test_must_fail git notes add -C deadbeef &&
812 test_must_fail git notes list HEAD
815 test_expect_success 'create note from non-blob with "git notes add -C" fails' '
816 commit=$(git rev-parse --verify HEAD) &&
817 tree=$(git rev-parse --verify HEAD:) &&
818 test_must_fail git notes add -C $commit &&
819 test_must_fail git notes add -C $tree &&
820 test_must_fail git notes list HEAD
823 cat > expect << EOF
824 commit 80d796defacd5db327b7a4e50099663902fbdc5c
825 Author: A U Thor <author@example.com>
826 Date: Thu Apr 7 15:20:13 2005 -0700
830 Notes (other):
831 This is a blob object
834 test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
835 blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
836 git notes add -C $blob &&
837 git log -1 > actual &&
838 test_cmp expect actual &&
839 test "$(git notes list HEAD)" = "$blob"
842 cat > expect << EOF
843 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
844 Author: A U Thor <author@example.com>
845 Date: Thu Apr 7 15:21:13 2005 -0700
849 Notes (other):
850 yet another note
853 test_expect_success 'create note from other note with "git notes add -c"' '
854 : > a9 &&
855 git add a9 &&
856 test_tick &&
857 git commit -m 9th &&
858 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
859 git log -1 > actual &&
860 test_cmp expect actual
863 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
864 : > a10 &&
865 git add a10 &&
866 test_tick &&
867 git commit -m 10th &&
869 MSG="yet another note" &&
870 export MSG &&
871 test_must_fail git notes add -c deadbeef
872 ) &&
873 test_must_fail git notes list HEAD
876 cat > expect << EOF
877 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
878 Author: A U Thor <author@example.com>
879 Date: Thu Apr 7 15:21:13 2005 -0700
883 Notes (other):
884 yet another note
885 $whitespace
886 yet another note
889 test_expect_success 'append to note from other note with "git notes append -C"' '
890 git notes append -C $(git notes list HEAD^) HEAD^ &&
891 git log -1 HEAD^ > actual &&
892 test_cmp expect actual
895 cat > expect << EOF
896 commit ffed603236bfa3891c49644257a83598afe8ae5a
897 Author: A U Thor <author@example.com>
898 Date: Thu Apr 7 15:22:13 2005 -0700
900 10th
902 Notes (other):
903 other note
906 test_expect_success 'create note from other note with "git notes append -c"' '
907 MSG="other note" git notes append -c $(git notes list HEAD^) &&
908 git log -1 > actual &&
909 test_cmp expect actual
912 cat > expect << EOF
913 commit ffed603236bfa3891c49644257a83598afe8ae5a
914 Author: A U Thor <author@example.com>
915 Date: Thu Apr 7 15:22:13 2005 -0700
917 10th
919 Notes (other):
920 other note
921 $whitespace
922 yet another note
925 test_expect_success 'append to note from other note with "git notes append -c"' '
926 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
927 git log -1 > actual &&
928 test_cmp expect actual
931 cat > expect << EOF
932 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
933 Author: A U Thor <author@example.com>
934 Date: Thu Apr 7 15:23:13 2005 -0700
936 11th
938 Notes (other):
939 other note
940 $whitespace
941 yet another note
944 test_expect_success 'copy note with "git notes copy"' '
945 : > a11 &&
946 git add a11 &&
947 test_tick &&
948 git commit -m 11th &&
949 git notes copy HEAD^ HEAD &&
950 git log -1 > actual &&
951 test_cmp expect actual &&
952 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
955 test_expect_success 'prevent overwrite with "git notes copy"' '
956 test_must_fail git notes copy HEAD~2 HEAD &&
957 git log -1 > actual &&
958 test_cmp expect actual &&
959 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
962 cat > expect << EOF
963 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
964 Author: A U Thor <author@example.com>
965 Date: Thu Apr 7 15:23:13 2005 -0700
967 11th
969 Notes (other):
970 yet another note
971 $whitespace
972 yet another note
975 test_expect_success 'allow overwrite with "git notes copy -f"' '
976 git notes copy -f HEAD~2 HEAD &&
977 git log -1 > actual &&
978 test_cmp expect actual &&
979 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
982 test_expect_success 'cannot copy note from object without notes' '
983 : > a12 &&
984 git add a12 &&
985 test_tick &&
986 git commit -m 12th &&
987 : > a13 &&
988 git add a13 &&
989 test_tick &&
990 git commit -m 13th &&
991 test_must_fail git notes copy HEAD^ HEAD
994 cat > expect << EOF
995 commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
996 Author: A U Thor <author@example.com>
997 Date: Thu Apr 7 15:25:13 2005 -0700
999 13th
1001 Notes (other):
1002 yet another note
1003 $whitespace
1004 yet another note
1006 commit 7038787dfe22a14c3867ce816dbba39845359719
1007 Author: A U Thor <author@example.com>
1008 Date: Thu Apr 7 15:24:13 2005 -0700
1010 12th
1012 Notes (other):
1013 other note
1014 $whitespace
1015 yet another note
1018 test_expect_success 'git notes copy --stdin' '
1019 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
1020 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
1021 git notes copy --stdin &&
1022 git log -2 > output &&
1023 test_cmp expect output &&
1024 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
1025 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
1028 cat > expect << EOF
1029 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1030 Author: A U Thor <author@example.com>
1031 Date: Thu Apr 7 15:27:13 2005 -0700
1033 15th
1035 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
1036 Author: A U Thor <author@example.com>
1037 Date: Thu Apr 7 15:26:13 2005 -0700
1039 14th
1042 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
1043 test_commit 14th &&
1044 test_commit 15th &&
1045 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
1046 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
1047 git notes copy --for-rewrite=foo &&
1048 git log -2 > output &&
1049 test_cmp expect output
1052 cat > expect << EOF
1053 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1054 Author: A U Thor <author@example.com>
1055 Date: Thu Apr 7 15:27:13 2005 -0700
1057 15th
1059 Notes (other):
1060 yet another note
1061 $whitespace
1062 yet another note
1064 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
1065 Author: A U Thor <author@example.com>
1066 Date: Thu Apr 7 15:26:13 2005 -0700
1068 14th
1070 Notes (other):
1071 other note
1072 $whitespace
1073 yet another note
1076 test_expect_success 'git notes copy --for-rewrite (enabled)' '
1077 git config notes.rewriteMode overwrite &&
1078 git config notes.rewriteRef "refs/notes/*" &&
1079 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
1080 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
1081 git notes copy --for-rewrite=foo &&
1082 git log -2 > output &&
1083 test_cmp expect output
1086 test_expect_success 'git notes copy --for-rewrite (disabled)' '
1087 git config notes.rewrite.bar false &&
1088 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
1089 git notes copy --for-rewrite=bar &&
1090 git log -2 > output &&
1091 test_cmp expect output
1094 cat > expect << EOF
1095 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1096 Author: A U Thor <author@example.com>
1097 Date: Thu Apr 7 15:27:13 2005 -0700
1099 15th
1101 Notes (other):
1102 a fresh note
1105 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
1106 git notes add -f -m"a fresh note" HEAD^ &&
1107 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1108 git notes copy --for-rewrite=foo &&
1109 git log -1 > output &&
1110 test_cmp expect output
1113 test_expect_success 'git notes copy --for-rewrite (ignore)' '
1114 git config notes.rewriteMode ignore &&
1115 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1116 git notes copy --for-rewrite=foo &&
1117 git log -1 > output &&
1118 test_cmp expect output
1121 cat > expect << EOF
1122 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1123 Author: A U Thor <author@example.com>
1124 Date: Thu Apr 7 15:27:13 2005 -0700
1126 15th
1128 Notes (other):
1129 a fresh note
1130 $whitespace
1131 another fresh note
1134 test_expect_success 'git notes copy --for-rewrite (append)' '
1135 git notes add -f -m"another fresh note" HEAD^ &&
1136 git config notes.rewriteMode concatenate &&
1137 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1138 git notes copy --for-rewrite=foo &&
1139 git log -1 > output &&
1140 test_cmp expect output
1143 cat > expect << EOF
1144 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1145 Author: A U Thor <author@example.com>
1146 Date: Thu Apr 7 15:27:13 2005 -0700
1148 15th
1150 Notes (other):
1151 a fresh note
1152 $whitespace
1153 another fresh note
1154 $whitespace
1155 append 1
1156 $whitespace
1157 append 2
1160 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1161 git notes add -f -m"append 1" HEAD^ &&
1162 git notes add -f -m"append 2" HEAD^^ &&
1163 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
1164 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1165 git notes copy --for-rewrite=foo &&
1166 git log -1 > output &&
1167 test_cmp expect output
1170 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1171 git notes remove HEAD^ &&
1172 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1173 git notes copy --for-rewrite=foo &&
1174 git log -1 > output &&
1175 test_cmp expect output
1178 cat > expect << EOF
1179 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1180 Author: A U Thor <author@example.com>
1181 Date: Thu Apr 7 15:27:13 2005 -0700
1183 15th
1185 Notes (other):
1186 replacement note 1
1189 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1190 git notes add -f -m"replacement note 1" HEAD^ &&
1191 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1192 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1193 git log -1 > output &&
1194 test_cmp expect output
1197 cat > expect << EOF
1198 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1199 Author: A U Thor <author@example.com>
1200 Date: Thu Apr 7 15:27:13 2005 -0700
1202 15th
1204 Notes (other):
1205 replacement note 2
1208 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1209 git config notes.rewriteMode overwrite &&
1210 git notes add -f -m"replacement note 2" HEAD^ &&
1211 git config --unset-all notes.rewriteRef &&
1212 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1213 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1214 git notes copy --for-rewrite=foo &&
1215 git log -1 > output &&
1216 test_cmp expect output
1219 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1220 git config notes.rewriteRef refs/notes/other &&
1221 git notes add -f -m"replacement note 3" HEAD^ &&
1222 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1223 GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1224 git log -1 > output &&
1225 test_cmp expect output
1228 test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1229 test_must_fail git notes copy &&
1230 test_must_fail git notes copy one two three
1233 test_expect_success 'git notes get-ref (no overrides)' '
1234 git config --unset core.notesRef &&
1235 sane_unset GIT_NOTES_REF &&
1236 test "$(git notes get-ref)" = "refs/notes/commits"
1239 test_expect_success 'git notes get-ref (core.notesRef)' '
1240 git config core.notesRef refs/notes/foo &&
1241 test "$(git notes get-ref)" = "refs/notes/foo"
1244 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1245 test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1248 test_expect_success 'git notes get-ref (--ref)' '
1249 test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1252 test_done