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