patch-delta: handle truncated copy parameters
[git.git] / t / t3301-notes.sh
blob84bbf88cf9d0cf8e2887abc6ef3a4c597ba4aa3a
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test commit notes'
8 . ./test-lib.sh
10 write_script fake_editor <<\EOF
11 echo "$MSG" >"$1"
12 echo "$MSG" >&2
13 EOF
14 GIT_EDITOR=./fake_editor
15 export GIT_EDITOR
17 indent=" "
19 test_expect_success 'cannot annotate non-existing HEAD' '
20 test_must_fail env MSG=3 git notes add
23 test_expect_success 'setup' '
24 test_commit 1st &&
25 test_commit 2nd
28 test_expect_success 'need valid notes ref' '
29 test_must_fail env MSG=1 GIT_NOTES_REF=/ git notes show &&
30 test_must_fail env MSG=2 GIT_NOTES_REF=/ git notes show
33 test_expect_success 'refusing to add notes in refs/heads/' '
34 test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add
37 test_expect_success 'refusing to edit notes in refs/remotes/' '
38 test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit
41 # 1 indicates caught gracefully by die, 128 means git-show barked
42 test_expect_success 'handle empty notes gracefully' '
43 test_expect_code 1 git notes show
46 test_expect_success 'show non-existent notes entry with %N' '
47 test_write_lines A B >expect &&
48 git show -s --format="A%n%NB" >actual &&
49 test_cmp expect actual
52 test_expect_success 'create notes' '
53 MSG=b4 git notes add &&
54 test_path_is_missing .git/NOTES_EDITMSG &&
55 git ls-tree -r refs/notes/commits >actual &&
56 test_line_count = 1 actual &&
57 test "b4" = "$(git notes show)" &&
58 git show HEAD^ &&
59 test_must_fail git notes show HEAD^
62 test_expect_success 'show notes entry with %N' '
63 test_write_lines A b4 B >expect &&
64 git show -s --format="A%n%NB" >actual &&
65 test_cmp expect actual
68 test_expect_success 'create reflog entry' '
69 cat <<-EOF >expect &&
70 a1d8fa6 refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
71 EOF
72 git reflog show refs/notes/commits >actual &&
73 test_cmp expect actual
76 test_expect_success 'edit existing notes' '
77 MSG=b3 git notes edit &&
78 test_path_is_missing .git/NOTES_EDITMSG &&
79 git ls-tree -r refs/notes/commits >actual &&
80 test_line_count = 1 actual &&
81 test "b3" = "$(git notes show)" &&
82 git show HEAD^ &&
83 test_must_fail git notes show HEAD^
86 test_expect_success 'show notes from treeish' '
87 test "b3" = "$(git notes --ref commits^{tree} show)" &&
88 test "b4" = "$(git notes --ref commits@{1} show)"
91 test_expect_success 'cannot edit notes from non-ref' '
92 test_must_fail git notes --ref commits^{tree} edit &&
93 test_must_fail git notes --ref commits@{1} edit
96 test_expect_success 'cannot "git notes add -m" where notes already exists' '
97 test_must_fail git notes add -m "b2" &&
98 test_path_is_missing .git/NOTES_EDITMSG &&
99 git ls-tree -r refs/notes/commits >actual &&
100 test_line_count = 1 actual &&
101 test "b3" = "$(git notes show)" &&
102 git show HEAD^ &&
103 test_must_fail git notes show HEAD^
106 test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
107 git notes add -f -m "b1" &&
108 test_path_is_missing .git/NOTES_EDITMSG &&
109 git ls-tree -r refs/notes/commits >actual &&
110 test_line_count = 1 actual &&
111 test "b1" = "$(git notes show)" &&
112 git show HEAD^ &&
113 test_must_fail git notes show HEAD^
116 test_expect_success 'add w/no options on existing note morphs into edit' '
117 MSG=b2 git notes add &&
118 test_path_is_missing .git/NOTES_EDITMSG &&
119 git ls-tree -r refs/notes/commits >actual &&
120 test_line_count = 1 actual &&
121 test "b2" = "$(git notes show)" &&
122 git show HEAD^ &&
123 test_must_fail git notes show HEAD^
126 test_expect_success 'can overwrite existing note with "git notes add -f"' '
127 MSG=b1 git notes add -f &&
128 test_path_is_missing .git/NOTES_EDITMSG &&
129 git ls-tree -r refs/notes/commits >actual &&
130 test_line_count = 1 actual &&
131 test "b1" = "$(git notes show)" &&
132 git show HEAD^ &&
133 test_must_fail git notes show HEAD^
136 test_expect_success 'show notes' '
137 cat >expect <<-EOF &&
138 commit 7a4ca6ee52a974a66cbaa78e33214535dff1d691
139 Author: A U Thor <author@example.com>
140 Date: Thu Apr 7 15:14:13 2005 -0700
142 ${indent}2nd
144 Notes:
145 ${indent}b1
147 ! (git cat-file commit HEAD | grep b1) &&
148 git log -1 >actual &&
149 test_cmp expect actual
152 test_expect_success 'show multi-line notes' '
153 test_commit 3rd &&
154 MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
155 cat >expect-multiline <<-EOF &&
156 commit d07d62e5208f22eb5695e7eb47667dc8b9860290
157 Author: A U Thor <author@example.com>
158 Date: Thu Apr 7 15:15:13 2005 -0700
160 ${indent}3rd
162 Notes:
163 ${indent}b3
164 ${indent}c3c3c3c3
165 ${indent}d3d3d3
168 cat expect >>expect-multiline &&
169 git log -2 >actual &&
170 test_cmp expect-multiline actual
173 test_expect_success 'show -F notes' '
174 test_commit 4th &&
175 echo "xyzzy" >note5 &&
176 git notes add -F note5 &&
177 cat >expect-F <<-EOF &&
178 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
179 Author: A U Thor <author@example.com>
180 Date: Thu Apr 7 15:16:13 2005 -0700
182 ${indent}4th
184 Notes:
185 ${indent}xyzzy
188 cat expect-multiline >>expect-F &&
189 git log -3 >actual &&
190 test_cmp expect-F actual
193 test_expect_success 'Re-adding -F notes without -f fails' '
194 echo "zyxxy" >note5 &&
195 test_must_fail git notes add -F note5 &&
196 git log -3 >actual &&
197 test_cmp expect-F actual
200 test_expect_success 'git log --pretty=raw does not show notes' '
201 cat >expect <<-EOF &&
202 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
203 tree 05ac65288c4c4b3b709a020ae94b2ece2f2201ae
204 parent d07d62e5208f22eb5695e7eb47667dc8b9860290
205 author A U Thor <author@example.com> 1112912173 -0700
206 committer C O Mitter <committer@example.com> 1112912173 -0700
208 ${indent}4th
210 git log -1 --pretty=raw >actual &&
211 test_cmp expect actual
214 test_expect_success 'git log --show-notes' '
215 cat >>expect <<-EOF &&
217 Notes:
218 ${indent}xyzzy
220 git log -1 --pretty=raw --show-notes >actual &&
221 test_cmp expect actual
224 test_expect_success 'git log --no-notes' '
225 git log -1 --no-notes >actual &&
226 ! grep xyzzy actual
229 test_expect_success 'git format-patch does not show notes' '
230 git format-patch -1 --stdout >actual &&
231 ! grep xyzzy actual
234 test_expect_success 'git format-patch --show-notes does show notes' '
235 git format-patch --show-notes -1 --stdout >actual &&
236 grep xyzzy actual
239 for pretty in \
240 "" --pretty --pretty=raw --pretty=short --pretty=medium \
241 --pretty=full --pretty=fuller --pretty=format:%s --oneline
243 case "$pretty" in
244 "") p= not= negate="" ;;
245 ?*) p="$pretty" not=" not" negate="!" ;;
246 esac
247 test_expect_success "git show $pretty does$not show notes" '
248 git show $p >actual &&
249 eval "$negate grep xyzzy actual"
251 done
253 test_expect_success 'setup alternate notes ref' '
254 git notes --ref=alternate add -m alternate
257 test_expect_success 'git log --notes shows default notes' '
258 git log -1 --notes >actual &&
259 grep xyzzy actual &&
260 ! grep alternate actual
263 test_expect_success 'git log --notes=X shows only X' '
264 git log -1 --notes=alternate >actual &&
265 ! grep xyzzy actual &&
266 grep alternate actual
269 test_expect_success 'git log --notes --notes=X shows both' '
270 git log -1 --notes --notes=alternate >actual &&
271 grep xyzzy actual &&
272 grep alternate actual
275 test_expect_success 'git log --no-notes resets default state' '
276 git log -1 --notes --notes=alternate \
277 --no-notes --notes=alternate \
278 >actual &&
279 ! grep xyzzy actual &&
280 grep alternate actual
283 test_expect_success 'git log --no-notes resets ref list' '
284 git log -1 --notes --notes=alternate \
285 --no-notes --notes \
286 >actual &&
287 grep xyzzy actual &&
288 ! grep alternate actual
291 test_expect_success 'show -m notes' '
292 test_commit 5th &&
293 git notes add -m spam -m "foo${LF}bar${LF}baz" &&
294 cat >expect-m <<-EOF &&
295 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
296 Author: A U Thor <author@example.com>
297 Date: Thu Apr 7 15:17:13 2005 -0700
299 ${indent}5th
301 Notes:
302 ${indent}spam
303 ${indent}
304 ${indent}foo
305 ${indent}bar
306 ${indent}baz
309 cat expect-F >>expect-m &&
310 git log -4 >actual &&
311 test_cmp expect-m actual
314 test_expect_success 'remove note with add -f -F /dev/null' '
315 git notes add -f -F /dev/null &&
316 cat >expect-rm-F <<-EOF &&
317 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
318 Author: A U Thor <author@example.com>
319 Date: Thu Apr 7 15:17:13 2005 -0700
321 ${indent}5th
324 cat expect-F >>expect-rm-F &&
325 git log -4 >actual &&
326 test_cmp expect-rm-F actual &&
327 test_must_fail git notes show
330 test_expect_success 'do not create empty note with -m ""' '
331 git notes add -m "" &&
332 git log -4 >actual &&
333 test_cmp expect-rm-F actual &&
334 test_must_fail git notes show
337 test_expect_success 'create note with combination of -m and -F' '
338 cat >expect-combine_m_and_F <<-EOF &&
341 xyzzy
345 zyxxy
349 echo "xyzzy" >note_a &&
350 echo "zyxxy" >note_b &&
351 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
352 git notes show >actual &&
353 test_cmp expect-combine_m_and_F actual
356 test_expect_success 'remove note with "git notes remove"' '
357 git notes remove HEAD^ &&
358 git notes remove &&
359 cat >expect-rm-remove <<-EOF &&
360 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
361 Author: A U Thor <author@example.com>
362 Date: Thu Apr 7 15:17:13 2005 -0700
364 ${indent}5th
366 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
367 Author: A U Thor <author@example.com>
368 Date: Thu Apr 7 15:16:13 2005 -0700
370 ${indent}4th
373 cat expect-multiline >>expect-rm-remove &&
374 git log -4 >actual &&
375 test_cmp expect-rm-remove actual &&
376 test_must_fail git notes show HEAD^
379 test_expect_success 'removing non-existing note should not create new commit' '
380 git rev-parse --verify refs/notes/commits >before_commit &&
381 test_must_fail git notes remove HEAD^ &&
382 git rev-parse --verify refs/notes/commits >after_commit &&
383 test_cmp before_commit after_commit
386 test_expect_success 'removing more than one' '
387 before=$(git rev-parse --verify refs/notes/commits) &&
388 test_when_finished "git update-ref refs/notes/commits $before" &&
390 # We have only two -- add another and make sure it stays
391 git notes add -m "extra" &&
392 git notes list HEAD >after-removal-expect &&
393 git notes remove HEAD^^ HEAD^^^ &&
394 git notes list | sed -e "s/ .*//" >actual &&
395 test_cmp after-removal-expect actual
398 test_expect_success 'removing is atomic' '
399 before=$(git rev-parse --verify refs/notes/commits) &&
400 test_when_finished "git update-ref refs/notes/commits $before" &&
401 test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
402 after=$(git rev-parse --verify refs/notes/commits) &&
403 test "$before" = "$after"
406 test_expect_success 'removing with --ignore-missing' '
407 before=$(git rev-parse --verify refs/notes/commits) &&
408 test_when_finished "git update-ref refs/notes/commits $before" &&
410 # We have only two -- add another and make sure it stays
411 git notes add -m "extra" &&
412 git notes list HEAD >after-removal-expect &&
413 git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
414 git notes list | sed -e "s/ .*//" >actual &&
415 test_cmp after-removal-expect actual
418 test_expect_success 'removing with --ignore-missing but bogus ref' '
419 before=$(git rev-parse --verify refs/notes/commits) &&
420 test_when_finished "git update-ref refs/notes/commits $before" &&
421 test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
422 after=$(git rev-parse --verify refs/notes/commits) &&
423 test "$before" = "$after"
426 test_expect_success 'remove reads from --stdin' '
427 before=$(git rev-parse --verify refs/notes/commits) &&
428 test_when_finished "git update-ref refs/notes/commits $before" &&
430 # We have only two -- add another and make sure it stays
431 git notes add -m "extra" &&
432 git notes list HEAD >after-removal-expect &&
433 git rev-parse HEAD^^ HEAD^^^ >input &&
434 git notes remove --stdin <input &&
435 git notes list | sed -e "s/ .*//" >actual &&
436 test_cmp after-removal-expect actual
439 test_expect_success 'remove --stdin is also atomic' '
440 before=$(git rev-parse --verify refs/notes/commits) &&
441 test_when_finished "git update-ref refs/notes/commits $before" &&
442 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
443 test_must_fail git notes remove --stdin <input &&
444 after=$(git rev-parse --verify refs/notes/commits) &&
445 test "$before" = "$after"
448 test_expect_success 'removing with --stdin --ignore-missing' '
449 before=$(git rev-parse --verify refs/notes/commits) &&
450 test_when_finished "git update-ref refs/notes/commits $before" &&
452 # We have only two -- add another and make sure it stays
453 git notes add -m "extra" &&
454 git notes list HEAD >after-removal-expect &&
455 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
456 git notes remove --ignore-missing --stdin <input &&
457 git notes list | sed -e "s/ .*//" >actual &&
458 test_cmp after-removal-expect actual
461 test_expect_success 'list notes with "git notes list"' '
462 cat >expect <<-EOF &&
463 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
464 c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
466 git notes list >actual &&
467 test_cmp expect actual
470 test_expect_success 'list notes with "git notes"' '
471 git notes >actual &&
472 test_cmp expect actual
475 test_expect_success 'list specific note with "git notes list <object>"' '
476 cat >expect <<-EOF &&
477 c18dc024e14f08d18d14eea0d747ff692d66d6a3
479 git notes list HEAD^^ >actual &&
480 test_cmp expect actual
483 test_expect_success 'listing non-existing notes fails' '
484 test_must_fail git notes list HEAD >actual &&
485 test_must_be_empty actual
488 test_expect_success 'append to existing note with "git notes append"' '
489 cat >expect <<-EOF &&
490 Initial set of notes
492 More notes appended with git notes append
494 git notes add -m "Initial set of notes" &&
495 git notes append -m "More notes appended with git notes append" &&
496 git notes show >actual &&
497 test_cmp expect actual
500 test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
501 cat >expect_list <<-EOF &&
502 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
503 4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
504 c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
506 git notes list >actual &&
507 test_cmp expect_list actual
510 test_expect_success 'appending empty string does not change existing note' '
511 git notes append -m "" &&
512 git notes show >actual &&
513 test_cmp expect actual
516 test_expect_success 'git notes append == add when there is no existing note' '
517 git notes remove HEAD &&
518 test_must_fail git notes list HEAD &&
519 git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
520 git notes show >actual &&
521 test_cmp expect actual
524 test_expect_success 'appending empty string to non-existing note does not create note' '
525 git notes remove HEAD &&
526 test_must_fail git notes list HEAD &&
527 git notes append -m "" &&
528 test_must_fail git notes list HEAD
531 test_expect_success 'create other note on a different notes ref (setup)' '
532 test_commit 6th &&
533 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
534 cat >expect-not-other <<-EOF &&
535 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
536 Author: A U Thor <author@example.com>
537 Date: Thu Apr 7 15:18:13 2005 -0700
539 ${indent}6th
541 cp expect-not-other expect-other &&
542 cat >>expect-other <<-EOF
544 Notes (other):
545 ${indent}other note
549 test_expect_success 'Do not show note on other ref by default' '
550 git log -1 >actual &&
551 test_cmp expect-not-other actual
554 test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
555 GIT_NOTES_REF="refs/notes/other" git log -1 >actual &&
556 test_cmp expect-other actual
559 test_expect_success 'Do show note when ref is given in core.notesRef config' '
560 test_config core.notesRef "refs/notes/other" &&
561 git log -1 >actual &&
562 test_cmp expect-other actual
565 test_expect_success 'Do not show note when core.notesRef is overridden' '
566 test_config core.notesRef "refs/notes/other" &&
567 GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual &&
568 test_cmp expect-not-other actual
571 test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
572 cat >expect-both <<-EOF &&
573 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
574 Author: A U Thor <author@example.com>
575 Date: Thu Apr 7 15:18:13 2005 -0700
577 ${indent}6th
579 Notes:
580 ${indent}order test
582 Notes (other):
583 ${indent}other note
585 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
586 Author: A U Thor <author@example.com>
587 Date: Thu Apr 7 15:17:13 2005 -0700
589 ${indent}5th
591 Notes:
592 ${indent}replacement for deleted note
594 GIT_NOTES_REF=refs/notes/commits git notes add \
595 -m"replacement for deleted note" HEAD^ &&
596 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
597 test_unconfig core.notesRef &&
598 test_config notes.displayRef "refs/notes/*" &&
599 git log -2 >actual &&
600 test_cmp expect-both actual
603 test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
604 test_config core.notesRef refs/notes/commits &&
605 test_config notes.displayRef refs/notes/other &&
606 git log -2 >actual &&
607 test_cmp expect-both actual
610 test_expect_success 'notes.displayRef can be given more than once' '
611 test_unconfig core.notesRef &&
612 test_config notes.displayRef refs/notes/commits &&
613 git config --add notes.displayRef refs/notes/other &&
614 git log -2 >actual &&
615 test_cmp expect-both actual
618 test_expect_success 'notes.displayRef respects order' '
619 cat >expect-both-reversed <<-EOF &&
620 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
621 Author: A U Thor <author@example.com>
622 Date: Thu Apr 7 15:18:13 2005 -0700
624 ${indent}6th
626 Notes (other):
627 ${indent}other note
629 Notes:
630 ${indent}order test
632 test_config core.notesRef refs/notes/other &&
633 test_config notes.displayRef refs/notes/commits &&
634 git log -1 >actual &&
635 test_cmp expect-both-reversed actual
638 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
639 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
640 git log -2 >actual &&
641 test_cmp expect-both actual
644 test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
645 cat >expect-none <<-EOF &&
646 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
647 Author: A U Thor <author@example.com>
648 Date: Thu Apr 7 15:18:13 2005 -0700
650 ${indent}6th
652 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
653 Author: A U Thor <author@example.com>
654 Date: Thu Apr 7 15:17:13 2005 -0700
656 ${indent}5th
658 test_config notes.displayRef "refs/notes/*" &&
659 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual &&
660 test_cmp expect-none actual
663 test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
664 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual &&
665 test_cmp expect-both actual
668 test_expect_success '--no-standard-notes' '
669 cat >expect-commits <<-EOF &&
670 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
671 Author: A U Thor <author@example.com>
672 Date: Thu Apr 7 15:18:13 2005 -0700
674 ${indent}6th
676 Notes:
677 ${indent}order test
679 git log --no-standard-notes --show-notes=commits -1 >actual &&
680 test_cmp expect-commits actual
683 test_expect_success '--standard-notes' '
684 test_config notes.displayRef "refs/notes/*" &&
685 git log --no-standard-notes --show-notes=commits \
686 --standard-notes -2 >actual &&
687 test_cmp expect-both actual
690 test_expect_success '--show-notes=ref accumulates' '
691 git log --show-notes=other --show-notes=commits \
692 --no-standard-notes -1 >actual &&
693 test_cmp expect-both-reversed actual
696 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
697 test_config core.notesRef refs/notes/other &&
698 echo "Note on a tree" >expect &&
699 git notes add -m "Note on a tree" HEAD: &&
700 git notes show HEAD: >actual &&
701 test_cmp expect actual &&
702 echo "Note on a blob" >expect &&
703 filename=$(git ls-tree --name-only HEAD | head -n1) &&
704 git notes add -m "Note on a blob" HEAD:$filename &&
705 git notes show HEAD:$filename >actual &&
706 test_cmp expect actual &&
707 echo "Note on a tag" >expect &&
708 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
709 git notes add -m "Note on a tag" foobar &&
710 git notes show foobar >actual &&
711 test_cmp expect actual
714 test_expect_success 'create note from other note with "git notes add -C"' '
715 cat >expect <<-EOF &&
716 commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c
717 Author: A U Thor <author@example.com>
718 Date: Thu Apr 7 15:19:13 2005 -0700
720 ${indent}7th
722 Notes:
723 ${indent}order test
725 test_commit 7th &&
726 git notes add -C $(git notes list HEAD^) &&
727 git log -1 >actual &&
728 test_cmp expect actual &&
729 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
732 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
733 test_commit 8th &&
734 test_must_fail git notes add -C deadbeef &&
735 test_must_fail git notes list HEAD
738 test_expect_success 'create note from non-blob with "git notes add -C" fails' '
739 commit=$(git rev-parse --verify HEAD) &&
740 tree=$(git rev-parse --verify HEAD:) &&
741 test_must_fail git notes add -C $commit &&
742 test_must_fail git notes add -C $tree &&
743 test_must_fail git notes list HEAD
746 test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
747 cat >expect <<-EOF &&
748 commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf
749 Author: A U Thor <author@example.com>
750 Date: Thu Apr 7 15:20:13 2005 -0700
752 ${indent}8th
754 Notes:
755 ${indent}This is a blob object
757 blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
758 git notes add -C $blob &&
759 git log -1 >actual &&
760 test_cmp expect actual &&
761 test "$(git notes list HEAD)" = "$blob"
764 test_expect_success 'create note from other note with "git notes add -c"' '
765 cat >expect <<-EOF &&
766 commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
767 Author: A U Thor <author@example.com>
768 Date: Thu Apr 7 15:21:13 2005 -0700
770 ${indent}9th
772 Notes:
773 ${indent}yet another note
775 test_commit 9th &&
776 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
777 git log -1 >actual &&
778 test_cmp expect actual
781 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
782 test_commit 10th &&
783 test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
784 test_must_fail git notes list HEAD
787 test_expect_success 'append to note from other note with "git notes append -C"' '
788 cat >expect <<-EOF &&
789 commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
790 Author: A U Thor <author@example.com>
791 Date: Thu Apr 7 15:21:13 2005 -0700
793 ${indent}9th
795 Notes:
796 ${indent}yet another note
797 ${indent}
798 ${indent}yet another note
800 git notes append -C $(git notes list HEAD^) HEAD^ &&
801 git log -1 HEAD^ >actual &&
802 test_cmp expect actual
805 test_expect_success 'create note from other note with "git notes append -c"' '
806 cat >expect <<-EOF &&
807 commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
808 Author: A U Thor <author@example.com>
809 Date: Thu Apr 7 15:22:13 2005 -0700
811 ${indent}10th
813 Notes:
814 ${indent}other note
816 MSG="other note" git notes append -c $(git notes list HEAD^) &&
817 git log -1 >actual &&
818 test_cmp expect actual
821 test_expect_success 'append to note from other note with "git notes append -c"' '
822 cat >expect <<-EOF &&
823 commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
824 Author: A U Thor <author@example.com>
825 Date: Thu Apr 7 15:22:13 2005 -0700
827 ${indent}10th
829 Notes:
830 ${indent}other note
831 ${indent}
832 ${indent}yet another note
834 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
835 git log -1 >actual &&
836 test_cmp expect actual
839 test_expect_success 'copy note with "git notes copy"' '
840 cat >expect <<-EOF &&
841 commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
842 Author: A U Thor <author@example.com>
843 Date: Thu Apr 7 15:23:13 2005 -0700
845 ${indent}11th
847 Notes:
848 ${indent}other note
849 ${indent}
850 ${indent}yet another note
852 test_commit 11th &&
853 git notes copy HEAD^ HEAD &&
854 git log -1 >actual &&
855 test_cmp expect actual &&
856 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
859 test_expect_success 'prevent overwrite with "git notes copy"' '
860 test_must_fail git notes copy HEAD~2 HEAD &&
861 git log -1 >actual &&
862 test_cmp expect actual &&
863 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
866 test_expect_success 'allow overwrite with "git notes copy -f"' '
867 cat >expect <<-EOF &&
868 commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
869 Author: A U Thor <author@example.com>
870 Date: Thu Apr 7 15:23:13 2005 -0700
872 ${indent}11th
874 Notes:
875 ${indent}yet another note
876 ${indent}
877 ${indent}yet another note
879 git notes copy -f HEAD~2 HEAD &&
880 git log -1 >actual &&
881 test_cmp expect actual &&
882 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
885 test_expect_success 'cannot copy note from object without notes' '
886 test_commit 12th &&
887 test_commit 13th &&
888 test_must_fail git notes copy HEAD^ HEAD
891 test_expect_success 'git notes copy --stdin' '
892 cat >expect <<-EOF &&
893 commit e871aa61182b1d95d0a6fb75445d891722863b6b
894 Author: A U Thor <author@example.com>
895 Date: Thu Apr 7 15:25:13 2005 -0700
897 ${indent}13th
899 Notes:
900 ${indent}yet another note
901 ${indent}
902 ${indent}yet another note
904 commit 65e263ded02ae4e8839bc151095113737579dc12
905 Author: A U Thor <author@example.com>
906 Date: Thu Apr 7 15:24:13 2005 -0700
908 ${indent}12th
910 Notes:
911 ${indent}other note
912 ${indent}
913 ${indent}yet another note
915 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
916 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
917 git notes copy --stdin &&
918 git log -2 >actual &&
919 test_cmp expect actual &&
920 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
921 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
924 test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
925 cat >expect <<-EOF &&
926 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
927 Author: A U Thor <author@example.com>
928 Date: Thu Apr 7 15:27:13 2005 -0700
930 ${indent}15th
932 commit 07c85d77059393ed0154b8c96906547a59dfcddd
933 Author: A U Thor <author@example.com>
934 Date: Thu Apr 7 15:26:13 2005 -0700
936 ${indent}14th
938 test_commit 14th &&
939 test_commit 15th &&
940 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
941 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
942 git notes copy --for-rewrite=foo &&
943 git log -2 >actual &&
944 test_cmp expect actual
947 test_expect_success 'git notes copy --for-rewrite (enabled)' '
948 cat >expect <<-EOF &&
949 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
950 Author: A U Thor <author@example.com>
951 Date: Thu Apr 7 15:27:13 2005 -0700
953 ${indent}15th
955 Notes:
956 ${indent}yet another note
957 ${indent}
958 ${indent}yet another note
960 commit 07c85d77059393ed0154b8c96906547a59dfcddd
961 Author: A U Thor <author@example.com>
962 Date: Thu Apr 7 15:26:13 2005 -0700
964 ${indent}14th
966 Notes:
967 ${indent}other note
968 ${indent}
969 ${indent}yet another note
971 test_config notes.rewriteMode overwrite &&
972 test_config notes.rewriteRef "refs/notes/*" &&
973 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) &&
974 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
975 git notes copy --for-rewrite=foo &&
976 git log -2 >actual &&
977 test_cmp expect actual
980 test_expect_success 'git notes copy --for-rewrite (disabled)' '
981 test_config notes.rewrite.bar false &&
982 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
983 git notes copy --for-rewrite=bar &&
984 git log -2 >actual &&
985 test_cmp expect actual
988 test_expect_success 'git notes copy --for-rewrite (overwrite)' '
989 cat >expect <<-EOF &&
990 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
991 Author: A U Thor <author@example.com>
992 Date: Thu Apr 7 15:27:13 2005 -0700
994 ${indent}15th
996 Notes:
997 ${indent}a fresh note
999 git notes add -f -m"a fresh note" HEAD^ &&
1000 test_config notes.rewriteMode overwrite &&
1001 test_config notes.rewriteRef "refs/notes/*" &&
1002 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1003 git notes copy --for-rewrite=foo &&
1004 git log -1 >actual &&
1005 test_cmp expect actual
1008 test_expect_success 'git notes copy --for-rewrite (ignore)' '
1009 test_config notes.rewriteMode ignore &&
1010 test_config notes.rewriteRef "refs/notes/*" &&
1011 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1012 git notes copy --for-rewrite=foo &&
1013 git log -1 >actual &&
1014 test_cmp expect actual
1017 test_expect_success 'git notes copy --for-rewrite (append)' '
1018 cat >expect <<-EOF &&
1019 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1020 Author: A U Thor <author@example.com>
1021 Date: Thu Apr 7 15:27:13 2005 -0700
1023 ${indent}15th
1025 Notes:
1026 ${indent}a fresh note
1027 ${indent}
1028 ${indent}another fresh note
1030 git notes add -f -m"another fresh note" HEAD^ &&
1031 test_config notes.rewriteMode concatenate &&
1032 test_config notes.rewriteRef "refs/notes/*" &&
1033 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1034 git notes copy --for-rewrite=foo &&
1035 git log -1 >actual &&
1036 test_cmp expect actual
1039 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1040 cat >expect <<-EOF &&
1041 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1042 Author: A U Thor <author@example.com>
1043 Date: Thu Apr 7 15:27:13 2005 -0700
1045 ${indent}15th
1047 Notes:
1048 ${indent}a fresh note
1049 ${indent}
1050 ${indent}another fresh note
1051 ${indent}
1052 ${indent}append 1
1053 ${indent}
1054 ${indent}append 2
1056 git notes add -f -m"append 1" HEAD^ &&
1057 git notes add -f -m"append 2" HEAD^^ &&
1058 test_config notes.rewriteMode concatenate &&
1059 test_config notes.rewriteRef "refs/notes/*" &&
1060 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD) &&
1061 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1062 git notes copy --for-rewrite=foo &&
1063 git log -1 >actual &&
1064 test_cmp expect actual
1067 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1068 git notes remove HEAD^ &&
1069 test_config notes.rewriteMode concatenate &&
1070 test_config notes.rewriteRef "refs/notes/*" &&
1071 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1072 git notes copy --for-rewrite=foo &&
1073 git log -1 >actual &&
1074 test_cmp expect actual
1077 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1078 cat >expect <<-EOF &&
1079 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1080 Author: A U Thor <author@example.com>
1081 Date: Thu Apr 7 15:27:13 2005 -0700
1083 ${indent}15th
1085 Notes:
1086 ${indent}replacement note 1
1088 test_config notes.rewriteMode concatenate &&
1089 test_config notes.rewriteRef "refs/notes/*" &&
1090 git notes add -f -m"replacement note 1" HEAD^ &&
1091 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1092 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1093 git log -1 >actual &&
1094 test_cmp expect actual
1097 test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1098 cat >expect <<-EOF &&
1099 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1100 Author: A U Thor <author@example.com>
1101 Date: Thu Apr 7 15:27:13 2005 -0700
1103 ${indent}15th
1105 Notes:
1106 ${indent}replacement note 2
1108 git notes add -f -m"replacement note 2" HEAD^ &&
1109 test_config notes.rewriteMode overwrite &&
1110 test_unconfig notes.rewriteRef &&
1111 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1112 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1113 git notes copy --for-rewrite=foo &&
1114 git log -1 >actual &&
1115 test_cmp expect actual
1118 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1119 git notes add -f -m"replacement note 3" HEAD^ &&
1120 test_config notes.rewriteMode overwrite &&
1121 test_config notes.rewriteRef refs/notes/other &&
1122 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1123 GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1124 git log -1 >actual &&
1125 test_cmp expect actual
1128 test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1129 test_must_fail git notes copy &&
1130 test_must_fail git notes copy one two three
1133 test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '
1134 test_unconfig core.notesRef &&
1135 sane_unset GIT_NOTES_REF &&
1136 test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master"
1139 test_expect_success 'git notes get-ref (no overrides)' '
1140 test_unconfig core.notesRef &&
1141 sane_unset GIT_NOTES_REF &&
1142 test "$(git notes get-ref)" = "refs/notes/commits"
1145 test_expect_success 'git notes get-ref (core.notesRef)' '
1146 test_config core.notesRef refs/notes/foo &&
1147 test "$(git notes get-ref)" = "refs/notes/foo"
1150 test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1151 test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1154 test_expect_success 'git notes get-ref (--ref)' '
1155 test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1158 test_expect_success 'setup testing of empty notes' '
1159 test_unconfig core.notesRef &&
1160 test_commit 16th &&
1161 empty_blob=$(git hash-object -w /dev/null) &&
1162 echo "$empty_blob" >expect_empty
1165 while read cmd
1167 test_expect_success "'git notes $cmd' removes empty note" "
1168 test_might_fail git notes remove HEAD &&
1169 MSG= git notes $cmd &&
1170 test_must_fail git notes list HEAD
1173 test_expect_success "'git notes $cmd --allow-empty' stores empty note" "
1174 test_might_fail git notes remove HEAD &&
1175 MSG= git notes $cmd --allow-empty &&
1176 git notes list HEAD >actual &&
1177 test_cmp expect_empty actual
1179 done <<\EOF
1181 add -F /dev/null
1182 add -m ""
1183 add -c "$empty_blob"
1184 add -C "$empty_blob"
1185 append
1186 append -F /dev/null
1187 append -m ""
1188 append -c "$empty_blob"
1189 append -C "$empty_blob"
1190 edit
1193 test_expect_success 'empty notes are displayed by git log' '
1194 test_commit 17th &&
1195 git log -1 >expect &&
1196 cat >>expect <<-EOF &&
1198 Notes:
1200 git notes add -C "$empty_blob" --allow-empty &&
1201 git log -1 >actual &&
1202 test_cmp expect actual
1205 test_done