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