3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='Test commit notes'
10 cat > fake_editor.sh
<< \EOF
14 chmod a
+x fake_editor.sh
15 GIT_EDITOR
=.
/fake_editor.sh
18 test_expect_success
'cannot annotate non-existing HEAD' '
19 (MSG=3 && export MSG && test_must_fail git notes add)
22 test_expect_success setup
'
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)
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)
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)
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 = $?
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) &&
64 test_must_fail git notes show HEAD^
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) &&
73 test_must_fail git notes show HEAD^
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) &&
82 test_must_fail git notes show HEAD^
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) &&
91 test_must_fail git notes show HEAD^
95 commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
96 Author: A U Thor <author@example.com>
97 Date: Thu Apr 7 15:14:13 2005 -0700
105 test_expect_success
'show notes' '
106 ! (git cat-file commit HEAD | grep b1) &&
107 git log -1 > output &&
108 test_cmp expect output
111 test_expect_success
'create multi-line notes (setup)' '
118 d3d3d3" git notes add
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
134 printf "\n" >> expect-multiline
135 cat expect
>> expect-multiline
137 test_expect_success
'show multi-line notes' '
138 git log -2 > output &&
139 test_cmp expect-multiline output
141 test_expect_success
'create -F notes (setup)' '
146 echo "xyzzy" > note5 &&
147 git notes add -F note5
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
161 printf "\n" >> expect-F
162 cat expect-multiline
>> expect-F
164 test_expect_success
'show -F notes' '
165 git log -3 > output &&
166 test_cmp expect-F output
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
178 test_expect_success
'git log --pretty=raw does not show notes' '
179 git log -1 --pretty=raw >output &&
180 test_cmp expect output
188 test_expect_success
'git log --show-notes' '
189 git log -1 --pretty=raw --show-notes >output &&
190 test_cmp expect output
193 test_expect_success
'git log --no-notes' '
194 git log -1 --no-notes >output &&
198 test_expect_success
'git format-patch does not show notes' '
199 git format-patch -1 --stdout >output &&
203 test_expect_success
'git format-patch --show-notes does show notes' '
204 git format-patch --show-notes -1 --stdout >output &&
209 "" --pretty --pretty=raw
--pretty=short
--pretty=medium \
210 --pretty=full
--pretty=fuller
--pretty=format
:%s
--oneline
213 "") p
= not
= negate
="" ;;
214 ?
*) p
="$pretty" not
=" not" negate
="!" ;;
216 test_expect_success
"git show $pretty does$not show notes" '
217 git show $p >output &&
218 eval "$negate grep xyzzy output"
222 test_expect_success
'create -m notes (setup)' '
227 git notes add -m spam -m "foo
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
248 printf "\n" >> expect-m
249 cat expect-F
>> expect-m
251 test_expect_success
'show -m notes' '
252 git log -4 > output &&
253 test_cmp expect-m output
256 test_expect_success
'remove note with add -f -F /dev/null (setup)' '
257 git notes add -f -F /dev/null
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
268 printf "\n" >> expect-rm-F
269 cat expect-F
>> expect-rm-F
271 test_expect_success
'verify note removal with -F /dev/null' '
272 git log -4 > output &&
273 test_cmp expect-rm-F output &&
277 test_expect_success
'do not create empty note with -m "" (setup)' '
281 test_expect_success
'verify non-creation of note with -m ""' '
282 git log -4 > output &&
283 test_cmp expect-rm-F output &&
287 cat > expect-combine_m_and_F
<< EOF
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
307 test_expect_success
'remove note with "git notes remove" (setup)' '
308 git notes remove HEAD^ &&
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
319 commit 15023535574ded8b1a89052b32673f84cf9582b8
320 Author: A U Thor <author@example.com>
321 Date: Thu Apr 7 15:16:13 2005 -0700
326 printf "\n" >> expect-rm-remove
327 cat expect-multiline
>> expect-rm-remove
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^
336 c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
337 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
340 test_expect_success
'list notes with "git notes list"' '
341 git notes list > output &&
342 test_cmp expect output
345 test_expect_success
'list notes with "git notes"' '
346 git notes > output &&
347 test_cmp expect output
351 c18dc024e14f08d18d14eea0d747ff692d66d6a3
354 test_expect_success
'list specific note with "git notes list <object>"' '
355 git notes list HEAD^^ > output &&
356 test_cmp expect output
362 test_expect_success
'listing non-existing notes fails' '
363 test_must_fail git notes list HEAD > output &&
364 test_cmp expect output
370 More notes appended with git notes append
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
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
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
391 More notes appended with git notes append" &&
392 git notes show > output &&
393 test_cmp expect output
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
403 test_expect_success
'create other note on a different notes ref (setup)' '
408 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
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
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
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
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
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
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
451 test_expect_success
'Allow notes on non-commits (trees, blobs, tags)' '
452 echo "Note on a tree" > expect
453 git notes add -m "Note on a tree" HEAD: &&
454 git notes show HEAD: > actual &&
455 test_cmp expect actual &&
456 echo "Note on a blob" > expect
457 filename=$(git ls-tree --name-only HEAD | head -n1) &&
458 git notes add -m "Note on a blob" HEAD:$filename &&
459 git notes show HEAD:$filename > actual &&
460 test_cmp expect actual &&
461 echo "Note on a tag" > expect
462 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
463 git notes add -m "Note on a tag" foobar &&
464 git notes show foobar > actual &&
465 test_cmp expect actual
469 commit 2ede89468182a62d0bde2583c736089bcf7d7e92
470 Author: A U Thor <author@example.com>
471 Date: Thu Apr 7 15:19:13 2005 -0700
479 test_expect_success
'create note from other note with "git notes add -C"' '
484 git notes add -C $(git notes list HEAD^) &&
485 git log -1 > actual &&
486 test_cmp expect actual &&
487 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
490 test_expect_success
'create note from non-existing note with "git notes add -C" fails' '
495 test_must_fail git notes add -C deadbeef &&
496 test_must_fail git notes list HEAD
500 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
501 Author: A U Thor <author@example.com>
502 Date: Thu Apr 7 15:21:13 2005 -0700
510 test_expect_success
'create note from other note with "git notes add -c"' '
515 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
516 git log -1 > actual &&
517 test_cmp expect actual
520 test_expect_success
'create note from non-existing note with "git notes add -c" fails' '
524 git commit -m 10th &&
525 test_must_fail MSG="yet another note" git notes add -c deadbeef &&
526 test_must_fail git notes list HEAD
530 commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
531 Author: A U Thor <author@example.com>
532 Date: Thu Apr 7 15:21:13 2005 -0700
542 test_expect_success
'append to note from other note with "git notes append -C"' '
543 git notes append -C $(git notes list HEAD^) HEAD^ &&
544 git log -1 HEAD^ > actual &&
545 test_cmp expect actual
549 commit ffed603236bfa3891c49644257a83598afe8ae5a
550 Author: A U Thor <author@example.com>
551 Date: Thu Apr 7 15:22:13 2005 -0700
559 test_expect_success
'create note from other note with "git notes append -c"' '
560 MSG="other note" git notes append -c $(git notes list HEAD^) &&
561 git log -1 > actual &&
562 test_cmp expect actual
566 commit ffed603236bfa3891c49644257a83598afe8ae5a
567 Author: A U Thor <author@example.com>
568 Date: Thu Apr 7 15:22:13 2005 -0700
578 test_expect_success
'append to note from other note with "git notes append -c"' '
579 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
580 git log -1 > actual &&
581 test_cmp expect actual
585 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
586 Author: A U Thor <author@example.com>
587 Date: Thu Apr 7 15:23:13 2005 -0700
597 test_expect_success
'copy note with "git notes copy"' '
601 git commit -m 11th &&
602 git notes copy HEAD^ HEAD &&
603 git log -1 > actual &&
604 test_cmp expect actual &&
605 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
608 test_expect_success
'prevent overwrite with "git notes copy"' '
609 test_must_fail git notes copy HEAD~2 HEAD &&
610 git log -1 > actual &&
611 test_cmp expect actual &&
612 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
616 commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
617 Author: A U Thor <author@example.com>
618 Date: Thu Apr 7 15:23:13 2005 -0700
628 test_expect_success
'allow overwrite with "git notes copy -f"' '
629 git notes copy -f HEAD~2 HEAD &&
630 git log -1 > actual &&
631 test_cmp expect actual &&
632 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
635 test_expect_success
'cannot copy note from object without notes' '
639 git commit -m 12th &&
643 git commit -m 13th &&
644 test_must_fail git notes copy HEAD^ HEAD