1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='Test commit notes'
7
8. ./test-lib.sh
9
10cat > fake_editor.sh << \EOF
11#!/bin/sh
12echo "$MSG" > "$1"
13echo "$MSG" >& 2
14EOF
15chmod a+x fake_editor.sh
16GIT_EDITOR=./fake_editor.sh
17export GIT_EDITOR
18
19test_expect_success 'cannot annotate non-existing HEAD' '
20 (MSG=3 && export MSG && test_must_fail git notes add)
21'
22
23test_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'
33
34test_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'
40
41test_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'
46
47test_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'
52
53# 1 indicates caught gracefully by die, 128 means git-show barked
54test_expect_success 'handle empty notes gracefully' '
55 test_expect_code 1 git notes show
56'
57
58test_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'
66
67test_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'
76
77test_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'
85
86cat >expect <<EOF
87d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add'
88EOF
89
90test_expect_success 'create reflog entry' '
91 git reflog show refs/notes/commits >output &&
92 test_cmp expect output
93'
94
95test_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^
102'
103
104test_expect_success 'cannot add note where one exists' '
105 ! MSG=b2 git notes add &&
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^
111'
112
113test_expect_success 'can overwrite existing note with "git notes add -f"' '
114 MSG=b1 git notes add -f &&
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^
120'
121
122cat > expect << EOF
123commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
124Author: A U Thor <author@example.com>
125Date: Thu Apr 7 15:14:13 2005 -0700
126
127 2nd
128
129Notes:
130 b1
131EOF
132
133test_expect_success 'show notes' '
134 ! (git cat-file commit HEAD | grep b1) &&
135 git log -1 > output &&
136 test_cmp expect output
137'
138
139test_expect_success 'create multi-line notes (setup)' '
140 : > a3 &&
141 git add a3 &&
142 test_tick &&
143 git commit -m 3rd &&
144 MSG="b3
145c3c3c3c3
146d3d3d3" git notes add
147'
148
149cat > expect-multiline << EOF
150commit 1584215f1d29c65e99c6c6848626553fdd07fd75
151Author: A U Thor <author@example.com>
152Date: Thu Apr 7 15:15:13 2005 -0700
153
154 3rd
155
156Notes:
157 b3
158 c3c3c3c3
159 d3d3d3
160EOF
161
162printf "\n" >> expect-multiline
163cat expect >> expect-multiline
164
165test_expect_success 'show multi-line notes' '
166 git log -2 > output &&
167 test_cmp expect-multiline output
168'
169test_expect_success 'create -F notes (setup)' '
170 : > a4 &&
171 git add a4 &&
172 test_tick &&
173 git commit -m 4th &&
174 echo "xyzzy" > note5 &&
175 git notes add -F note5
176'
177
178cat > expect-F << EOF
179commit 15023535574ded8b1a89052b32673f84cf9582b8
180Author: A U Thor <author@example.com>
181Date: Thu Apr 7 15:16:13 2005 -0700
182
183 4th
184
185Notes:
186 xyzzy
187EOF
188
189printf "\n" >> expect-F
190cat expect-multiline >> expect-F
191
192test_expect_success 'show -F notes' '
193 git log -3 > output &&
194 test_cmp expect-F output
195'
196
197cat >expect << EOF
198commit 15023535574ded8b1a89052b32673f84cf9582b8
199tree e070e3af51011e47b183c33adf9736736a525709
200parent 1584215f1d29c65e99c6c6848626553fdd07fd75
201author A U Thor <author@example.com> 1112912173 -0700
202committer C O Mitter <committer@example.com> 1112912173 -0700
203
204 4th
205EOF
206test_expect_success 'git log --pretty=raw does not show notes' '
207 git log -1 --pretty=raw >output &&
208 test_cmp expect output
209'
210
211cat >>expect <<EOF
212
213Notes:
214 xyzzy
215EOF
216test_expect_success 'git log --show-notes' '
217 git log -1 --pretty=raw --show-notes >output &&
218 test_cmp expect output
219'
220
221test_expect_success 'git log --no-notes' '
222 git log -1 --no-notes >output &&
223 ! grep xyzzy output
224'
225
226test_expect_success 'git format-patch does not show notes' '
227 git format-patch -1 --stdout >output &&
228 ! grep xyzzy output
229'
230
231test_expect_success 'git format-patch --show-notes does show notes' '
232 git format-patch --show-notes -1 --stdout >output &&
233 grep xyzzy output
234'
235
236for pretty in \
237 "" --pretty --pretty=raw --pretty=short --pretty=medium \
238 --pretty=full --pretty=fuller --pretty=format:%s --oneline
239do
240 case "$pretty" in
241 "") p= not= negate="" ;;
242 ?*) p="$pretty" not=" not" negate="!" ;;
243 esac
244 test_expect_success "git show $pretty does$not show notes" '
245 git show $p >output &&
246 eval "$negate grep xyzzy output"
247 '
248done
249
250test_expect_success 'setup alternate notes ref' '
251 git notes --ref=alternate add -m alternate
252'
253
254test_expect_success 'git log --notes shows default notes' '
255 git log -1 --notes >output &&
256 grep xyzzy output &&
257 ! grep alternate output
258'
259
260test_expect_success 'git log --notes=X shows only X' '
261 git log -1 --notes=alternate >output &&
262 ! grep xyzzy output &&
263 grep alternate output
264'
265
266test_expect_success 'git log --notes --notes=X shows both' '
267 git log -1 --notes --notes=alternate >output &&
268 grep xyzzy output &&
269 grep alternate output
270'
271
272test_expect_success 'git log --no-notes resets default state' '
273 git log -1 --notes --notes=alternate \
274 --no-notes --notes=alternate \
275 >output &&
276 ! grep xyzzy output &&
277 grep alternate output
278'
279
280test_expect_success 'git log --no-notes resets ref list' '
281 git log -1 --notes --notes=alternate \
282 --no-notes --notes \
283 >output &&
284 grep xyzzy output &&
285 ! grep alternate output
286'
287
288test_expect_success 'create -m notes (setup)' '
289 : > a5 &&
290 git add a5 &&
291 test_tick &&
292 git commit -m 5th &&
293 git notes add -m spam -m "foo
294bar
295baz"
296'
297
298whitespace=" "
299cat > expect-m << EOF
300commit bd1753200303d0a0344be813e504253b3d98e74d
301Author: A U Thor <author@example.com>
302Date: Thu Apr 7 15:17:13 2005 -0700
303
304 5th
305
306Notes:
307 spam
308$whitespace
309 foo
310 bar
311 baz
312EOF
313
314printf "\n" >> expect-m
315cat expect-F >> expect-m
316
317test_expect_success 'show -m notes' '
318 git log -4 > output &&
319 test_cmp expect-m output
320'
321
322test_expect_success 'remove note with add -f -F /dev/null (setup)' '
323 git notes add -f -F /dev/null
324'
325
326cat > expect-rm-F << EOF
327commit bd1753200303d0a0344be813e504253b3d98e74d
328Author: A U Thor <author@example.com>
329Date: Thu Apr 7 15:17:13 2005 -0700
330
331 5th
332EOF
333
334printf "\n" >> expect-rm-F
335cat expect-F >> expect-rm-F
336
337test_expect_success 'verify note removal with -F /dev/null' '
338 git log -4 > output &&
339 test_cmp expect-rm-F output &&
340 test_must_fail git notes show
341'
342
343test_expect_success 'do not create empty note with -m "" (setup)' '
344 git notes add -m ""
345'
346
347test_expect_success 'verify non-creation of note with -m ""' '
348 git log -4 > output &&
349 test_cmp expect-rm-F output &&
350 test_must_fail git notes show
351'
352
353cat > expect-combine_m_and_F << EOF
354foo
355
356xyzzy
357
358bar
359
360zyxxy
361
362baz
363EOF
364
365test_expect_success 'create note with combination of -m and -F' '
366 echo "xyzzy" > note_a &&
367 echo "zyxxy" > note_b &&
368 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
369 git notes show > output &&
370 test_cmp expect-combine_m_and_F output
371'
372
373test_expect_success 'remove note with "git notes remove" (setup)' '
374 git notes remove HEAD^ &&
375 git notes remove
376'
377
378cat > expect-rm-remove << EOF
379commit bd1753200303d0a0344be813e504253b3d98e74d
380Author: A U Thor <author@example.com>
381Date: Thu Apr 7 15:17:13 2005 -0700
382
383 5th
384
385commit 15023535574ded8b1a89052b32673f84cf9582b8
386Author: A U Thor <author@example.com>
387Date: Thu Apr 7 15:16:13 2005 -0700
388
389 4th
390EOF
391
392printf "\n" >> expect-rm-remove
393cat expect-multiline >> expect-rm-remove
394
395test_expect_success 'verify note removal with "git notes remove"' '
396 git log -4 > output &&
397 test_cmp expect-rm-remove output &&
398 test_must_fail git notes show HEAD^
399'
400
401cat > expect << EOF
402c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
403c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
404EOF
405
406test_expect_success 'removing non-existing note should not create new commit' '
407 git rev-parse --verify refs/notes/commits > before_commit &&
408 test_must_fail git notes remove HEAD^ &&
409 git rev-parse --verify refs/notes/commits > after_commit &&
410 test_cmp before_commit after_commit
411'
412
413test_expect_success 'list notes with "git notes list"' '
414 git notes list > output &&
415 test_cmp expect output
416'
417
418test_expect_success 'list notes with "git notes"' '
419 git notes > output &&
420 test_cmp expect output
421'
422
423cat > expect << EOF
424c18dc024e14f08d18d14eea0d747ff692d66d6a3
425EOF
426
427test_expect_success 'list specific note with "git notes list <object>"' '
428 git notes list HEAD^^ > output &&
429 test_cmp expect output
430'
431
432cat > expect << EOF
433EOF
434
435test_expect_success 'listing non-existing notes fails' '
436 test_must_fail git notes list HEAD > output &&
437 test_cmp expect output
438'
439
440cat > expect << EOF
441Initial set of notes
442
443More notes appended with git notes append
444EOF
445
446test_expect_success 'append to existing note with "git notes append"' '
447 git notes add -m "Initial set of notes" &&
448 git notes append -m "More notes appended with git notes append" &&
449 git notes show > output &&
450 test_cmp expect output
451'
452
453cat > expect_list << EOF
454c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
455c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
4564b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
457EOF
458
459test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
460 git notes list > output &&
461 test_cmp expect_list output
462'
463
464test_expect_success 'appending empty string does not change existing note' '
465 git notes append -m "" &&
466 git notes show > output &&
467 test_cmp expect output
468'
469
470test_expect_success 'git notes append == add when there is no existing note' '
471 git notes remove HEAD &&
472 test_must_fail git notes list HEAD &&
473 git notes append -m "Initial set of notes
474
475More notes appended with git notes append" &&
476 git notes show > output &&
477 test_cmp expect output
478'
479
480test_expect_success 'appending empty string to non-existing note does not create note' '
481 git notes remove HEAD &&
482 test_must_fail git notes list HEAD &&
483 git notes append -m "" &&
484 test_must_fail git notes list HEAD
485'
486
487test_expect_success 'create other note on a different notes ref (setup)' '
488 : > a6 &&
489 git add a6 &&
490 test_tick &&
491 git commit -m 6th &&
492 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
493'
494
495cat > expect-other << EOF
496commit 387a89921c73d7ed72cd94d179c1c7048ca47756
497Author: A U Thor <author@example.com>
498Date: Thu Apr 7 15:18:13 2005 -0700
499
500 6th
501
502Notes (other):
503 other note
504EOF
505
506cat > expect-not-other << EOF
507commit 387a89921c73d7ed72cd94d179c1c7048ca47756
508Author: A U Thor <author@example.com>
509Date: Thu Apr 7 15:18:13 2005 -0700
510
511 6th
512EOF
513
514test_expect_success 'Do not show note on other ref by default' '
515 git log -1 > output &&
516 test_cmp expect-not-other output
517'
518
519test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
520 GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
521 test_cmp expect-other output
522'
523
524test_expect_success 'Do show note when ref is given in core.notesRef config' '
525 git config core.notesRef "refs/notes/other" &&
526 git log -1 > output &&
527 test_cmp expect-other output
528'
529
530test_expect_success 'Do not show note when core.notesRef is overridden' '
531 GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
532 test_cmp expect-not-other output
533'
534
535cat > expect-both << EOF
536commit 387a89921c73d7ed72cd94d179c1c7048ca47756
537Author: A U Thor <author@example.com>
538Date: Thu Apr 7 15:18:13 2005 -0700
539
540 6th
541
542Notes:
543 order test
544
545Notes (other):
546 other note
547
548commit bd1753200303d0a0344be813e504253b3d98e74d
549Author: A U Thor <author@example.com>
550Date: Thu Apr 7 15:17:13 2005 -0700
551
552 5th
553
554Notes:
555 replacement for deleted note
556EOF
557
558test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
559 GIT_NOTES_REF=refs/notes/commits git notes add \
560 -m"replacement for deleted note" HEAD^ &&
561 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
562 git config --unset core.notesRef &&
563 git config notes.displayRef "refs/notes/*" &&
564 git log -2 > output &&
565 test_cmp expect-both output
566'
567
568test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
569 git config core.notesRef refs/notes/commits &&
570 git config notes.displayRef refs/notes/other &&
571 git log -2 > output &&
572 test_cmp expect-both output
573'
574
575test_expect_success 'notes.displayRef can be given more than once' '
576 git config --unset core.notesRef &&
577 git config notes.displayRef refs/notes/commits &&
578 git config --add notes.displayRef refs/notes/other &&
579 git log -2 > output &&
580 test_cmp expect-both output
581'
582
583cat > expect-both-reversed << EOF
584commit 387a89921c73d7ed72cd94d179c1c7048ca47756
585Author: A U Thor <author@example.com>
586Date: Thu Apr 7 15:18:13 2005 -0700
587
588 6th
589
590Notes (other):
591 other note
592
593Notes:
594 order test
595EOF
596
597test_expect_success 'notes.displayRef respects order' '
598 git config core.notesRef refs/notes/other &&
599 git config --unset-all notes.displayRef &&
600 git config notes.displayRef refs/notes/commits &&
601 git log -1 > output &&
602 test_cmp expect-both-reversed output
603'
604
605test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
606 git config --unset-all core.notesRef &&
607 git config --unset-all notes.displayRef &&
608 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
609 git log -2 > output &&
610 test_cmp expect-both output
611'
612
613cat > expect-none << EOF
614commit 387a89921c73d7ed72cd94d179c1c7048ca47756
615Author: A U Thor <author@example.com>
616Date: Thu Apr 7 15:18:13 2005 -0700
617
618 6th
619
620commit bd1753200303d0a0344be813e504253b3d98e74d
621Author: A U Thor <author@example.com>
622Date: Thu Apr 7 15:17:13 2005 -0700
623
624 5th
625EOF
626
627test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
628 git config notes.displayRef "refs/notes/*" &&
629 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
630 test_cmp expect-none output
631'
632
633test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
634 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
635 test_cmp expect-both output
636'
637
638cat > expect-commits << EOF
639commit 387a89921c73d7ed72cd94d179c1c7048ca47756
640Author: A U Thor <author@example.com>
641Date: Thu Apr 7 15:18:13 2005 -0700
642
643 6th
644
645Notes:
646 order test
647EOF
648
649test_expect_success '--no-standard-notes' '
650 git log --no-standard-notes --show-notes=commits -1 > output &&
651 test_cmp expect-commits output
652'
653
654test_expect_success '--standard-notes' '
655 git log --no-standard-notes --show-notes=commits \
656 --standard-notes -2 > output &&
657 test_cmp expect-both output
658'
659
660test_expect_success '--show-notes=ref accumulates' '
661 git log --show-notes=other --show-notes=commits \
662 --no-standard-notes -1 > output &&
663 test_cmp expect-both-reversed output
664'
665
666test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
667 git config core.notesRef refs/notes/other &&
668 echo "Note on a tree" > expect &&
669 git notes add -m "Note on a tree" HEAD: &&
670 git notes show HEAD: > actual &&
671 test_cmp expect actual &&
672 echo "Note on a blob" > expect &&
673 filename=$(git ls-tree --name-only HEAD | head -n1) &&
674 git notes add -m "Note on a blob" HEAD:$filename &&
675 git notes show HEAD:$filename > actual &&
676 test_cmp expect actual &&
677 echo "Note on a tag" > expect &&
678 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
679 git notes add -m "Note on a tag" foobar &&
680 git notes show foobar > actual &&
681 test_cmp expect actual
682'
683
684cat > expect << EOF
685commit 2ede89468182a62d0bde2583c736089bcf7d7e92
686Author: A U Thor <author@example.com>
687Date: Thu Apr 7 15:19:13 2005 -0700
688
689 7th
690
691Notes (other):
692 other note
693EOF
694
695test_expect_success 'create note from other note with "git notes add -C"' '
696 : > a7 &&
697 git add a7 &&
698 test_tick &&
699 git commit -m 7th &&
700 git notes add -C $(git notes list HEAD^) &&
701 git log -1 > actual &&
702 test_cmp expect actual &&
703 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
704'
705
706test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
707 : > a8 &&
708 git add a8 &&
709 test_tick &&
710 git commit -m 8th &&
711 test_must_fail git notes add -C deadbeef &&
712 test_must_fail git notes list HEAD
713'
714
715cat > expect << EOF
716commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
717Author: A U Thor <author@example.com>
718Date: Thu Apr 7 15:21:13 2005 -0700
719
720 9th
721
722Notes (other):
723 yet another note
724EOF
725
726test_expect_success 'create note from other note with "git notes add -c"' '
727 : > a9 &&
728 git add a9 &&
729 test_tick &&
730 git commit -m 9th &&
731 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
732 git log -1 > actual &&
733 test_cmp expect actual
734'
735
736test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
737 : > a10 &&
738 git add a10 &&
739 test_tick &&
740 git commit -m 10th &&
741 (
742 MSG="yet another note" &&
743 export MSG &&
744 test_must_fail git notes add -c deadbeef
745 ) &&
746 test_must_fail git notes list HEAD
747'
748
749cat > expect << EOF
750commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
751Author: A U Thor <author@example.com>
752Date: Thu Apr 7 15:21:13 2005 -0700
753
754 9th
755
756Notes (other):
757 yet another note
758$whitespace
759 yet another note
760EOF
761
762test_expect_success 'append to note from other note with "git notes append -C"' '
763 git notes append -C $(git notes list HEAD^) HEAD^ &&
764 git log -1 HEAD^ > actual &&
765 test_cmp expect actual
766'
767
768cat > expect << EOF
769commit ffed603236bfa3891c49644257a83598afe8ae5a
770Author: A U Thor <author@example.com>
771Date: Thu Apr 7 15:22:13 2005 -0700
772
773 10th
774
775Notes (other):
776 other note
777EOF
778
779test_expect_success 'create note from other note with "git notes append -c"' '
780 MSG="other note" git notes append -c $(git notes list HEAD^) &&
781 git log -1 > actual &&
782 test_cmp expect actual
783'
784
785cat > expect << EOF
786commit ffed603236bfa3891c49644257a83598afe8ae5a
787Author: A U Thor <author@example.com>
788Date: Thu Apr 7 15:22:13 2005 -0700
789
790 10th
791
792Notes (other):
793 other note
794$whitespace
795 yet another note
796EOF
797
798test_expect_success 'append to note from other note with "git notes append -c"' '
799 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
800 git log -1 > actual &&
801 test_cmp expect actual
802'
803
804cat > expect << EOF
805commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
806Author: A U Thor <author@example.com>
807Date: Thu Apr 7 15:23:13 2005 -0700
808
809 11th
810
811Notes (other):
812 other note
813$whitespace
814 yet another note
815EOF
816
817test_expect_success 'copy note with "git notes copy"' '
818 : > a11 &&
819 git add a11 &&
820 test_tick &&
821 git commit -m 11th &&
822 git notes copy HEAD^ HEAD &&
823 git log -1 > actual &&
824 test_cmp expect actual &&
825 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
826'
827
828test_expect_success 'prevent overwrite with "git notes copy"' '
829 test_must_fail git notes copy HEAD~2 HEAD &&
830 git log -1 > actual &&
831 test_cmp expect actual &&
832 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
833'
834
835cat > expect << EOF
836commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
837Author: A U Thor <author@example.com>
838Date: Thu Apr 7 15:23:13 2005 -0700
839
840 11th
841
842Notes (other):
843 yet another note
844$whitespace
845 yet another note
846EOF
847
848test_expect_success 'allow overwrite with "git notes copy -f"' '
849 git notes copy -f HEAD~2 HEAD &&
850 git log -1 > actual &&
851 test_cmp expect actual &&
852 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
853'
854
855test_expect_success 'cannot copy note from object without notes' '
856 : > a12 &&
857 git add a12 &&
858 test_tick &&
859 git commit -m 12th &&
860 : > a13 &&
861 git add a13 &&
862 test_tick &&
863 git commit -m 13th &&
864 test_must_fail git notes copy HEAD^ HEAD
865'
866
867cat > expect << EOF
868commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
869Author: A U Thor <author@example.com>
870Date: Thu Apr 7 15:25:13 2005 -0700
871
872 13th
873
874Notes (other):
875 yet another note
876$whitespace
877 yet another note
878
879commit 7038787dfe22a14c3867ce816dbba39845359719
880Author: A U Thor <author@example.com>
881Date: Thu Apr 7 15:24:13 2005 -0700
882
883 12th
884
885Notes (other):
886 other note
887$whitespace
888 yet another note
889EOF
890
891test_expect_success 'git notes copy --stdin' '
892 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
893 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
894 git notes copy --stdin &&
895 git log -2 > output &&
896 test_cmp expect output &&
897 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
898 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
899'
900
901cat > expect << EOF
902commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
903Author: A U Thor <author@example.com>
904Date: Thu Apr 7 15:27:13 2005 -0700
905
906 15th
907
908commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
909Author: A U Thor <author@example.com>
910Date: Thu Apr 7 15:26:13 2005 -0700
911
912 14th
913EOF
914
915test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
916 test_commit 14th &&
917 test_commit 15th &&
918 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
919 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
920 git notes copy --for-rewrite=foo &&
921 git log -2 > output &&
922 test_cmp expect output
923'
924
925cat > expect << EOF
926commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
927Author: A U Thor <author@example.com>
928Date: Thu Apr 7 15:27:13 2005 -0700
929
930 15th
931
932Notes (other):
933 yet another note
934$whitespace
935 yet another note
936
937commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
938Author: A U Thor <author@example.com>
939Date: Thu Apr 7 15:26:13 2005 -0700
940
941 14th
942
943Notes (other):
944 other note
945$whitespace
946 yet another note
947EOF
948
949test_expect_success 'git notes copy --for-rewrite (enabled)' '
950 git config notes.rewriteMode overwrite &&
951 git config notes.rewriteRef "refs/notes/*" &&
952 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
953 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
954 git notes copy --for-rewrite=foo &&
955 git log -2 > output &&
956 test_cmp expect output
957'
958
959test_expect_success 'git notes copy --for-rewrite (disabled)' '
960 git config notes.rewrite.bar false &&
961 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
962 git notes copy --for-rewrite=bar &&
963 git log -2 > output &&
964 test_cmp expect output
965'
966
967cat > expect << EOF
968commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
969Author: A U Thor <author@example.com>
970Date: Thu Apr 7 15:27:13 2005 -0700
971
972 15th
973
974Notes (other):
975 a fresh note
976EOF
977
978test_expect_success 'git notes copy --for-rewrite (overwrite)' '
979 git notes add -f -m"a fresh note" HEAD^ &&
980 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
981 git notes copy --for-rewrite=foo &&
982 git log -1 > output &&
983 test_cmp expect output
984'
985
986test_expect_success 'git notes copy --for-rewrite (ignore)' '
987 git config notes.rewriteMode ignore &&
988 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
989 git notes copy --for-rewrite=foo &&
990 git log -1 > output &&
991 test_cmp expect output
992'
993
994cat > expect << EOF
995commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
996Author: A U Thor <author@example.com>
997Date: Thu Apr 7 15:27:13 2005 -0700
998
999 15th
1000
1001Notes (other):
1002 a fresh note
1003$whitespace
1004 another fresh note
1005EOF
1006
1007test_expect_success 'git notes copy --for-rewrite (append)' '
1008 git notes add -f -m"another fresh note" HEAD^ &&
1009 git config notes.rewriteMode concatenate &&
1010 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1011 git notes copy --for-rewrite=foo &&
1012 git log -1 > output &&
1013 test_cmp expect output
1014'
1015
1016cat > expect << EOF
1017commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1018Author: A U Thor <author@example.com>
1019Date: Thu Apr 7 15:27:13 2005 -0700
1020
1021 15th
1022
1023Notes (other):
1024 a fresh note
1025$whitespace
1026 another fresh note
1027$whitespace
1028 append 1
1029$whitespace
1030 append 2
1031EOF
1032
1033test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1034 git notes add -f -m"append 1" HEAD^ &&
1035 git notes add -f -m"append 2" HEAD^^ &&
1036 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
1037 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1038 git notes copy --for-rewrite=foo &&
1039 git log -1 > output &&
1040 test_cmp expect output
1041'
1042
1043test_expect_success 'git notes copy --for-rewrite (append empty)' '
1044 git notes remove 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
1049'
1050
1051cat > expect << EOF
1052commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1053Author: A U Thor <author@example.com>
1054Date: Thu Apr 7 15:27:13 2005 -0700
1055
1056 15th
1057
1058Notes (other):
1059 replacement note 1
1060EOF
1061
1062test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1063 git notes add -f -m"replacement note 1" HEAD^ &&
1064 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1065 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1066 git log -1 > output &&
1067 test_cmp expect output
1068'
1069
1070cat > expect << EOF
1071commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1072Author: A U Thor <author@example.com>
1073Date: Thu Apr 7 15:27:13 2005 -0700
1074
1075 15th
1076
1077Notes (other):
1078 replacement note 2
1079EOF
1080
1081test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1082 git config notes.rewriteMode overwrite &&
1083 git notes add -f -m"replacement note 2" HEAD^ &&
1084 git config --unset-all notes.rewriteRef &&
1085 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1086 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1087 git notes copy --for-rewrite=foo &&
1088 git log -1 > output &&
1089 test_cmp expect output
1090'
1091
1092test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1093 git config notes.rewriteRef refs/notes/other &&
1094 git notes add -f -m"replacement note 3" HEAD^ &&
1095 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1096 GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1097 git log -1 > output &&
1098 test_cmp expect output
1099'
1100
1101test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1102 test_must_fail git notes copy &&
1103 test_must_fail git notes copy one two three
1104'
1105
1106test_expect_success 'git notes get-ref (no overrides)' '
1107 git config --unset core.notesRef &&
1108 sane_unset GIT_NOTES_REF &&
1109 test "$(git notes get-ref)" = "refs/notes/commits"
1110'
1111
1112test_expect_success 'git notes get-ref (core.notesRef)' '
1113 git config core.notesRef refs/notes/foo &&
1114 test "$(git notes get-ref)" = "refs/notes/foo"
1115'
1116
1117test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1118 test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1119'
1120
1121test_expect_success 'git notes get-ref (--ref)' '
1122 test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1123'
1124
1125test_done