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