Code

t3301-notes: Test the creation of reflog entries
[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         git notes show ; test 1 = $?
56 '
58 test_expect_success 'create notes' '
59         git config core.notesRef refs/notes/commits &&
60         MSG=b4 git notes add &&
61         test ! -f .git/NOTES_EDITMSG &&
62         test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
63         test b4 = $(git notes show) &&
64         git show HEAD^ &&
65         test_must_fail git notes show HEAD^
66 '
68 cat >expect <<EOF
69 d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add'
70 EOF
72 test_expect_failure 'create reflog entry' '
73         git reflog show refs/notes/commits >output &&
74         test_cmp expect output
75 '
77 test_expect_success 'edit existing notes' '
78         MSG=b3 git notes edit &&
79         test ! -f .git/NOTES_EDITMSG &&
80         test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
81         test b3 = $(git notes show) &&
82         git show HEAD^ &&
83         test_must_fail git notes show HEAD^
84 '
86 test_expect_success 'cannot add note where one exists' '
87         ! MSG=b2 git notes add &&
88         test ! -f .git/NOTES_EDITMSG &&
89         test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
90         test b3 = $(git notes show) &&
91         git show HEAD^ &&
92         test_must_fail git notes show HEAD^
93 '
95 test_expect_success 'can overwrite existing note with "git notes add -f"' '
96         MSG=b1 git notes add -f &&
97         test ! -f .git/NOTES_EDITMSG &&
98         test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
99         test b1 = $(git notes show) &&
100         git show HEAD^ &&
101         test_must_fail git notes show HEAD^
104 cat > expect << EOF
105 commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
106 Author: A U Thor <author@example.com>
107 Date:   Thu Apr 7 15:14:13 2005 -0700
109     2nd
111 Notes:
112     b1
113 EOF
115 test_expect_success 'show notes' '
116         ! (git cat-file commit HEAD | grep b1) &&
117         git log -1 > output &&
118         test_cmp expect output
121 test_expect_success 'create multi-line notes (setup)' '
122         : > a3 &&
123         git add a3 &&
124         test_tick &&
125         git commit -m 3rd &&
126         MSG="b3
127 c3c3c3c3
128 d3d3d3" git notes add
131 cat > expect-multiline << EOF
132 commit 1584215f1d29c65e99c6c6848626553fdd07fd75
133 Author: A U Thor <author@example.com>
134 Date:   Thu Apr 7 15:15:13 2005 -0700
136     3rd
138 Notes:
139     b3
140     c3c3c3c3
141     d3d3d3
142 EOF
144 printf "\n" >> expect-multiline
145 cat expect >> expect-multiline
147 test_expect_success 'show multi-line notes' '
148         git log -2 > output &&
149         test_cmp expect-multiline output
151 test_expect_success 'create -F notes (setup)' '
152         : > a4 &&
153         git add a4 &&
154         test_tick &&
155         git commit -m 4th &&
156         echo "xyzzy" > note5 &&
157         git notes add -F note5
160 cat > expect-F << EOF
161 commit 15023535574ded8b1a89052b32673f84cf9582b8
162 Author: A U Thor <author@example.com>
163 Date:   Thu Apr 7 15:16:13 2005 -0700
165     4th
167 Notes:
168     xyzzy
169 EOF
171 printf "\n" >> expect-F
172 cat expect-multiline >> expect-F
174 test_expect_success 'show -F notes' '
175         git log -3 > output &&
176         test_cmp expect-F output
179 cat >expect << EOF
180 commit 15023535574ded8b1a89052b32673f84cf9582b8
181 tree e070e3af51011e47b183c33adf9736736a525709
182 parent 1584215f1d29c65e99c6c6848626553fdd07fd75
183 author A U Thor <author@example.com> 1112912173 -0700
184 committer C O Mitter <committer@example.com> 1112912173 -0700
186     4th
187 EOF
188 test_expect_success 'git log --pretty=raw does not show notes' '
189         git log -1 --pretty=raw >output &&
190         test_cmp expect output
193 cat >>expect <<EOF
195 Notes:
196     xyzzy
197 EOF
198 test_expect_success 'git log --show-notes' '
199         git log -1 --pretty=raw --show-notes >output &&
200         test_cmp expect output
203 test_expect_success 'git log --no-notes' '
204         git log -1 --no-notes >output &&
205         ! grep xyzzy output
208 test_expect_success 'git format-patch does not show notes' '
209         git format-patch -1 --stdout >output &&
210         ! grep xyzzy output
213 test_expect_success 'git format-patch --show-notes does show notes' '
214         git format-patch --show-notes -1 --stdout >output &&
215         grep xyzzy output
218 for pretty in \
219         "" --pretty --pretty=raw --pretty=short --pretty=medium \
220         --pretty=full --pretty=fuller --pretty=format:%s --oneline
221 do
222         case "$pretty" in
223         "") p= not= negate="" ;;
224         ?*) p="$pretty" not=" not" negate="!" ;;
225         esac
226         test_expect_success "git show $pretty does$not show notes" '
227                 git show $p >output &&
228                 eval "$negate grep xyzzy output"
229         '
230 done
232 test_expect_success 'create -m notes (setup)' '
233         : > a5 &&
234         git add a5 &&
235         test_tick &&
236         git commit -m 5th &&
237         git notes add -m spam -m "foo
238 bar
239 baz"
242 whitespace="    "
243 cat > expect-m << EOF
244 commit bd1753200303d0a0344be813e504253b3d98e74d
245 Author: A U Thor <author@example.com>
246 Date:   Thu Apr 7 15:17:13 2005 -0700
248     5th
250 Notes:
251     spam
252 $whitespace
253     foo
254     bar
255     baz
256 EOF
258 printf "\n" >> expect-m
259 cat expect-F >> expect-m
261 test_expect_success 'show -m notes' '
262         git log -4 > output &&
263         test_cmp expect-m output
266 test_expect_success 'remove note with add -f -F /dev/null (setup)' '
267         git notes add -f -F /dev/null
270 cat > expect-rm-F << EOF
271 commit bd1753200303d0a0344be813e504253b3d98e74d
272 Author: A U Thor <author@example.com>
273 Date:   Thu Apr 7 15:17:13 2005 -0700
275     5th
276 EOF
278 printf "\n" >> expect-rm-F
279 cat expect-F >> expect-rm-F
281 test_expect_success 'verify note removal with -F /dev/null' '
282         git log -4 > output &&
283         test_cmp expect-rm-F output &&
284         ! git notes show
287 test_expect_success 'do not create empty note with -m "" (setup)' '
288         git notes add -m ""
291 test_expect_success 'verify non-creation of note with -m ""' '
292         git log -4 > output &&
293         test_cmp expect-rm-F output &&
294         ! git notes show
297 cat > expect-combine_m_and_F << EOF
298 foo
300 xyzzy
302 bar
304 zyxxy
306 baz
307 EOF
309 test_expect_success 'create note with combination of -m and -F' '
310         echo "xyzzy" > note_a &&
311         echo "zyxxy" > note_b &&
312         git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
313         git notes show > output &&
314         test_cmp expect-combine_m_and_F output
317 test_expect_success 'remove note with "git notes remove" (setup)' '
318         git notes remove HEAD^ &&
319         git notes remove
322 cat > expect-rm-remove << EOF
323 commit bd1753200303d0a0344be813e504253b3d98e74d
324 Author: A U Thor <author@example.com>
325 Date:   Thu Apr 7 15:17:13 2005 -0700
327     5th
329 commit 15023535574ded8b1a89052b32673f84cf9582b8
330 Author: A U Thor <author@example.com>
331 Date:   Thu Apr 7 15:16:13 2005 -0700
333     4th
334 EOF
336 printf "\n" >> expect-rm-remove
337 cat expect-multiline >> expect-rm-remove
339 test_expect_success 'verify note removal with "git notes remove"' '
340         git log -4 > output &&
341         test_cmp expect-rm-remove output &&
342         ! git notes show HEAD^
345 cat > expect << EOF
346 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
347 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
348 EOF
350 test_expect_success 'list notes with "git notes list"' '
351         git notes list > output &&
352         test_cmp expect output
355 test_expect_success 'list notes with "git notes"' '
356         git notes > output &&
357         test_cmp expect output
360 cat > expect << EOF
361 c18dc024e14f08d18d14eea0d747ff692d66d6a3
362 EOF
364 test_expect_success 'list specific note with "git notes list <object>"' '
365         git notes list HEAD^^ > output &&
366         test_cmp expect output
369 cat > expect << EOF
370 EOF
372 test_expect_success 'listing non-existing notes fails' '
373         test_must_fail git notes list HEAD > output &&
374         test_cmp expect output
377 cat > expect << EOF
378 Initial set of notes
380 More notes appended with git notes append
381 EOF
383 test_expect_success 'append to existing note with "git notes append"' '
384         git notes add -m "Initial set of notes" &&
385         git notes append -m "More notes appended with git notes append" &&
386         git notes show > output &&
387         test_cmp expect output
390 cat > expect_list << EOF
391 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
392 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
393 4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
394 EOF
396 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
397         git notes list > output &&
398         test_cmp expect_list output
401 test_expect_success 'appending empty string does not change existing note' '
402         git notes append -m "" &&
403         git notes show > output &&
404         test_cmp expect output
407 test_expect_success 'git notes append == add when there is no existing note' '
408         git notes remove HEAD &&
409         test_must_fail git notes list HEAD &&
410         git notes append -m "Initial set of notes
412 More notes appended with git notes append" &&
413         git notes show > output &&
414         test_cmp expect output
417 test_expect_success 'appending empty string to non-existing note does not create note' '
418         git notes remove HEAD &&
419         test_must_fail git notes list HEAD &&
420         git notes append -m "" &&
421         test_must_fail git notes list HEAD
424 test_expect_success 'create other note on a different notes ref (setup)' '
425         : > a6 &&
426         git add a6 &&
427         test_tick &&
428         git commit -m 6th &&
429         GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
432 cat > expect-other << EOF
433 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
434 Author: A U Thor <author@example.com>
435 Date:   Thu Apr 7 15:18:13 2005 -0700
437     6th
439 Notes (other):
440     other note
441 EOF
443 cat > expect-not-other << EOF
444 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
445 Author: A U Thor <author@example.com>
446 Date:   Thu Apr 7 15:18:13 2005 -0700
448     6th
449 EOF
451 test_expect_success 'Do not show note on other ref by default' '
452         git log -1 > output &&
453         test_cmp expect-not-other output
456 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
457         GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
458         test_cmp expect-other output
461 test_expect_success 'Do show note when ref is given in core.notesRef config' '
462         git config core.notesRef "refs/notes/other" &&
463         git log -1 > output &&
464         test_cmp expect-other output
467 test_expect_success 'Do not show note when core.notesRef is overridden' '
468         GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
469         test_cmp expect-not-other output
472 cat > expect-both << EOF
473 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
474 Author: A U Thor <author@example.com>
475 Date:   Thu Apr 7 15:18:13 2005 -0700
477     6th
479 Notes:
480     order test
482 Notes (other):
483     other note
485 commit bd1753200303d0a0344be813e504253b3d98e74d
486 Author: A U Thor <author@example.com>
487 Date:   Thu Apr 7 15:17:13 2005 -0700
489     5th
491 Notes:
492     replacement for deleted note
493 EOF
495 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
496         GIT_NOTES_REF=refs/notes/commits git notes add \
497                 -m"replacement for deleted note" HEAD^ &&
498         GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
499         git config --unset core.notesRef &&
500         git config notes.displayRef "refs/notes/*" &&
501         git log -2 > output &&
502         test_cmp expect-both output
505 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
506         git config core.notesRef refs/notes/commits &&
507         git config notes.displayRef refs/notes/other &&
508         git log -2 > output &&
509         test_cmp expect-both output
512 test_expect_success 'notes.displayRef can be given more than once' '
513         git config --unset core.notesRef &&
514         git config notes.displayRef refs/notes/commits &&
515         git config --add notes.displayRef refs/notes/other &&
516         git log -2 > output &&
517         test_cmp expect-both output
520 cat > expect-both-reversed << EOF
521 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
522 Author: A U Thor <author@example.com>
523 Date:   Thu Apr 7 15:18:13 2005 -0700
525     6th
527 Notes (other):
528     other note
530 Notes:
531     order test
532 EOF
534 test_expect_success 'notes.displayRef respects order' '
535         git config core.notesRef refs/notes/other &&
536         git config --unset-all notes.displayRef &&
537         git config notes.displayRef refs/notes/commits &&
538         git log -1 > output &&
539         test_cmp expect-both-reversed output
542 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
543         git config --unset-all core.notesRef &&
544         git config --unset-all notes.displayRef &&
545         GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
546                 git log -2 > output &&
547         test_cmp expect-both output
550 cat > expect-none << EOF
551 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
552 Author: A U Thor <author@example.com>
553 Date:   Thu Apr 7 15:18:13 2005 -0700
555     6th
557 commit bd1753200303d0a0344be813e504253b3d98e74d
558 Author: A U Thor <author@example.com>
559 Date:   Thu Apr 7 15:17:13 2005 -0700
561     5th
562 EOF
564 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
565         git config notes.displayRef "refs/notes/*" &&
566         GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
567         test_cmp expect-none output
570 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
571         GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
572         test_cmp expect-both output
575 cat > expect-commits << EOF
576 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
577 Author: A U Thor <author@example.com>
578 Date:   Thu Apr 7 15:18:13 2005 -0700
580     6th
582 Notes:
583     order test
584 EOF
586 test_expect_success '--no-standard-notes' '
587         git log --no-standard-notes --show-notes=commits -1 > output &&
588         test_cmp expect-commits output
591 test_expect_success '--standard-notes' '
592         git log --no-standard-notes --show-notes=commits \
593                 --standard-notes -2 > output &&
594         test_cmp expect-both output
597 test_expect_success '--show-notes=ref accumulates' '
598         git log --show-notes=other --show-notes=commits \
599                  --no-standard-notes -1 > output &&
600         test_cmp expect-both-reversed output
603 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
604         git config core.notesRef refs/notes/other &&
605         echo "Note on a tree" > expect
606         git notes add -m "Note on a tree" HEAD: &&
607         git notes show HEAD: > actual &&
608         test_cmp expect actual &&
609         echo "Note on a blob" > expect
610         filename=$(git ls-tree --name-only HEAD | head -n1) &&
611         git notes add -m "Note on a blob" HEAD:$filename &&
612         git notes show HEAD:$filename > actual &&
613         test_cmp expect actual &&
614         echo "Note on a tag" > expect
615         git tag -a -m "This is an annotated tag" foobar HEAD^ &&
616         git notes add -m "Note on a tag" foobar &&
617         git notes show foobar > actual &&
618         test_cmp expect actual
621 cat > expect << EOF
622 commit 2ede89468182a62d0bde2583c736089bcf7d7e92
623 Author: A U Thor <author@example.com>
624 Date:   Thu Apr 7 15:19:13 2005 -0700
626     7th
628 Notes (other):
629     other note
630 EOF
632 test_expect_success 'create note from other note with "git notes add -C"' '
633         : > a7 &&
634         git add a7 &&
635         test_tick &&
636         git commit -m 7th &&
637         git notes add -C $(git notes list HEAD^) &&
638         git log -1 > actual &&
639         test_cmp expect actual &&
640         test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
643 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
644         : > a8 &&
645         git add a8 &&
646         test_tick &&
647         git commit -m 8th &&
648         test_must_fail git notes add -C deadbeef &&
649         test_must_fail git notes list HEAD
652 cat > expect << EOF
653 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
654 Author: A U Thor <author@example.com>
655 Date:   Thu Apr 7 15:21:13 2005 -0700
657     9th
659 Notes (other):
660     yet another note
661 EOF
663 test_expect_success 'create note from other note with "git notes add -c"' '
664         : > a9 &&
665         git add a9 &&
666         test_tick &&
667         git commit -m 9th &&
668         MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
669         git log -1 > actual &&
670         test_cmp expect actual
673 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
674         : > a10 &&
675         git add a10 &&
676         test_tick &&
677         git commit -m 10th &&
678         test_must_fail MSG="yet another note" git notes add -c deadbeef &&
679         test_must_fail git notes list HEAD
682 cat > expect << EOF
683 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
684 Author: A U Thor <author@example.com>
685 Date:   Thu Apr 7 15:21:13 2005 -0700
687     9th
689 Notes (other):
690     yet another note
691 $whitespace
692     yet another note
693 EOF
695 test_expect_success 'append to note from other note with "git notes append -C"' '
696         git notes append -C $(git notes list HEAD^) HEAD^ &&
697         git log -1 HEAD^ > actual &&
698         test_cmp expect actual
701 cat > expect << EOF
702 commit ffed603236bfa3891c49644257a83598afe8ae5a
703 Author: A U Thor <author@example.com>
704 Date:   Thu Apr 7 15:22:13 2005 -0700
706     10th
708 Notes (other):
709     other note
710 EOF
712 test_expect_success 'create note from other note with "git notes append -c"' '
713         MSG="other note" git notes append -c $(git notes list HEAD^) &&
714         git log -1 > actual &&
715         test_cmp expect actual
718 cat > expect << EOF
719 commit ffed603236bfa3891c49644257a83598afe8ae5a
720 Author: A U Thor <author@example.com>
721 Date:   Thu Apr 7 15:22:13 2005 -0700
723     10th
725 Notes (other):
726     other note
727 $whitespace
728     yet another note
729 EOF
731 test_expect_success 'append to note from other note with "git notes append -c"' '
732         MSG="yet another note" git notes append -c $(git notes list HEAD) &&
733         git log -1 > actual &&
734         test_cmp expect actual
737 cat > expect << EOF
738 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
739 Author: A U Thor <author@example.com>
740 Date:   Thu Apr 7 15:23:13 2005 -0700
742     11th
744 Notes (other):
745     other note
746 $whitespace
747     yet another note
748 EOF
750 test_expect_success 'copy note with "git notes copy"' '
751         : > a11 &&
752         git add a11 &&
753         test_tick &&
754         git commit -m 11th &&
755         git notes copy HEAD^ HEAD &&
756         git log -1 > actual &&
757         test_cmp expect actual &&
758         test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
761 test_expect_success 'prevent overwrite with "git notes copy"' '
762         test_must_fail git notes copy HEAD~2 HEAD &&
763         git log -1 > actual &&
764         test_cmp expect actual &&
765         test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
768 cat > expect << EOF
769 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
770 Author: A U Thor <author@example.com>
771 Date:   Thu Apr 7 15:23:13 2005 -0700
773     11th
775 Notes (other):
776     yet another note
777 $whitespace
778     yet another note
779 EOF
781 test_expect_success 'allow overwrite with "git notes copy -f"' '
782         git notes copy -f HEAD~2 HEAD &&
783         git log -1 > actual &&
784         test_cmp expect actual &&
785         test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
788 test_expect_success 'cannot copy note from object without notes' '
789         : > a12 &&
790         git add a12 &&
791         test_tick &&
792         git commit -m 12th &&
793         : > a13 &&
794         git add a13 &&
795         test_tick &&
796         git commit -m 13th &&
797         test_must_fail git notes copy HEAD^ HEAD
800 cat > expect << EOF
801 commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
802 Author: A U Thor <author@example.com>
803 Date:   Thu Apr 7 15:25:13 2005 -0700
805     13th
807 Notes (other):
808     yet another note
809 $whitespace
810     yet another note
812 commit 7038787dfe22a14c3867ce816dbba39845359719
813 Author: A U Thor <author@example.com>
814 Date:   Thu Apr 7 15:24:13 2005 -0700
816     12th
818 Notes (other):
819     other note
820 $whitespace
821     yet another note
822 EOF
824 test_expect_success 'git notes copy --stdin' '
825         (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
826         echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
827         git notes copy --stdin &&
828         git log -2 > output &&
829         test_cmp expect output &&
830         test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
831         test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
834 cat > expect << EOF
835 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
836 Author: A U Thor <author@example.com>
837 Date:   Thu Apr 7 15:27:13 2005 -0700
839     15th
841 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
842 Author: A U Thor <author@example.com>
843 Date:   Thu Apr 7 15:26:13 2005 -0700
845     14th
846 EOF
848 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
849         test_commit 14th &&
850         test_commit 15th &&
851         (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
852         echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
853         git notes copy --for-rewrite=foo &&
854         git log -2 > output &&
855         test_cmp expect output
858 cat > expect << EOF
859 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
860 Author: A U Thor <author@example.com>
861 Date:   Thu Apr 7 15:27:13 2005 -0700
863     15th
865 Notes (other):
866     yet another note
867 $whitespace
868     yet another note
870 commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
871 Author: A U Thor <author@example.com>
872 Date:   Thu Apr 7 15:26:13 2005 -0700
874     14th
876 Notes (other):
877     other note
878 $whitespace
879     yet another note
880 EOF
882 test_expect_success 'git notes copy --for-rewrite (enabled)' '
883         git config notes.rewriteMode overwrite &&
884         git config notes.rewriteRef "refs/notes/*" &&
885         (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
886         echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
887         git notes copy --for-rewrite=foo &&
888         git log -2 > output &&
889         test_cmp expect output
892 test_expect_success 'git notes copy --for-rewrite (disabled)' '
893         git config notes.rewrite.bar false &&
894         echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
895         git notes copy --for-rewrite=bar &&
896         git log -2 > output &&
897         test_cmp expect output
900 cat > expect << EOF
901 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
902 Author: A U Thor <author@example.com>
903 Date:   Thu Apr 7 15:27:13 2005 -0700
905     15th
907 Notes (other):
908     a fresh note
909 EOF
911 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
912         git notes add -f -m"a fresh note" HEAD^ &&
913         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
914         git notes copy --for-rewrite=foo &&
915         git log -1 > output &&
916         test_cmp expect output
919 test_expect_success 'git notes copy --for-rewrite (ignore)' '
920         git config notes.rewriteMode ignore &&
921         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
922         git notes copy --for-rewrite=foo &&
923         git log -1 > output &&
924         test_cmp expect output
927 cat > expect << EOF
928 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
929 Author: A U Thor <author@example.com>
930 Date:   Thu Apr 7 15:27:13 2005 -0700
932     15th
934 Notes (other):
935     a fresh note
936     another fresh note
937 EOF
939 test_expect_success 'git notes copy --for-rewrite (append)' '
940         git notes add -f -m"another fresh note" HEAD^ &&
941         git config notes.rewriteMode concatenate &&
942         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
943         git notes copy --for-rewrite=foo &&
944         git log -1 > output &&
945         test_cmp expect output
948 cat > expect << EOF
949 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
950 Author: A U Thor <author@example.com>
951 Date:   Thu Apr 7 15:27:13 2005 -0700
953     15th
955 Notes (other):
956     a fresh note
957     another fresh note
958     append 1
959     append 2
960 EOF
962 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
963         git notes add -f -m"append 1" HEAD^ &&
964         git notes add -f -m"append 2" HEAD^^ &&
965         (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
966         echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
967         git notes copy --for-rewrite=foo &&
968         git log -1 > output &&
969         test_cmp expect output
972 test_expect_success 'git notes copy --for-rewrite (append empty)' '
973         git notes remove HEAD^ &&
974         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
975         git notes copy --for-rewrite=foo &&
976         git log -1 > output &&
977         test_cmp expect output
980 cat > expect << EOF
981 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
982 Author: A U Thor <author@example.com>
983 Date:   Thu Apr 7 15:27:13 2005 -0700
985     15th
987 Notes (other):
988     replacement note 1
989 EOF
991 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
992         git notes add -f -m"replacement note 1" HEAD^ &&
993         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
994         GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
995         git log -1 > output &&
996         test_cmp expect output
999 cat > expect << EOF
1000 commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1001 Author: A U Thor <author@example.com>
1002 Date:   Thu Apr 7 15:27:13 2005 -0700
1004     15th
1006 Notes (other):
1007     replacement note 2
1008 EOF
1010 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1011         git config notes.rewriteMode overwrite &&
1012         git notes add -f -m"replacement note 2" HEAD^ &&
1013         git config --unset-all notes.rewriteRef &&
1014         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1015         GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1016                 git notes copy --for-rewrite=foo &&
1017         git log -1 > output &&
1018         test_cmp expect output
1021 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1022         git config notes.rewriteRef refs/notes/other &&
1023         git notes add -f -m"replacement note 3" HEAD^ &&
1024         echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1025         GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1026         git log -1 > output &&
1027         test_cmp expect output
1029 test_done