diff.c: omit hidden entries from namelen calculation with --stat
[git/dscho.git] / t / t3301-notes.sh
blob28e17c8920cbe9f2b13ff5cc30939eab8171bae2
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 'list notes with "git notes list"' '
439 git notes list > output &&
440 test_cmp expect output
443 test_expect_success 'list notes with "git notes"' '
444 git notes > output &&
445 test_cmp expect output
448 cat > expect << EOF
449 c18dc024e14f08d18d14eea0d747ff692d66d6a3
452 test_expect_success 'list specific note with "git notes list <object>"' '
453 git notes list HEAD^^ > output &&
454 test_cmp expect output
457 cat > expect << EOF
460 test_expect_success 'listing non-existing notes fails' '
461 test_must_fail git notes list HEAD > output &&
462 test_cmp expect output
465 cat > expect << EOF
466 Initial set of notes
468 More notes appended with git notes append
471 test_expect_success 'append to existing note with "git notes append"' '
472 git notes add -m "Initial set of notes" &&
473 git notes append -m "More notes appended with git notes append" &&
474 git notes show > output &&
475 test_cmp expect output
478 cat > expect_list << EOF
479 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
480 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
481 4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
484 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
485 git notes list > output &&
486 test_cmp expect_list output
489 test_expect_success 'appending empty string does not change existing note' '
490 git notes append -m "" &&
491 git notes show > output &&
492 test_cmp expect output
495 test_expect_success 'git notes append == add when there is no existing note' '
496 git notes remove HEAD &&
497 test_must_fail git notes list HEAD &&
498 git notes append -m "Initial set of notes
500 More notes appended with git notes append" &&
501 git notes show > output &&
502 test_cmp expect output
505 test_expect_success 'appending empty string to non-existing note does not create note' '
506 git notes remove HEAD &&
507 test_must_fail git notes list HEAD &&
508 git notes append -m "" &&
509 test_must_fail git notes list HEAD
512 test_expect_success 'create other note on a different notes ref (setup)' '
513 : > a6 &&
514 git add a6 &&
515 test_tick &&
516 git commit -m 6th &&
517 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
520 cat > expect-other << EOF
521 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
522 Author: A U Thor <author@example.com>
523 Date: Thu Apr 7 15:18:13 2005 -0700
527 Notes (other):
528 other note
531 cat > expect-not-other << EOF
532 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
533 Author: A U Thor <author@example.com>
534 Date: Thu Apr 7 15:18:13 2005 -0700
539 test_expect_success 'Do not show note on other ref by default' '
540 git log -1 > output &&
541 test_cmp expect-not-other output
544 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
545 GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
546 test_cmp expect-other output
549 test_expect_success 'Do show note when ref is given in core.notesRef config' '
550 git config core.notesRef "refs/notes/other" &&
551 git log -1 > output &&
552 test_cmp expect-other output
555 test_expect_success 'Do not show note when core.notesRef is overridden' '
556 GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
557 test_cmp expect-not-other output
560 cat > expect-both << EOF
561 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
562 Author: A U Thor <author@example.com>
563 Date: Thu Apr 7 15:18:13 2005 -0700
567 Notes:
568 order test
570 Notes (other):
571 other note
573 commit bd1753200303d0a0344be813e504253b3d98e74d
574 Author: A U Thor <author@example.com>
575 Date: Thu Apr 7 15:17:13 2005 -0700
579 Notes:
580 replacement for deleted note
583 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
584 GIT_NOTES_REF=refs/notes/commits git notes add \
585 -m"replacement for deleted note" HEAD^ &&
586 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
587 git config --unset core.notesRef &&
588 git config notes.displayRef "refs/notes/*" &&
589 git log -2 > output &&
590 test_cmp expect-both output
593 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
594 git config core.notesRef refs/notes/commits &&
595 git config notes.displayRef refs/notes/other &&
596 git log -2 > output &&
597 test_cmp expect-both output
600 test_expect_success 'notes.displayRef can be given more than once' '
601 git config --unset core.notesRef &&
602 git config notes.displayRef refs/notes/commits &&
603 git config --add notes.displayRef refs/notes/other &&
604 git log -2 > output &&
605 test_cmp expect-both output
608 cat > expect-both-reversed << EOF
609 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
610 Author: A U Thor <author@example.com>
611 Date: Thu Apr 7 15:18:13 2005 -0700
615 Notes (other):
616 other note
618 Notes:
619 order test
622 test_expect_success 'notes.displayRef respects order' '
623 git config core.notesRef refs/notes/other &&
624 git config --unset-all notes.displayRef &&
625 git config notes.displayRef refs/notes/commits &&
626 git log -1 > output &&
627 test_cmp expect-both-reversed output
630 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
631 git config --unset-all core.notesRef &&
632 git config --unset-all notes.displayRef &&
633 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
634 git log -2 > output &&
635 test_cmp expect-both output
638 cat > expect-none << EOF
639 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
640 Author: A U Thor <author@example.com>
641 Date: Thu Apr 7 15:18:13 2005 -0700
645 commit bd1753200303d0a0344be813e504253b3d98e74d
646 Author: A U Thor <author@example.com>
647 Date: Thu Apr 7 15:17:13 2005 -0700
652 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
653 git config notes.displayRef "refs/notes/*" &&
654 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
655 test_cmp expect-none output
658 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
659 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
660 test_cmp expect-both output
663 cat > expect-commits << EOF
664 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
665 Author: A U Thor <author@example.com>
666 Date: Thu Apr 7 15:18:13 2005 -0700
670 Notes:
671 order test
674 test_expect_success '--no-standard-notes' '
675 git log --no-standard-notes --show-notes=commits -1 > output &&
676 test_cmp expect-commits output
679 test_expect_success '--standard-notes' '
680 git log --no-standard-notes --show-notes=commits \
681 --standard-notes -2 > output &&
682 test_cmp expect-both output
685 test_expect_success '--show-notes=ref accumulates' '
686 git log --show-notes=other --show-notes=commits \
687 --no-standard-notes -1 > output &&
688 test_cmp expect-both-reversed output
691 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
692 git config core.notesRef refs/notes/other &&
693 echo "Note on a tree" > expect &&
694 git notes add -m "Note on a tree" HEAD: &&
695 git notes show HEAD: > actual &&
696 test_cmp expect actual &&
697 echo "Note on a blob" > expect &&
698 filename=$(git ls-tree --name-only HEAD | head -n1) &&
699 git notes add -m "Note on a blob" HEAD:$filename &&
700 git notes show HEAD:$filename > actual &&
701 test_cmp expect actual &&
702 echo "Note on a tag" > expect &&
703 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
704 git notes add -m "Note on a tag" foobar &&
705 git notes show foobar > actual &&
706 test_cmp expect actual
709 cat > expect << EOF
710 commit 2ede89468182a62d0bde2583c736089bcf7d7e92
711 Author: A U Thor <author@example.com>
712 Date: Thu Apr 7 15:19:13 2005 -0700
716 Notes (other):
717 other note
720 test_expect_success 'create note from other note with "git notes add -C"' '
721 : > a7 &&
722 git add a7 &&
723 test_tick &&
724 git commit -m 7th &&
725 git notes add -C $(git notes list HEAD^) &&
726 git log -1 > actual &&
727 test_cmp expect actual &&
728 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
731 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
732 : > a8 &&
733 git add a8 &&
734 test_tick &&
735 git commit -m 8th &&
736 test_must_fail git notes add -C deadbeef &&
737 test_must_fail git notes list HEAD
740 cat > expect << EOF
741 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
742 Author: A U Thor <author@example.com>
743 Date: Thu Apr 7 15:21:13 2005 -0700
747 Notes (other):
748 yet another note
751 test_expect_success 'create note from other note with "git notes add -c"' '
752 : > a9 &&
753 git add a9 &&
754 test_tick &&
755 git commit -m 9th &&
756 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
757 git log -1 > actual &&
758 test_cmp expect actual
761 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
762 : > a10 &&
763 git add a10 &&
764 test_tick &&
765 git commit -m 10th &&
767 MSG="yet another note" &&
768 export MSG &&
769 test_must_fail git notes add -c deadbeef
770 ) &&
771 test_must_fail git notes list HEAD
774 cat > expect << EOF
775 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
776 Author: A U Thor <author@example.com>
777 Date: Thu Apr 7 15:21:13 2005 -0700
781 Notes (other):
782 yet another note
783 $whitespace
784 yet another note
787 test_expect_success 'append to note from other note with "git notes append -C"' '
788 git notes append -C $(git notes list HEAD^) HEAD^ &&
789 git log -1 HEAD^ > actual &&
790 test_cmp expect actual
793 cat > expect << EOF
794 commit ffed603236bfa3891c49644257a83598afe8ae5a
795 Author: A U Thor <author@example.com>
796 Date: Thu Apr 7 15:22:13 2005 -0700
798 10th
800 Notes (other):
801 other note
804 test_expect_success 'create note from other note with "git notes append -c"' '
805 MSG="other note" git notes append -c $(git notes list HEAD^) &&
806 git log -1 > actual &&
807 test_cmp expect actual
810 cat > expect << EOF
811 commit ffed603236bfa3891c49644257a83598afe8ae5a
812 Author: A U Thor <author@example.com>
813 Date: Thu Apr 7 15:22:13 2005 -0700
815 10th
817 Notes (other):
818 other note
819 $whitespace
820 yet another note
823 test_expect_success 'append to note from other note with "git notes append -c"' '
824 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
825 git log -1 > actual &&
826 test_cmp expect actual
829 cat > expect << EOF
830 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
831 Author: A U Thor <author@example.com>
832 Date: Thu Apr 7 15:23:13 2005 -0700
834 11th
836 Notes (other):
837 other note
838 $whitespace
839 yet another note
842 test_expect_success 'copy note with "git notes copy"' '
843 : > a11 &&
844 git add a11 &&
845 test_tick &&
846 git commit -m 11th &&
847 git notes copy HEAD^ HEAD &&
848 git log -1 > actual &&
849 test_cmp expect actual &&
850 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
853 test_expect_success 'prevent overwrite with "git notes copy"' '
854 test_must_fail git notes copy HEAD~2 HEAD &&
855 git log -1 > actual &&
856 test_cmp expect actual &&
857 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
860 cat > expect << EOF
861 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
862 Author: A U Thor <author@example.com>
863 Date: Thu Apr 7 15:23:13 2005 -0700
865 11th
867 Notes (other):
868 yet another note
869 $whitespace
870 yet another note
873 test_expect_success 'allow overwrite with "git notes copy -f"' '
874 git notes copy -f HEAD~2 HEAD &&
875 git log -1 > actual &&
876 test_cmp expect actual &&
877 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
880 test_expect_success 'cannot copy note from object without notes' '
881 : > a12 &&
882 git add a12 &&
883 test_tick &&
884 git commit -m 12th &&
885 : > a13 &&
886 git add a13 &&
887 test_tick &&
888 git commit -m 13th &&
889 test_must_fail git notes copy HEAD^ HEAD
892 cat > expect << EOF
893 commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
894 Author: A U Thor <author@example.com>
895 Date: Thu Apr 7 15:25:13 2005 -0700
897 13th
899 Notes (other):
900 yet another note
901 $whitespace
902 yet another note
904 commit 7038787dfe22a14c3867ce816dbba39845359719
905 Author: A U Thor <author@example.com>
906 Date: Thu Apr 7 15:24:13 2005 -0700
908 12th
910 Notes (other):
911 other note
912 $whitespace
913 yet another note
916 test_expect_success 'git notes copy --stdin' '
917 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
918 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
919 git notes copy --stdin &&
920 git log -2 > output &&
921 test_cmp expect output &&
922 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
923 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
926 cat > expect << EOF
927 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
928 Author: A U Thor <author@example.com>
929 Date: Thu Apr 7 15:27:13 2005 -0700
931 15th
933 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
934 Author: A U Thor <author@example.com>
935 Date: Thu Apr 7 15:26:13 2005 -0700
937 14th
940 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
941 test_commit 14th &&
942 test_commit 15th &&
943 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
944 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
945 git notes copy --for-rewrite=foo &&
946 git log -2 > output &&
947 test_cmp expect output
950 cat > expect << EOF
951 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
952 Author: A U Thor <author@example.com>
953 Date: Thu Apr 7 15:27:13 2005 -0700
955 15th
957 Notes (other):
958 yet another note
959 $whitespace
960 yet another note
962 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
963 Author: A U Thor <author@example.com>
964 Date: Thu Apr 7 15:26:13 2005 -0700
966 14th
968 Notes (other):
969 other note
970 $whitespace
971 yet another note
974 test_expect_success 'git notes copy --for-rewrite (enabled)' '
975 git config notes.rewriteMode overwrite &&
976 git config notes.rewriteRef "refs/notes/*" &&
977 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
978 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
979 git notes copy --for-rewrite=foo &&
980 git log -2 > output &&
981 test_cmp expect output
984 test_expect_success 'git notes copy --for-rewrite (disabled)' '
985 git config notes.rewrite.bar false &&
986 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
987 git notes copy --for-rewrite=bar &&
988 git log -2 > output &&
989 test_cmp expect output
992 cat > expect << EOF
993 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
994 Author: A U Thor <author@example.com>
995 Date: Thu Apr 7 15:27:13 2005 -0700
997 15th
999 Notes (other):
1000 a fresh note
1003 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
1004 git notes add -f -m"a fresh note" HEAD^ &&
1005 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1006 git notes copy --for-rewrite=foo &&
1007 git log -1 > output &&
1008 test_cmp expect output
1011 test_expect_success 'git notes copy --for-rewrite (ignore)' '
1012 git config notes.rewriteMode ignore &&
1013 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1014 git notes copy --for-rewrite=foo &&
1015 git log -1 > output &&
1016 test_cmp expect output
1019 cat > expect << EOF
1020 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1021 Author: A U Thor <author@example.com>
1022 Date: Thu Apr 7 15:27:13 2005 -0700
1024 15th
1026 Notes (other):
1027 a fresh note
1028 $whitespace
1029 another fresh note
1032 test_expect_success 'git notes copy --for-rewrite (append)' '
1033 git notes add -f -m"another fresh note" HEAD^ &&
1034 git config notes.rewriteMode concatenate &&
1035 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1036 git notes copy --for-rewrite=foo &&
1037 git log -1 > output &&
1038 test_cmp expect output
1041 cat > expect << EOF
1042 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1043 Author: A U Thor <author@example.com>
1044 Date: Thu Apr 7 15:27:13 2005 -0700
1046 15th
1048 Notes (other):
1049 a fresh note
1050 $whitespace
1051 another fresh note
1052 $whitespace
1053 append 1
1054 $whitespace
1055 append 2
1058 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1059 git notes add -f -m"append 1" HEAD^ &&
1060 git notes add -f -m"append 2" HEAD^^ &&
1061 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
1062 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1063 git notes copy --for-rewrite=foo &&
1064 git log -1 > output &&
1065 test_cmp expect output
1068 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1069 git notes remove HEAD^ &&
1070 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1071 git notes copy --for-rewrite=foo &&
1072 git log -1 > output &&
1073 test_cmp expect output
1076 cat > expect << EOF
1077 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1078 Author: A U Thor <author@example.com>
1079 Date: Thu Apr 7 15:27:13 2005 -0700
1081 15th
1083 Notes (other):
1084 replacement note 1
1087 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1088 git notes add -f -m"replacement note 1" HEAD^ &&
1089 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1090 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1091 git log -1 > output &&
1092 test_cmp expect output
1095 cat > expect << EOF
1096 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1097 Author: A U Thor <author@example.com>
1098 Date: Thu Apr 7 15:27:13 2005 -0700
1100 15th
1102 Notes (other):
1103 replacement note 2
1106 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1107 git config notes.rewriteMode overwrite &&
1108 git notes add -f -m"replacement note 2" HEAD^ &&
1109 git config --unset-all notes.rewriteRef &&
1110 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1111 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1112 git notes copy --for-rewrite=foo &&
1113 git log -1 > output &&
1114 test_cmp expect output
1117 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1118 git config notes.rewriteRef refs/notes/other &&
1119 git notes add -f -m"replacement note 3" HEAD^ &&
1120 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1121 GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1122 git log -1 > output &&
1123 test_cmp expect output
1126 test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1127 test_must_fail git notes copy &&
1128 test_must_fail git notes copy one two three
1131 test_expect_success 'git notes get-ref (no overrides)' '
1132 git config --unset core.notesRef &&
1133 sane_unset GIT_NOTES_REF &&
1134 test "$(git notes get-ref)" = "refs/notes/commits"
1137 test_expect_success 'git notes get-ref (core.notesRef)' '
1138 git config core.notesRef refs/notes/foo &&
1139 test "$(git notes get-ref)" = "refs/notes/foo"
1142 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1143 test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1146 test_expect_success 'git notes get-ref (--ref)' '
1147 test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1150 test_done