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 git notes show ; test 1 = $?
56'
57
58test_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'
67
68cat >expect <<EOF
69d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add'
70EOF
71
72test_expect_success 'create reflog entry' '
73 git reflog show refs/notes/commits >output &&
74 test_cmp expect output
75'
76
77test_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'
85
86test_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'
94
95test_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^
102'
103
104cat > expect << EOF
105commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
106Author: A U Thor <author@example.com>
107Date: Thu Apr 7 15:14:13 2005 -0700
108
109 2nd
110
111Notes:
112 b1
113EOF
114
115test_expect_success 'show notes' '
116 ! (git cat-file commit HEAD | grep b1) &&
117 git log -1 > output &&
118 test_cmp expect output
119'
120
121test_expect_success 'create multi-line notes (setup)' '
122 : > a3 &&
123 git add a3 &&
124 test_tick &&
125 git commit -m 3rd &&
126 MSG="b3
127c3c3c3c3
128d3d3d3" git notes add
129'
130
131cat > expect-multiline << EOF
132commit 1584215f1d29c65e99c6c6848626553fdd07fd75
133Author: A U Thor <author@example.com>
134Date: Thu Apr 7 15:15:13 2005 -0700
135
136 3rd
137
138Notes:
139 b3
140 c3c3c3c3
141 d3d3d3
142EOF
143
144printf "\n" >> expect-multiline
145cat expect >> expect-multiline
146
147test_expect_success 'show multi-line notes' '
148 git log -2 > output &&
149 test_cmp expect-multiline output
150'
151test_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
158'
159
160cat > expect-F << EOF
161commit 15023535574ded8b1a89052b32673f84cf9582b8
162Author: A U Thor <author@example.com>
163Date: Thu Apr 7 15:16:13 2005 -0700
164
165 4th
166
167Notes:
168 xyzzy
169EOF
170
171printf "\n" >> expect-F
172cat expect-multiline >> expect-F
173
174test_expect_success 'show -F notes' '
175 git log -3 > output &&
176 test_cmp expect-F output
177'
178
179cat >expect << EOF
180commit 15023535574ded8b1a89052b32673f84cf9582b8
181tree e070e3af51011e47b183c33adf9736736a525709
182parent 1584215f1d29c65e99c6c6848626553fdd07fd75
183author A U Thor <author@example.com> 1112912173 -0700
184committer C O Mitter <committer@example.com> 1112912173 -0700
185
186 4th
187EOF
188test_expect_success 'git log --pretty=raw does not show notes' '
189 git log -1 --pretty=raw >output &&
190 test_cmp expect output
191'
192
193cat >>expect <<EOF
194
195Notes:
196 xyzzy
197EOF
198test_expect_success 'git log --show-notes' '
199 git log -1 --pretty=raw --show-notes >output &&
200 test_cmp expect output
201'
202
203test_expect_success 'git log --no-notes' '
204 git log -1 --no-notes >output &&
205 ! grep xyzzy output
206'
207
208test_expect_success 'git format-patch does not show notes' '
209 git format-patch -1 --stdout >output &&
210 ! grep xyzzy output
211'
212
213test_expect_success 'git format-patch --show-notes does show notes' '
214 git format-patch --show-notes -1 --stdout >output &&
215 grep xyzzy output
216'
217
218for pretty in \
219 "" --pretty --pretty=raw --pretty=short --pretty=medium \
220 --pretty=full --pretty=fuller --pretty=format:%s --oneline
221do
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 '
230done
231
232test_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
238bar
239baz"
240'
241
242whitespace=" "
243cat > expect-m << EOF
244commit bd1753200303d0a0344be813e504253b3d98e74d
245Author: A U Thor <author@example.com>
246Date: Thu Apr 7 15:17:13 2005 -0700
247
248 5th
249
250Notes:
251 spam
252$whitespace
253 foo
254 bar
255 baz
256EOF
257
258printf "\n" >> expect-m
259cat expect-F >> expect-m
260
261test_expect_success 'show -m notes' '
262 git log -4 > output &&
263 test_cmp expect-m output
264'
265
266test_expect_success 'remove note with add -f -F /dev/null (setup)' '
267 git notes add -f -F /dev/null
268'
269
270cat > expect-rm-F << EOF
271commit bd1753200303d0a0344be813e504253b3d98e74d
272Author: A U Thor <author@example.com>
273Date: Thu Apr 7 15:17:13 2005 -0700
274
275 5th
276EOF
277
278printf "\n" >> expect-rm-F
279cat expect-F >> expect-rm-F
280
281test_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
285'
286
287test_expect_success 'do not create empty note with -m "" (setup)' '
288 git notes add -m ""
289'
290
291test_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
295'
296
297cat > expect-combine_m_and_F << EOF
298foo
299
300xyzzy
301
302bar
303
304zyxxy
305
306baz
307EOF
308
309test_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
315'
316
317test_expect_success 'remove note with "git notes remove" (setup)' '
318 git notes remove HEAD^ &&
319 git notes remove
320'
321
322cat > expect-rm-remove << EOF
323commit bd1753200303d0a0344be813e504253b3d98e74d
324Author: A U Thor <author@example.com>
325Date: Thu Apr 7 15:17:13 2005 -0700
326
327 5th
328
329commit 15023535574ded8b1a89052b32673f84cf9582b8
330Author: A U Thor <author@example.com>
331Date: Thu Apr 7 15:16:13 2005 -0700
332
333 4th
334EOF
335
336printf "\n" >> expect-rm-remove
337cat expect-multiline >> expect-rm-remove
338
339test_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^
343'
344
345cat > expect << EOF
346c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
347c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
348EOF
349
350test_expect_success 'list notes with "git notes list"' '
351 git notes list > output &&
352 test_cmp expect output
353'
354
355test_expect_success 'list notes with "git notes"' '
356 git notes > output &&
357 test_cmp expect output
358'
359
360cat > expect << EOF
361c18dc024e14f08d18d14eea0d747ff692d66d6a3
362EOF
363
364test_expect_success 'list specific note with "git notes list <object>"' '
365 git notes list HEAD^^ > output &&
366 test_cmp expect output
367'
368
369cat > expect << EOF
370EOF
371
372test_expect_success 'listing non-existing notes fails' '
373 test_must_fail git notes list HEAD > output &&
374 test_cmp expect output
375'
376
377cat > expect << EOF
378Initial set of notes
379
380More notes appended with git notes append
381EOF
382
383test_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
388'
389
390cat > expect_list << EOF
391c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
392c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
3934b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
394EOF
395
396test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
397 git notes list > output &&
398 test_cmp expect_list output
399'
400
401test_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
405'
406
407test_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
411
412More notes appended with git notes append" &&
413 git notes show > output &&
414 test_cmp expect output
415'
416
417test_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
422'
423
424test_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"
430'
431
432cat > expect-other << EOF
433commit 387a89921c73d7ed72cd94d179c1c7048ca47756
434Author: A U Thor <author@example.com>
435Date: Thu Apr 7 15:18:13 2005 -0700
436
437 6th
438
439Notes (other):
440 other note
441EOF
442
443cat > expect-not-other << EOF
444commit 387a89921c73d7ed72cd94d179c1c7048ca47756
445Author: A U Thor <author@example.com>
446Date: Thu Apr 7 15:18:13 2005 -0700
447
448 6th
449EOF
450
451test_expect_success 'Do not show note on other ref by default' '
452 git log -1 > output &&
453 test_cmp expect-not-other output
454'
455
456test_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
459'
460
461test_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
465'
466
467test_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
470'
471
472cat > expect-both << EOF
473commit 387a89921c73d7ed72cd94d179c1c7048ca47756
474Author: A U Thor <author@example.com>
475Date: Thu Apr 7 15:18:13 2005 -0700
476
477 6th
478
479Notes:
480 order test
481
482Notes (other):
483 other note
484
485commit bd1753200303d0a0344be813e504253b3d98e74d
486Author: A U Thor <author@example.com>
487Date: Thu Apr 7 15:17:13 2005 -0700
488
489 5th
490
491Notes:
492 replacement for deleted note
493EOF
494
495test_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
503'
504
505test_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
510'
511
512test_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
518'
519
520cat > expect-both-reversed << EOF
521commit 387a89921c73d7ed72cd94d179c1c7048ca47756
522Author: A U Thor <author@example.com>
523Date: Thu Apr 7 15:18:13 2005 -0700
524
525 6th
526
527Notes (other):
528 other note
529
530Notes:
531 order test
532EOF
533
534test_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
540'
541
542test_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
548'
549
550cat > expect-none << EOF
551commit 387a89921c73d7ed72cd94d179c1c7048ca47756
552Author: A U Thor <author@example.com>
553Date: Thu Apr 7 15:18:13 2005 -0700
554
555 6th
556
557commit bd1753200303d0a0344be813e504253b3d98e74d
558Author: A U Thor <author@example.com>
559Date: Thu Apr 7 15:17:13 2005 -0700
560
561 5th
562EOF
563
564test_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
568'
569
570test_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
573'
574
575cat > expect-commits << EOF
576commit 387a89921c73d7ed72cd94d179c1c7048ca47756
577Author: A U Thor <author@example.com>
578Date: Thu Apr 7 15:18:13 2005 -0700
579
580 6th
581
582Notes:
583 order test
584EOF
585
586test_expect_success '--no-standard-notes' '
587 git log --no-standard-notes --show-notes=commits -1 > output &&
588 test_cmp expect-commits output
589'
590
591test_expect_success '--standard-notes' '
592 git log --no-standard-notes --show-notes=commits \
593 --standard-notes -2 > output &&
594 test_cmp expect-both output
595'
596
597test_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
601'
602
603test_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
619'
620
621cat > expect << EOF
622commit 2ede89468182a62d0bde2583c736089bcf7d7e92
623Author: A U Thor <author@example.com>
624Date: Thu Apr 7 15:19:13 2005 -0700
625
626 7th
627
628Notes (other):
629 other note
630EOF
631
632test_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^)"
641'
642
643test_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
650'
651
652cat > expect << EOF
653commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
654Author: A U Thor <author@example.com>
655Date: Thu Apr 7 15:21:13 2005 -0700
656
657 9th
658
659Notes (other):
660 yet another note
661EOF
662
663test_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
671'
672
673test_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
680'
681
682cat > expect << EOF
683commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
684Author: A U Thor <author@example.com>
685Date: Thu Apr 7 15:21:13 2005 -0700
686
687 9th
688
689Notes (other):
690 yet another note
691$whitespace
692 yet another note
693EOF
694
695test_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
699'
700
701cat > expect << EOF
702commit ffed603236bfa3891c49644257a83598afe8ae5a
703Author: A U Thor <author@example.com>
704Date: Thu Apr 7 15:22:13 2005 -0700
705
706 10th
707
708Notes (other):
709 other note
710EOF
711
712test_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
716'
717
718cat > expect << EOF
719commit ffed603236bfa3891c49644257a83598afe8ae5a
720Author: A U Thor <author@example.com>
721Date: Thu Apr 7 15:22:13 2005 -0700
722
723 10th
724
725Notes (other):
726 other note
727$whitespace
728 yet another note
729EOF
730
731test_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
735'
736
737cat > expect << EOF
738commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
739Author: A U Thor <author@example.com>
740Date: Thu Apr 7 15:23:13 2005 -0700
741
742 11th
743
744Notes (other):
745 other note
746$whitespace
747 yet another note
748EOF
749
750test_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^)"
759'
760
761test_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^)"
766'
767
768cat > expect << EOF
769commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
770Author: A U Thor <author@example.com>
771Date: Thu Apr 7 15:23:13 2005 -0700
772
773 11th
774
775Notes (other):
776 yet another note
777$whitespace
778 yet another note
779EOF
780
781test_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)"
786'
787
788test_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
798'
799
800cat > expect << EOF
801commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
802Author: A U Thor <author@example.com>
803Date: Thu Apr 7 15:25:13 2005 -0700
804
805 13th
806
807Notes (other):
808 yet another note
809$whitespace
810 yet another note
811
812commit 7038787dfe22a14c3867ce816dbba39845359719
813Author: A U Thor <author@example.com>
814Date: Thu Apr 7 15:24:13 2005 -0700
815
816 12th
817
818Notes (other):
819 other note
820$whitespace
821 yet another note
822EOF
823
824test_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)"
832'
833
834cat > expect << EOF
835commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
836Author: A U Thor <author@example.com>
837Date: Thu Apr 7 15:27:13 2005 -0700
838
839 15th
840
841commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
842Author: A U Thor <author@example.com>
843Date: Thu Apr 7 15:26:13 2005 -0700
844
845 14th
846EOF
847
848test_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
856'
857
858cat > expect << EOF
859commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
860Author: A U Thor <author@example.com>
861Date: Thu Apr 7 15:27:13 2005 -0700
862
863 15th
864
865Notes (other):
866 yet another note
867$whitespace
868 yet another note
869
870commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
871Author: A U Thor <author@example.com>
872Date: Thu Apr 7 15:26:13 2005 -0700
873
874 14th
875
876Notes (other):
877 other note
878$whitespace
879 yet another note
880EOF
881
882test_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
890'
891
892test_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
898'
899
900cat > expect << EOF
901commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
902Author: A U Thor <author@example.com>
903Date: Thu Apr 7 15:27:13 2005 -0700
904
905 15th
906
907Notes (other):
908 a fresh note
909EOF
910
911test_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
917'
918
919test_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
925'
926
927cat > expect << EOF
928commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
929Author: A U Thor <author@example.com>
930Date: Thu Apr 7 15:27:13 2005 -0700
931
932 15th
933
934Notes (other):
935 a fresh note
936 another fresh note
937EOF
938
939test_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
946'
947
948cat > expect << EOF
949commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
950Author: A U Thor <author@example.com>
951Date: Thu Apr 7 15:27:13 2005 -0700
952
953 15th
954
955Notes (other):
956 a fresh note
957 another fresh note
958 append 1
959 append 2
960EOF
961
962test_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
970'
971
972test_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
978'
979
980cat > expect << EOF
981commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
982Author: A U Thor <author@example.com>
983Date: Thu Apr 7 15:27:13 2005 -0700
984
985 15th
986
987Notes (other):
988 replacement note 1
989EOF
990
991test_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
997'
998
999cat > expect << EOF
1000commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1001Author: A U Thor <author@example.com>
1002Date: Thu Apr 7 15:27:13 2005 -0700
1003
1004 15th
1005
1006Notes (other):
1007 replacement note 2
1008EOF
1009
1010test_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
1019'
1020
1021test_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
1028'
1029test_done