revert: use strbuf to refactor the code that writes the merge message
[git/dscho.git] / t / t3301-notes.sh
blob37b96871c54037399450dd8c982d83e47dda0184
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test commit notes'
8 . ./test-lib.sh
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
19 test_expect_success 'cannot annotate non-existing HEAD' '
20 (MSG=3 && export MSG && test_must_fail git notes add)
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
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)
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)
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)
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 = $?
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^
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^
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^
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^
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
102 Notes:
106 test_expect_success 'show notes' '
107 ! (git cat-file commit HEAD | grep b1) &&
108 git log -1 > output &&
109 test_cmp expect output
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
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
129 Notes:
131 c3c3c3c3
132 d3d3d3
135 printf "\n" >> expect-multiline
136 cat expect >> expect-multiline
138 test_expect_success 'show multi-line notes' '
139 git log -2 > output &&
140 test_cmp expect-multiline output
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
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
158 Notes:
159 xyzzy
162 printf "\n" >> expect-F
163 cat expect-multiline >> expect-F
165 test_expect_success 'show -F notes' '
166 git log -3 > output &&
167 test_cmp expect-F output
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
179 test_expect_success 'git log --pretty=raw does not show notes' '
180 git log -1 --pretty=raw >output &&
181 test_cmp expect output
184 cat >>expect <<EOF
186 Notes:
187 xyzzy
189 test_expect_success 'git log --show-notes' '
190 git log -1 --pretty=raw --show-notes >output &&
191 test_cmp expect output
194 test_expect_success 'git log --no-notes' '
195 git log -1 --no-notes >output &&
196 ! grep xyzzy output
199 test_expect_success 'git format-patch does not show notes' '
200 git format-patch -1 --stdout >output &&
201 ! grep xyzzy output
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
209 for pretty in \
210 "" --pretty --pretty=raw --pretty=short --pretty=medium \
211 --pretty=full --pretty=fuller --pretty=format:%s --oneline
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"
221 done
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
230 baz"
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
241 Notes:
242 spam
243 $whitespace
249 printf "\n" >> expect-m
250 cat expect-F >> expect-m
252 test_expect_success 'show -m notes' '
253 git log -4 > output &&
254 test_cmp expect-m output
257 test_expect_success 'remove note with add -f -F /dev/null (setup)' '
258 git notes add -f -F /dev/null
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
269 printf "\n" >> expect-rm-F
270 cat expect-F >> expect-rm-F
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
278 test_expect_success 'do not create empty note with -m "" (setup)' '
279 git notes add -m ""
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
288 cat > expect-combine_m_and_F << EOF
291 xyzzy
295 zyxxy
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
308 test_expect_success 'remove note with "git notes remove" (setup)' '
309 git notes remove HEAD^ &&
310 git notes remove
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
320 commit 15023535574ded8b1a89052b32673f84cf9582b8
321 Author: A U Thor <author@example.com>
322 Date: Thu Apr 7 15:16:13 2005 -0700
327 printf "\n" >> expect-rm-remove
328 cat expect-multiline >> expect-rm-remove
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^
336 cat > expect << EOF
337 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
338 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
341 test_expect_success 'list notes with "git notes list"' '
342 git notes list > output &&
343 test_cmp expect output
346 test_expect_success 'list notes with "git notes"' '
347 git notes > output &&
348 test_cmp expect output
351 cat > expect << EOF
352 c18dc024e14f08d18d14eea0d747ff692d66d6a3
355 test_expect_success 'list specific note with "git notes list <object>"' '
356 git notes list HEAD^^ > output &&
357 test_cmp expect output
360 cat > expect << EOF
363 test_expect_success 'listing non-existing notes fails' '
364 test_must_fail git notes list HEAD > output &&
365 test_cmp expect output
368 cat > expect << EOF
369 Initial set of notes
371 More notes appended with git notes append
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
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
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
392 More notes appended with git notes append" &&
393 git notes show > output &&
394 test_cmp expect output
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
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"
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
419 Notes:
420 other note
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
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
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
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
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
452 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
453 echo "Note on a tree" > expect
454 git notes add -m "Note on a tree" HEAD: &&
455 git notes show HEAD: > actual &&
456 test_cmp expect actual &&
457 echo "Note on a blob" > expect
458 filename=$(git ls-tree --name-only HEAD | head -n1) &&
459 git notes add -m "Note on a blob" HEAD:$filename &&
460 git notes show HEAD:$filename > actual &&
461 test_cmp expect actual &&
462 echo "Note on a tag" > expect
463 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
464 git notes add -m "Note on a tag" foobar &&
465 git notes show foobar > actual &&
466 test_cmp expect actual
469 cat > expect << EOF
470 commit 2ede89468182a62d0bde2583c736089bcf7d7e92
471 Author: A U Thor <author@example.com>
472 Date: Thu Apr 7 15:19:13 2005 -0700
476 Notes:
477 other note
480 test_expect_success 'create note from other note with "git notes add -C"' '
481 : > a7 &&
482 git add a7 &&
483 test_tick &&
484 git commit -m 7th &&
485 git notes add -C $(git notes list HEAD^) &&
486 git log -1 > actual &&
487 test_cmp expect actual &&
488 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
491 test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
492 : > a8 &&
493 git add a8 &&
494 test_tick &&
495 git commit -m 8th &&
496 test_must_fail git notes add -C deadbeef &&
497 test_must_fail git notes list HEAD
500 cat > expect << EOF
501 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
502 Author: A U Thor <author@example.com>
503 Date: Thu Apr 7 15:21:13 2005 -0700
507 Notes:
508 yet another note
511 test_expect_success 'create note from other note with "git notes add -c"' '
512 : > a9 &&
513 git add a9 &&
514 test_tick &&
515 git commit -m 9th &&
516 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
517 git log -1 > actual &&
518 test_cmp expect actual
521 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
522 : > a10 &&
523 git add a10 &&
524 test_tick &&
525 git commit -m 10th &&
526 test_must_fail MSG="yet another note" git notes add -c deadbeef &&
527 test_must_fail git notes list HEAD
530 cat > expect << EOF
531 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
532 Author: A U Thor <author@example.com>
533 Date: Thu Apr 7 15:21:13 2005 -0700
537 Notes:
538 yet another note
539 $whitespace
540 yet another note
543 test_expect_success 'append to note from other note with "git notes append -C"' '
544 git notes append -C $(git notes list HEAD^) HEAD^ &&
545 git log -1 HEAD^ > actual &&
546 test_cmp expect actual
549 cat > expect << EOF
550 commit ffed603236bfa3891c49644257a83598afe8ae5a
551 Author: A U Thor <author@example.com>
552 Date: Thu Apr 7 15:22:13 2005 -0700
554 10th
556 Notes:
557 other note
560 test_expect_success 'create note from other note with "git notes append -c"' '
561 MSG="other note" git notes append -c $(git notes list HEAD^) &&
562 git log -1 > actual &&
563 test_cmp expect actual
566 cat > expect << EOF
567 commit ffed603236bfa3891c49644257a83598afe8ae5a
568 Author: A U Thor <author@example.com>
569 Date: Thu Apr 7 15:22:13 2005 -0700
571 10th
573 Notes:
574 other note
575 $whitespace
576 yet another note
579 test_expect_success 'append to note from other note with "git notes append -c"' '
580 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
581 git log -1 > actual &&
582 test_cmp expect actual
585 cat > expect << EOF
586 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
587 Author: A U Thor <author@example.com>
588 Date: Thu Apr 7 15:23:13 2005 -0700
590 11th
592 Notes:
593 other note
594 $whitespace
595 yet another note
598 test_expect_success 'copy note with "git notes copy"' '
599 : > a11 &&
600 git add a11 &&
601 test_tick &&
602 git commit -m 11th &&
603 git notes copy HEAD^ HEAD &&
604 git log -1 > actual &&
605 test_cmp expect actual &&
606 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
609 test_expect_success 'prevent overwrite with "git notes copy"' '
610 test_must_fail git notes copy HEAD~2 HEAD &&
611 git log -1 > actual &&
612 test_cmp expect actual &&
613 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
616 cat > expect << EOF
617 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
618 Author: A U Thor <author@example.com>
619 Date: Thu Apr 7 15:23:13 2005 -0700
621 11th
623 Notes:
624 yet another note
625 $whitespace
626 yet another note
629 test_expect_success 'allow overwrite with "git notes copy -f"' '
630 git notes copy -f HEAD~2 HEAD &&
631 git log -1 > actual &&
632 test_cmp expect actual &&
633 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
636 test_expect_success 'cannot copy note from object without notes' '
637 : > a12 &&
638 git add a12 &&
639 test_tick &&
640 git commit -m 12th &&
641 : > a13 &&
642 git add a13 &&
643 test_tick &&
644 git commit -m 13th &&
645 test_must_fail git notes copy HEAD^ HEAD
648 test_done