Merge branch 'jh/notes-add-ui'
[alt-git.git] / t / t3301-notes.sh
blob3448c23776dc867fa0542665f69ccb27ac564337
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 'create -m notes (setup)' '
276 : > a5 &&
277 git add a5 &&
278 test_tick &&
279 git commit -m 5th &&
280 git notes add -m spam -m "foo
282 baz"
285 whitespace=" "
286 cat > expect-m << EOF
287 commit bd1753200303d0a0344be813e504253b3d98e74d
288 Author: A U Thor <author@example.com>
289 Date: Thu Apr 7 15:17:13 2005 -0700
293 Notes:
294 spam
295 $whitespace
301 printf "\n" >> expect-m
302 cat expect-F >> expect-m
304 test_expect_success 'show -m notes' '
305 git log -4 > output &&
306 test_cmp expect-m output
309 test_expect_success 'remove note with add -f -F /dev/null (setup)' '
310 git notes add -f -F /dev/null
313 cat > expect-rm-F << EOF
314 commit bd1753200303d0a0344be813e504253b3d98e74d
315 Author: A U Thor <author@example.com>
316 Date: Thu Apr 7 15:17:13 2005 -0700
321 printf "\n" >> expect-rm-F
322 cat expect-F >> expect-rm-F
324 test_expect_success 'verify note removal with -F /dev/null' '
325 git log -4 > output &&
326 test_cmp expect-rm-F output &&
327 test_must_fail git notes show
330 test_expect_success 'do not create empty note with -m "" (setup)' '
331 git notes add -m ""
334 test_expect_success 'verify non-creation of note with -m ""' '
335 git log -4 > output &&
336 test_cmp expect-rm-F output &&
337 test_must_fail git notes show
340 cat > expect-combine_m_and_F << EOF
343 xyzzy
347 zyxxy
352 test_expect_success 'create note with combination of -m and -F' '
353 echo "xyzzy" > note_a &&
354 echo "zyxxy" > note_b &&
355 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
356 git notes show > output &&
357 test_cmp expect-combine_m_and_F output
360 test_expect_success 'remove note with "git notes remove" (setup)' '
361 git notes remove HEAD^ &&
362 git notes remove
365 cat > expect-rm-remove << EOF
366 commit bd1753200303d0a0344be813e504253b3d98e74d
367 Author: A U Thor <author@example.com>
368 Date: Thu Apr 7 15:17:13 2005 -0700
372 commit 15023535574ded8b1a89052b32673f84cf9582b8
373 Author: A U Thor <author@example.com>
374 Date: Thu Apr 7 15:16:13 2005 -0700
379 printf "\n" >> expect-rm-remove
380 cat expect-multiline >> expect-rm-remove
382 test_expect_success 'verify note removal with "git notes remove"' '
383 git log -4 > output &&
384 test_cmp expect-rm-remove output &&
385 test_must_fail git notes show HEAD^
388 cat > expect << EOF
389 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
390 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
393 test_expect_success 'removing non-existing note should not create new commit' '
394 git rev-parse --verify refs/notes/commits > before_commit &&
395 test_must_fail git notes remove HEAD^ &&
396 git rev-parse --verify refs/notes/commits > after_commit &&
397 test_cmp before_commit after_commit
400 test_expect_success 'list notes with "git notes list"' '
401 git notes list > output &&
402 test_cmp expect output
405 test_expect_success 'list notes with "git notes"' '
406 git notes > output &&
407 test_cmp expect output
410 cat > expect << EOF
411 c18dc024e14f08d18d14eea0d747ff692d66d6a3
414 test_expect_success 'list specific note with "git notes list <object>"' '
415 git notes list HEAD^^ > output &&
416 test_cmp expect output
419 cat > expect << EOF
422 test_expect_success 'listing non-existing notes fails' '
423 test_must_fail git notes list HEAD > output &&
424 test_cmp expect output
427 cat > expect << EOF
428 Initial set of notes
430 More notes appended with git notes append
433 test_expect_success 'append to existing note with "git notes append"' '
434 git notes add -m "Initial set of notes" &&
435 git notes append -m "More notes appended with git notes append" &&
436 git notes show > output &&
437 test_cmp expect output
440 cat > expect_list << EOF
441 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
442 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
443 4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
446 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
447 git notes list > output &&
448 test_cmp expect_list output
451 test_expect_success 'appending empty string does not change existing note' '
452 git notes append -m "" &&
453 git notes show > output &&
454 test_cmp expect output
457 test_expect_success 'git notes append == add when there is no existing note' '
458 git notes remove HEAD &&
459 test_must_fail git notes list HEAD &&
460 git notes append -m "Initial set of notes
462 More notes appended with git notes append" &&
463 git notes show > output &&
464 test_cmp expect output
467 test_expect_success 'appending empty string to non-existing note does not create note' '
468 git notes remove HEAD &&
469 test_must_fail git notes list HEAD &&
470 git notes append -m "" &&
471 test_must_fail git notes list HEAD
474 test_expect_success 'create other note on a different notes ref (setup)' '
475 : > a6 &&
476 git add a6 &&
477 test_tick &&
478 git commit -m 6th &&
479 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
482 cat > expect-other << EOF
483 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
484 Author: A U Thor <author@example.com>
485 Date: Thu Apr 7 15:18:13 2005 -0700
489 Notes (other):
490 other note
493 cat > expect-not-other << EOF
494 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
495 Author: A U Thor <author@example.com>
496 Date: Thu Apr 7 15:18:13 2005 -0700
501 test_expect_success 'Do not show note on other ref by default' '
502 git log -1 > output &&
503 test_cmp expect-not-other output
506 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
507 GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
508 test_cmp expect-other output
511 test_expect_success 'Do show note when ref is given in core.notesRef config' '
512 git config core.notesRef "refs/notes/other" &&
513 git log -1 > output &&
514 test_cmp expect-other output
517 test_expect_success 'Do not show note when core.notesRef is overridden' '
518 GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
519 test_cmp expect-not-other output
522 cat > expect-both << EOF
523 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
524 Author: A U Thor <author@example.com>
525 Date: Thu Apr 7 15:18:13 2005 -0700
529 Notes:
530 order test
532 Notes (other):
533 other note
535 commit bd1753200303d0a0344be813e504253b3d98e74d
536 Author: A U Thor <author@example.com>
537 Date: Thu Apr 7 15:17:13 2005 -0700
541 Notes:
542 replacement for deleted note
545 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
546 GIT_NOTES_REF=refs/notes/commits git notes add \
547 -m"replacement for deleted note" HEAD^ &&
548 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
549 git config --unset core.notesRef &&
550 git config notes.displayRef "refs/notes/*" &&
551 git log -2 > output &&
552 test_cmp expect-both output
555 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
556 git config core.notesRef refs/notes/commits &&
557 git config notes.displayRef refs/notes/other &&
558 git log -2 > output &&
559 test_cmp expect-both output
562 test_expect_success 'notes.displayRef can be given more than once' '
563 git config --unset core.notesRef &&
564 git config notes.displayRef refs/notes/commits &&
565 git config --add notes.displayRef refs/notes/other &&
566 git log -2 > output &&
567 test_cmp expect-both output
570 cat > expect-both-reversed << EOF
571 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
572 Author: A U Thor <author@example.com>
573 Date: Thu Apr 7 15:18:13 2005 -0700
577 Notes (other):
578 other note
580 Notes:
581 order test
584 test_expect_success 'notes.displayRef respects order' '
585 git config core.notesRef refs/notes/other &&
586 git config --unset-all notes.displayRef &&
587 git config notes.displayRef refs/notes/commits &&
588 git log -1 > output &&
589 test_cmp expect-both-reversed output
592 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
593 git config --unset-all core.notesRef &&
594 git config --unset-all notes.displayRef &&
595 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
596 git log -2 > output &&
597 test_cmp expect-both output
600 cat > expect-none << EOF
601 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
602 Author: A U Thor <author@example.com>
603 Date: Thu Apr 7 15:18:13 2005 -0700
607 commit bd1753200303d0a0344be813e504253b3d98e74d
608 Author: A U Thor <author@example.com>
609 Date: Thu Apr 7 15:17:13 2005 -0700
614 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
615 git config notes.displayRef "refs/notes/*" &&
616 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
617 test_cmp expect-none output
620 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
621 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
622 test_cmp expect-both output
625 cat > expect-commits << EOF
626 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
627 Author: A U Thor <author@example.com>
628 Date: Thu Apr 7 15:18:13 2005 -0700
632 Notes:
633 order test
636 test_expect_success '--no-standard-notes' '
637 git log --no-standard-notes --show-notes=commits -1 > output &&
638 test_cmp expect-commits output
641 test_expect_success '--standard-notes' '
642 git log --no-standard-notes --show-notes=commits \
643 --standard-notes -2 > output &&
644 test_cmp expect-both output
647 test_expect_success '--show-notes=ref accumulates' '
648 git log --show-notes=other --show-notes=commits \
649 --no-standard-notes -1 > output &&
650 test_cmp expect-both-reversed output
653 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
654 git config core.notesRef refs/notes/other &&
655 echo "Note on a tree" > expect &&
656 git notes add -m "Note on a tree" HEAD: &&
657 git notes show HEAD: > actual &&
658 test_cmp expect actual &&
659 echo "Note on a blob" > expect &&
660 filename=$(git ls-tree --name-only HEAD | head -n1) &&
661 git notes add -m "Note on a blob" HEAD:$filename &&
662 git notes show HEAD:$filename > actual &&
663 test_cmp expect actual &&
664 echo "Note on a tag" > expect &&
665 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
666 git notes add -m "Note on a tag" foobar &&
667 git notes show foobar > actual &&
668 test_cmp expect actual
671 cat > expect << EOF
672 commit 2ede89468182a62d0bde2583c736089bcf7d7e92
673 Author: A U Thor <author@example.com>
674 Date: Thu Apr 7 15:19:13 2005 -0700
678 Notes (other):
679 other note
682 test_expect_success 'create note from other note with "git notes add -C"' '
683 : > a7 &&
684 git add a7 &&
685 test_tick &&
686 git commit -m 7th &&
687 git notes add -C $(git notes list HEAD^) &&
688 git log -1 > actual &&
689 test_cmp expect actual &&
690 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
693 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
694 : > a8 &&
695 git add a8 &&
696 test_tick &&
697 git commit -m 8th &&
698 test_must_fail git notes add -C deadbeef &&
699 test_must_fail git notes list HEAD
702 cat > expect << EOF
703 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
704 Author: A U Thor <author@example.com>
705 Date: Thu Apr 7 15:21:13 2005 -0700
709 Notes (other):
710 yet another note
713 test_expect_success 'create note from other note with "git notes add -c"' '
714 : > a9 &&
715 git add a9 &&
716 test_tick &&
717 git commit -m 9th &&
718 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
719 git log -1 > actual &&
720 test_cmp expect actual
723 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
724 : > a10 &&
725 git add a10 &&
726 test_tick &&
727 git commit -m 10th &&
729 MSG="yet another note" &&
730 export MSG &&
731 test_must_fail git notes add -c deadbeef
732 ) &&
733 test_must_fail git notes list HEAD
736 cat > expect << EOF
737 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
738 Author: A U Thor <author@example.com>
739 Date: Thu Apr 7 15:21:13 2005 -0700
743 Notes (other):
744 yet another note
745 $whitespace
746 yet another note
749 test_expect_success 'append to note from other note with "git notes append -C"' '
750 git notes append -C $(git notes list HEAD^) HEAD^ &&
751 git log -1 HEAD^ > actual &&
752 test_cmp expect actual
755 cat > expect << EOF
756 commit ffed603236bfa3891c49644257a83598afe8ae5a
757 Author: A U Thor <author@example.com>
758 Date: Thu Apr 7 15:22:13 2005 -0700
760 10th
762 Notes (other):
763 other note
766 test_expect_success 'create note from other note with "git notes append -c"' '
767 MSG="other note" git notes append -c $(git notes list HEAD^) &&
768 git log -1 > actual &&
769 test_cmp expect actual
772 cat > expect << EOF
773 commit ffed603236bfa3891c49644257a83598afe8ae5a
774 Author: A U Thor <author@example.com>
775 Date: Thu Apr 7 15:22:13 2005 -0700
777 10th
779 Notes (other):
780 other note
781 $whitespace
782 yet another note
785 test_expect_success 'append to note from other note with "git notes append -c"' '
786 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
787 git log -1 > actual &&
788 test_cmp expect actual
791 cat > expect << EOF
792 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
793 Author: A U Thor <author@example.com>
794 Date: Thu Apr 7 15:23:13 2005 -0700
796 11th
798 Notes (other):
799 other note
800 $whitespace
801 yet another note
804 test_expect_success 'copy note with "git notes copy"' '
805 : > a11 &&
806 git add a11 &&
807 test_tick &&
808 git commit -m 11th &&
809 git notes copy HEAD^ HEAD &&
810 git log -1 > actual &&
811 test_cmp expect actual &&
812 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
815 test_expect_success 'prevent overwrite with "git notes copy"' '
816 test_must_fail git notes copy HEAD~2 HEAD &&
817 git log -1 > actual &&
818 test_cmp expect actual &&
819 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
822 cat > expect << EOF
823 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
824 Author: A U Thor <author@example.com>
825 Date: Thu Apr 7 15:23:13 2005 -0700
827 11th
829 Notes (other):
830 yet another note
831 $whitespace
832 yet another note
835 test_expect_success 'allow overwrite with "git notes copy -f"' '
836 git notes copy -f HEAD~2 HEAD &&
837 git log -1 > actual &&
838 test_cmp expect actual &&
839 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
842 test_expect_success 'cannot copy note from object without notes' '
843 : > a12 &&
844 git add a12 &&
845 test_tick &&
846 git commit -m 12th &&
847 : > a13 &&
848 git add a13 &&
849 test_tick &&
850 git commit -m 13th &&
851 test_must_fail git notes copy HEAD^ HEAD
854 cat > expect << EOF
855 commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
856 Author: A U Thor <author@example.com>
857 Date: Thu Apr 7 15:25:13 2005 -0700
859 13th
861 Notes (other):
862 yet another note
863 $whitespace
864 yet another note
866 commit 7038787dfe22a14c3867ce816dbba39845359719
867 Author: A U Thor <author@example.com>
868 Date: Thu Apr 7 15:24:13 2005 -0700
870 12th
872 Notes (other):
873 other note
874 $whitespace
875 yet another note
878 test_expect_success 'git notes copy --stdin' '
879 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
880 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
881 git notes copy --stdin &&
882 git log -2 > output &&
883 test_cmp expect output &&
884 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
885 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
888 cat > expect << EOF
889 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
890 Author: A U Thor <author@example.com>
891 Date: Thu Apr 7 15:27:13 2005 -0700
893 15th
895 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
896 Author: A U Thor <author@example.com>
897 Date: Thu Apr 7 15:26:13 2005 -0700
899 14th
902 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
903 test_commit 14th &&
904 test_commit 15th &&
905 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
906 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
907 git notes copy --for-rewrite=foo &&
908 git log -2 > output &&
909 test_cmp expect output
912 cat > expect << EOF
913 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
914 Author: A U Thor <author@example.com>
915 Date: Thu Apr 7 15:27:13 2005 -0700
917 15th
919 Notes (other):
920 yet another note
921 $whitespace
922 yet another note
924 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
925 Author: A U Thor <author@example.com>
926 Date: Thu Apr 7 15:26:13 2005 -0700
928 14th
930 Notes (other):
931 other note
932 $whitespace
933 yet another note
936 test_expect_success 'git notes copy --for-rewrite (enabled)' '
937 git config notes.rewriteMode overwrite &&
938 git config notes.rewriteRef "refs/notes/*" &&
939 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
940 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
941 git notes copy --for-rewrite=foo &&
942 git log -2 > output &&
943 test_cmp expect output
946 test_expect_success 'git notes copy --for-rewrite (disabled)' '
947 git config notes.rewrite.bar false &&
948 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
949 git notes copy --for-rewrite=bar &&
950 git log -2 > output &&
951 test_cmp expect output
954 cat > expect << EOF
955 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
956 Author: A U Thor <author@example.com>
957 Date: Thu Apr 7 15:27:13 2005 -0700
959 15th
961 Notes (other):
962 a fresh note
965 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
966 git notes add -f -m"a fresh note" HEAD^ &&
967 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
968 git notes copy --for-rewrite=foo &&
969 git log -1 > output &&
970 test_cmp expect output
973 test_expect_success 'git notes copy --for-rewrite (ignore)' '
974 git config notes.rewriteMode ignore &&
975 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
976 git notes copy --for-rewrite=foo &&
977 git log -1 > output &&
978 test_cmp expect output
981 cat > expect << EOF
982 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
983 Author: A U Thor <author@example.com>
984 Date: Thu Apr 7 15:27:13 2005 -0700
986 15th
988 Notes (other):
989 a fresh note
990 $whitespace
991 another fresh note
994 test_expect_success 'git notes copy --for-rewrite (append)' '
995 git notes add -f -m"another fresh note" HEAD^ &&
996 git config notes.rewriteMode concatenate &&
997 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
998 git notes copy --for-rewrite=foo &&
999 git log -1 > output &&
1000 test_cmp expect output
1003 cat > expect << EOF
1004 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1005 Author: A U Thor <author@example.com>
1006 Date: Thu Apr 7 15:27:13 2005 -0700
1008 15th
1010 Notes (other):
1011 a fresh note
1012 $whitespace
1013 another fresh note
1014 $whitespace
1015 append 1
1016 $whitespace
1017 append 2
1020 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1021 git notes add -f -m"append 1" HEAD^ &&
1022 git notes add -f -m"append 2" HEAD^^ &&
1023 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
1024 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1025 git notes copy --for-rewrite=foo &&
1026 git log -1 > output &&
1027 test_cmp expect output
1030 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1031 git notes remove HEAD^ &&
1032 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1033 git notes copy --for-rewrite=foo &&
1034 git log -1 > output &&
1035 test_cmp expect output
1038 cat > expect << EOF
1039 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1040 Author: A U Thor <author@example.com>
1041 Date: Thu Apr 7 15:27:13 2005 -0700
1043 15th
1045 Notes (other):
1046 replacement note 1
1049 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1050 git notes add -f -m"replacement note 1" HEAD^ &&
1051 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1052 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1053 git log -1 > output &&
1054 test_cmp expect output
1057 cat > expect << EOF
1058 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1059 Author: A U Thor <author@example.com>
1060 Date: Thu Apr 7 15:27:13 2005 -0700
1062 15th
1064 Notes (other):
1065 replacement note 2
1068 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1069 git config notes.rewriteMode overwrite &&
1070 git notes add -f -m"replacement note 2" HEAD^ &&
1071 git config --unset-all notes.rewriteRef &&
1072 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1073 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1074 git notes copy --for-rewrite=foo &&
1075 git log -1 > output &&
1076 test_cmp expect output
1079 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1080 git config notes.rewriteRef refs/notes/other &&
1081 git notes add -f -m"replacement note 3" HEAD^ &&
1082 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1083 GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1084 git log -1 > output &&
1085 test_cmp expect output
1088 test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1089 test_must_fail git notes copy &&
1090 test_must_fail git notes copy one two three
1093 test_expect_success 'git notes get-ref (no overrides)' '
1094 git config --unset core.notesRef &&
1095 sane_unset GIT_NOTES_REF &&
1096 test "$(git notes get-ref)" = "refs/notes/commits"
1099 test_expect_success 'git notes get-ref (core.notesRef)' '
1100 git config core.notesRef refs/notes/foo &&
1101 test "$(git notes get-ref)" = "refs/notes/foo"
1104 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1105 test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1108 test_expect_success 'git notes get-ref (--ref)' '
1109 test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1112 test_done