Code

notes remove: --ignore-missing
[git.git] / t / t3301-notes.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
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)
21 '
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
32 '
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)
39 '
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)
45 '
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)
51 '
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
56 '
58 test_expect_success 'show non-existent notes entry with %N' '
59         for l in A B
60         do
61                 echo "$l"
62         done >expect &&
63         git show -s --format='A%n%NB' >output &&
64         test_cmp expect output
65 '
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^
75 '
77 test_expect_success 'show notes entry with %N' '
78         for l in A b4 B
79         do
80                 echo "$l"
81         done >expect &&
82         git show -s --format='A%n%NB' >output &&
83         test_cmp expect output
84 '
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
93 '
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
145     2nd
147 Notes:
148     b1
149 EOF
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
172     3rd
174 Notes:
175     b3
176     c3c3c3c3
177     d3d3d3
178 EOF
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
201     4th
203 Notes:
204     xyzzy
205 EOF
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
229     4th
230 EOF
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
240 EOF
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
264 do
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"
272         '
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
319 bar
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
329     5th
331 Notes:
332     spam
333 $whitespace
334     foo
335     bar
336     baz
337 EOF
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
356     5th
357 EOF
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
379 foo
381 xyzzy
383 bar
385 zyxxy
387 baz
388 EOF
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
408     5th
410 commit 15023535574ded8b1a89052b32673f84cf9582b8
411 Author: A U Thor <author@example.com>
412 Date:   Thu Apr 7 15:16:13 2005 -0700
414     4th
415 EOF
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
429 EOF
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 'list notes with "git notes list"' '
479         git notes list > output &&
480         test_cmp expect output
483 test_expect_success 'list notes with "git notes"' '
484         git notes > output &&
485         test_cmp expect output
488 cat > expect << EOF
489 c18dc024e14f08d18d14eea0d747ff692d66d6a3
490 EOF
492 test_expect_success 'list specific note with "git notes list <object>"' '
493         git notes list HEAD^^ > output &&
494         test_cmp expect output
497 cat > expect << EOF
498 EOF
500 test_expect_success 'listing non-existing notes fails' '
501         test_must_fail git notes list HEAD > output &&
502         test_cmp expect output
505 cat > expect << EOF
506 Initial set of notes
508 More notes appended with git notes append
509 EOF
511 test_expect_success 'append to existing note with "git notes append"' '
512         git notes add -m "Initial set of notes" &&
513         git notes append -m "More notes appended with git notes append" &&
514         git notes show > output &&
515         test_cmp expect output
518 cat > expect_list << EOF
519 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
520 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
521 4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
522 EOF
524 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
525         git notes list > output &&
526         test_cmp expect_list output
529 test_expect_success 'appending empty string does not change existing note' '
530         git notes append -m "" &&
531         git notes show > output &&
532         test_cmp expect output
535 test_expect_success 'git notes append == add when there is no existing note' '
536         git notes remove HEAD &&
537         test_must_fail git notes list HEAD &&
538         git notes append -m "Initial set of notes
540 More notes appended with git notes append" &&
541         git notes show > output &&
542         test_cmp expect output
545 test_expect_success 'appending empty string to non-existing note does not create note' '
546         git notes remove HEAD &&
547         test_must_fail git notes list HEAD &&
548         git notes append -m "" &&
549         test_must_fail git notes list HEAD
552 test_expect_success 'create other note on a different notes ref (setup)' '
553         : > a6 &&
554         git add a6 &&
555         test_tick &&
556         git commit -m 6th &&
557         GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
560 cat > expect-other << EOF
561 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
562 Author: A U Thor <author@example.com>
563 Date:   Thu Apr 7 15:18:13 2005 -0700
565     6th
567 Notes (other):
568     other note
569 EOF
571 cat > expect-not-other << EOF
572 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
573 Author: A U Thor <author@example.com>
574 Date:   Thu Apr 7 15:18:13 2005 -0700
576     6th
577 EOF
579 test_expect_success 'Do not show note on other ref by default' '
580         git log -1 > output &&
581         test_cmp expect-not-other output
584 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
585         GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
586         test_cmp expect-other output
589 test_expect_success 'Do show note when ref is given in core.notesRef config' '
590         git config core.notesRef "refs/notes/other" &&
591         git log -1 > output &&
592         test_cmp expect-other output
595 test_expect_success 'Do not show note when core.notesRef is overridden' '
596         GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
597         test_cmp expect-not-other output
600 cat > expect-both << EOF
601 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
602 Author: A U Thor <author@example.com>
603 Date:   Thu Apr 7 15:18:13 2005 -0700
605     6th
607 Notes:
608     order test
610 Notes (other):
611     other note
613 commit bd1753200303d0a0344be813e504253b3d98e74d
614 Author: A U Thor <author@example.com>
615 Date:   Thu Apr 7 15:17:13 2005 -0700
617     5th
619 Notes:
620     replacement for deleted note
621 EOF
623 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
624         GIT_NOTES_REF=refs/notes/commits git notes add \
625                 -m"replacement for deleted note" HEAD^ &&
626         GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
627         git config --unset core.notesRef &&
628         git config notes.displayRef "refs/notes/*" &&
629         git log -2 > output &&
630         test_cmp expect-both output
633 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
634         git config core.notesRef refs/notes/commits &&
635         git config notes.displayRef refs/notes/other &&
636         git log -2 > output &&
637         test_cmp expect-both output
640 test_expect_success 'notes.displayRef can be given more than once' '
641         git config --unset core.notesRef &&
642         git config notes.displayRef refs/notes/commits &&
643         git config --add notes.displayRef refs/notes/other &&
644         git log -2 > output &&
645         test_cmp expect-both output
648 cat > expect-both-reversed << EOF
649 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
650 Author: A U Thor <author@example.com>
651 Date:   Thu Apr 7 15:18:13 2005 -0700
653     6th
655 Notes (other):
656     other note
658 Notes:
659     order test
660 EOF
662 test_expect_success 'notes.displayRef respects order' '
663         git config core.notesRef refs/notes/other &&
664         git config --unset-all notes.displayRef &&
665         git config notes.displayRef refs/notes/commits &&
666         git log -1 > output &&
667         test_cmp expect-both-reversed output
670 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
671         git config --unset-all core.notesRef &&
672         git config --unset-all notes.displayRef &&
673         GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
674                 git log -2 > output &&
675         test_cmp expect-both output
678 cat > expect-none << EOF
679 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
680 Author: A U Thor <author@example.com>
681 Date:   Thu Apr 7 15:18:13 2005 -0700
683     6th
685 commit bd1753200303d0a0344be813e504253b3d98e74d
686 Author: A U Thor <author@example.com>
687 Date:   Thu Apr 7 15:17:13 2005 -0700
689     5th
690 EOF
692 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
693         git config notes.displayRef "refs/notes/*" &&
694         GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
695         test_cmp expect-none output
698 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
699         GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
700         test_cmp expect-both output
703 cat > expect-commits << EOF
704 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
705 Author: A U Thor <author@example.com>
706 Date:   Thu Apr 7 15:18:13 2005 -0700
708     6th
710 Notes:
711     order test
712 EOF
714 test_expect_success '--no-standard-notes' '
715         git log --no-standard-notes --show-notes=commits -1 > output &&
716         test_cmp expect-commits output
719 test_expect_success '--standard-notes' '
720         git log --no-standard-notes --show-notes=commits \
721                 --standard-notes -2 > output &&
722         test_cmp expect-both output
725 test_expect_success '--show-notes=ref accumulates' '
726         git log --show-notes=other --show-notes=commits \
727                  --no-standard-notes -1 > output &&
728         test_cmp expect-both-reversed output
731 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
732         git config core.notesRef refs/notes/other &&
733         echo "Note on a tree" > expect &&
734         git notes add -m "Note on a tree" HEAD: &&
735         git notes show HEAD: > actual &&
736         test_cmp expect actual &&
737         echo "Note on a blob" > expect &&
738         filename=$(git ls-tree --name-only HEAD | head -n1) &&
739         git notes add -m "Note on a blob" HEAD:$filename &&
740         git notes show HEAD:$filename > actual &&
741         test_cmp expect actual &&
742         echo "Note on a tag" > expect &&
743         git tag -a -m "This is an annotated tag" foobar HEAD^ &&
744         git notes add -m "Note on a tag" foobar &&
745         git notes show foobar > actual &&
746         test_cmp expect actual
749 cat > expect << EOF
750 commit 2ede89468182a62d0bde2583c736089bcf7d7e92
751 Author: A U Thor <author@example.com>
752 Date:   Thu Apr 7 15:19:13 2005 -0700
754     7th
756 Notes (other):
757     other note
758 EOF
760 test_expect_success 'create note from other note with "git notes add -C"' '
761         : > a7 &&
762         git add a7 &&
763         test_tick &&
764         git commit -m 7th &&
765         git notes add -C $(git notes list HEAD^) &&
766         git log -1 > actual &&
767         test_cmp expect actual &&
768         test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
771 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
772         : > a8 &&
773         git add a8 &&
774         test_tick &&
775         git commit -m 8th &&
776         test_must_fail git notes add -C deadbeef &&
777         test_must_fail git notes list HEAD
780 cat > expect << EOF
781 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
782 Author: A U Thor <author@example.com>
783 Date:   Thu Apr 7 15:21:13 2005 -0700
785     9th
787 Notes (other):
788     yet another note
789 EOF
791 test_expect_success 'create note from other note with "git notes add -c"' '
792         : > a9 &&
793         git add a9 &&
794         test_tick &&
795         git commit -m 9th &&
796         MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
797         git log -1 > actual &&
798         test_cmp expect actual
801 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
802         : > a10 &&
803         git add a10 &&
804         test_tick &&
805         git commit -m 10th &&
806         (
807                 MSG="yet another note" &&
808                 export MSG &&
809                 test_must_fail git notes add -c deadbeef
810         ) &&
811         test_must_fail git notes list HEAD
814 cat > expect << EOF
815 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
816 Author: A U Thor <author@example.com>
817 Date:   Thu Apr 7 15:21:13 2005 -0700
819     9th
821 Notes (other):
822     yet another note
823 $whitespace
824     yet another note
825 EOF
827 test_expect_success 'append to note from other note with "git notes append -C"' '
828         git notes append -C $(git notes list HEAD^) HEAD^ &&
829         git log -1 HEAD^ > actual &&
830         test_cmp expect actual
833 cat > expect << EOF
834 commit ffed603236bfa3891c49644257a83598afe8ae5a
835 Author: A U Thor <author@example.com>
836 Date:   Thu Apr 7 15:22:13 2005 -0700
838     10th
840 Notes (other):
841     other note
842 EOF
844 test_expect_success 'create note from other note with "git notes append -c"' '
845         MSG="other note" git notes append -c $(git notes list HEAD^) &&
846         git log -1 > actual &&
847         test_cmp expect actual
850 cat > expect << EOF
851 commit ffed603236bfa3891c49644257a83598afe8ae5a
852 Author: A U Thor <author@example.com>
853 Date:   Thu Apr 7 15:22:13 2005 -0700
855     10th
857 Notes (other):
858     other note
859 $whitespace
860     yet another note
861 EOF
863 test_expect_success 'append to note from other note with "git notes append -c"' '
864         MSG="yet another note" git notes append -c $(git notes list HEAD) &&
865         git log -1 > actual &&
866         test_cmp expect actual
869 cat > expect << EOF
870 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
871 Author: A U Thor <author@example.com>
872 Date:   Thu Apr 7 15:23:13 2005 -0700
874     11th
876 Notes (other):
877     other note
878 $whitespace
879     yet another note
880 EOF
882 test_expect_success 'copy note with "git notes copy"' '
883         : > a11 &&
884         git add a11 &&
885         test_tick &&
886         git commit -m 11th &&
887         git notes copy HEAD^ HEAD &&
888         git log -1 > actual &&
889         test_cmp expect actual &&
890         test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
893 test_expect_success 'prevent overwrite with "git notes copy"' '
894         test_must_fail git notes copy HEAD~2 HEAD &&
895         git log -1 > actual &&
896         test_cmp expect actual &&
897         test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
900 cat > expect << EOF
901 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
902 Author: A U Thor <author@example.com>
903 Date:   Thu Apr 7 15:23:13 2005 -0700
905     11th
907 Notes (other):
908     yet another note
909 $whitespace
910     yet another note
911 EOF
913 test_expect_success 'allow overwrite with "git notes copy -f"' '
914         git notes copy -f HEAD~2 HEAD &&
915         git log -1 > actual &&
916         test_cmp expect actual &&
917         test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
920 test_expect_success 'cannot copy note from object without notes' '
921         : > a12 &&
922         git add a12 &&
923         test_tick &&
924         git commit -m 12th &&
925         : > a13 &&
926         git add a13 &&
927         test_tick &&
928         git commit -m 13th &&
929         test_must_fail git notes copy HEAD^ HEAD
932 cat > expect << EOF
933 commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
934 Author: A U Thor <author@example.com>
935 Date:   Thu Apr 7 15:25:13 2005 -0700
937     13th
939 Notes (other):
940     yet another note
941 $whitespace
942     yet another note
944 commit 7038787dfe22a14c3867ce816dbba39845359719
945 Author: A U Thor <author@example.com>
946 Date:   Thu Apr 7 15:24:13 2005 -0700
948     12th
950 Notes (other):
951     other note
952 $whitespace
953     yet another note
954 EOF
956 test_expect_success 'git notes copy --stdin' '
957         (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
958         echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
959         git notes copy --stdin &&
960         git log -2 > output &&
961         test_cmp expect output &&
962         test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
963         test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
966 cat > expect << EOF
967 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
968 Author: A U Thor <author@example.com>
969 Date:   Thu Apr 7 15:27:13 2005 -0700
971     15th
973 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
974 Author: A U Thor <author@example.com>
975 Date:   Thu Apr 7 15:26:13 2005 -0700
977     14th
978 EOF
980 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
981         test_commit 14th &&
982         test_commit 15th &&
983         (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
984         echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
985         git notes copy --for-rewrite=foo &&
986         git log -2 > output &&
987         test_cmp expect output
990 cat > expect << EOF
991 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
992 Author: A U Thor <author@example.com>
993 Date:   Thu Apr 7 15:27:13 2005 -0700
995     15th
997 Notes (other):
998     yet another note
999 $whitespace
1000     yet another note
1002 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
1003 Author: A U Thor <author@example.com>
1004 Date:   Thu Apr 7 15:26:13 2005 -0700
1006     14th
1008 Notes (other):
1009     other note
1010 $whitespace
1011     yet another note
1012 EOF
1014 test_expect_success 'git notes copy --for-rewrite (enabled)' '
1015         git config notes.rewriteMode overwrite &&
1016         git config notes.rewriteRef "refs/notes/*" &&
1017         (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
1018         echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
1019         git notes copy --for-rewrite=foo &&
1020         git log -2 > output &&
1021         test_cmp expect output
1024 test_expect_success 'git notes copy --for-rewrite (disabled)' '
1025         git config notes.rewrite.bar false &&
1026         echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
1027         git notes copy --for-rewrite=bar &&
1028         git log -2 > output &&
1029         test_cmp expect output
1032 cat > expect << EOF
1033 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1034 Author: A U Thor <author@example.com>
1035 Date:   Thu Apr 7 15:27:13 2005 -0700
1037     15th
1039 Notes (other):
1040     a fresh note
1041 EOF
1043 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
1044         git notes add -f -m"a fresh note" HEAD^ &&
1045         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1046         git notes copy --for-rewrite=foo &&
1047         git log -1 > output &&
1048         test_cmp expect output
1051 test_expect_success 'git notes copy --for-rewrite (ignore)' '
1052         git config notes.rewriteMode ignore &&
1053         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1054         git notes copy --for-rewrite=foo &&
1055         git log -1 > output &&
1056         test_cmp expect output
1059 cat > expect << EOF
1060 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1061 Author: A U Thor <author@example.com>
1062 Date:   Thu Apr 7 15:27:13 2005 -0700
1064     15th
1066 Notes (other):
1067     a fresh note
1068 $whitespace
1069     another fresh note
1070 EOF
1072 test_expect_success 'git notes copy --for-rewrite (append)' '
1073         git notes add -f -m"another fresh note" HEAD^ &&
1074         git config notes.rewriteMode concatenate &&
1075         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1076         git notes copy --for-rewrite=foo &&
1077         git log -1 > output &&
1078         test_cmp expect output
1081 cat > expect << EOF
1082 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1083 Author: A U Thor <author@example.com>
1084 Date:   Thu Apr 7 15:27:13 2005 -0700
1086     15th
1088 Notes (other):
1089     a fresh note
1090 $whitespace
1091     another fresh note
1092 $whitespace
1093     append 1
1094 $whitespace
1095     append 2
1096 EOF
1098 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1099         git notes add -f -m"append 1" HEAD^ &&
1100         git notes add -f -m"append 2" HEAD^^ &&
1101         (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
1102         echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1103         git notes copy --for-rewrite=foo &&
1104         git log -1 > output &&
1105         test_cmp expect output
1108 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1109         git notes remove HEAD^ &&
1110         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1111         git notes copy --for-rewrite=foo &&
1112         git log -1 > output &&
1113         test_cmp expect output
1116 cat > expect << EOF
1117 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1118 Author: A U Thor <author@example.com>
1119 Date:   Thu Apr 7 15:27:13 2005 -0700
1121     15th
1123 Notes (other):
1124     replacement note 1
1125 EOF
1127 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1128         git notes add -f -m"replacement note 1" HEAD^ &&
1129         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1130         GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1131         git log -1 > output &&
1132         test_cmp expect output
1135 cat > expect << EOF
1136 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1137 Author: A U Thor <author@example.com>
1138 Date:   Thu Apr 7 15:27:13 2005 -0700
1140     15th
1142 Notes (other):
1143     replacement note 2
1144 EOF
1146 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1147         git config notes.rewriteMode overwrite &&
1148         git notes add -f -m"replacement note 2" HEAD^ &&
1149         git config --unset-all notes.rewriteRef &&
1150         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1151         GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1152                 git notes copy --for-rewrite=foo &&
1153         git log -1 > output &&
1154         test_cmp expect output
1157 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1158         git config notes.rewriteRef refs/notes/other &&
1159         git notes add -f -m"replacement note 3" HEAD^ &&
1160         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1161         GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1162         git log -1 > output &&
1163         test_cmp expect output
1166 test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1167         test_must_fail git notes copy &&
1168         test_must_fail git notes copy one two three
1171 test_expect_success 'git notes get-ref (no overrides)' '
1172         git config --unset core.notesRef &&
1173         sane_unset GIT_NOTES_REF &&
1174         test "$(git notes get-ref)" = "refs/notes/commits"
1177 test_expect_success 'git notes get-ref (core.notesRef)' '
1178         git config core.notesRef refs/notes/foo &&
1179         test "$(git notes get-ref)" = "refs/notes/foo"
1182 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1183         test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1186 test_expect_success 'git notes get-ref (--ref)' '
1187         test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1190 test_done