]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3301-notes.sh
t3301: modernize style
[thirdparty/git.git] / t / t3301-notes.sh
CommitLineData
65d9fb48
JS
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='Test commit notes'
7
8. ./test-lib.sh
9
908a3203
JH
10write_script fake_editor <<\EOF
11echo "$MSG" >"$1"
12echo "$MSG" >&2
65d9fb48 13EOF
908a3203 14GIT_EDITOR=./fake_editor
cd067d3b 15export GIT_EDITOR
65d9fb48 16
908a3203
JH
17indent=" "
18
65d9fb48 19test_expect_success 'cannot annotate non-existing HEAD' '
512477b1 20 test_must_fail env MSG=3 git notes add
65d9fb48
JS
21'
22
908a3203
JH
23test_expect_success 'setup' '
24 test_commit 1st &&
25 test_commit 2nd
65d9fb48
JS
26'
27
28test_expect_success 'need valid notes ref' '
512477b1
DT
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
65d9fb48
JS
31'
32
7aa4754e 33test_expect_success 'refusing to add notes in refs/heads/' '
512477b1 34 test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add
65d9fb48
JS
35'
36
7aa4754e 37test_expect_success 'refusing to edit notes in refs/remotes/' '
512477b1 38 test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit
65d9fb48
JS
39'
40
41# 1 indicates caught gracefully by die, 128 means git-show barked
42test_expect_success 'handle empty notes gracefully' '
0155a64e 43 test_expect_code 1 git notes show
65d9fb48
JS
44'
45
636db2c0 46test_expect_success 'show non-existent notes entry with %N' '
908a3203
JH
47 test_write_lines A B >expect &&
48 git show -s --format="A%n%NB" >actual &&
49 test_cmp expect actual
636db2c0
JH
50'
51
65d9fb48 52test_expect_success 'create notes' '
7aa4754e 53 MSG=b4 git notes add &&
908a3203
JH
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)" &&
cd067d3b
JH
58 git show HEAD^ &&
59 test_must_fail git notes show HEAD^
60'
61
636db2c0 62test_expect_success 'show notes entry with %N' '
908a3203
JH
63 test_write_lines A b4 B >expect &&
64 git show -s --format="A%n%NB" >actual &&
65 test_cmp expect actual
636db2c0
JH
66'
67
b2e256b0 68test_expect_success 'create reflog entry' '
908a3203
JH
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
4d80fa8f
MG
74'
75
cd067d3b 76test_expect_success 'edit existing notes' '
7aa4754e 77 MSG=b3 git notes edit &&
908a3203
JH
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)" &&
7aa4754e
JH
82 git show HEAD^ &&
83 test_must_fail git notes show HEAD^
84'
85
84a7e35e
JH
86test_expect_success 'cannot "git notes add -m" where notes already exists' '
87 test_must_fail git notes add -m "b2" &&
908a3203
JH
88 test_path_is_missing .git/NOTES_EDITMSG &&
89 git ls-tree -r refs/notes/commits >actual &&
90 test_line_count = 1 actual &&
91 test "b3" = "$(git notes show)" &&
7aa4754e
JH
92 git show HEAD^ &&
93 test_must_fail git notes show HEAD^
94'
95
84a7e35e
JH
96test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
97 git notes add -f -m "b1" &&
908a3203
JH
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 "b1" = "$(git notes show)" &&
84a7e35e
JH
102 git show HEAD^ &&
103 test_must_fail git notes show HEAD^
104'
105
106test_expect_success 'add w/no options on existing note morphs into edit' '
107 MSG=b2 git notes add &&
908a3203
JH
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 "b2" = "$(git notes show)" &&
84a7e35e
JH
112 git show HEAD^ &&
113 test_must_fail git notes show HEAD^
114'
115
7aa4754e
JH
116test_expect_success 'can overwrite existing note with "git notes add -f"' '
117 MSG=b1 git notes add -f &&
908a3203
JH
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 "b1" = "$(git notes show)" &&
65d9fb48
JS
122 git show HEAD^ &&
123 test_must_fail git notes show HEAD^
124'
125
908a3203
JH
126test_expect_success 'show notes' '
127 cat >expect <<-EOF &&
128 commit 7a4ca6ee52a974a66cbaa78e33214535dff1d691
129 Author: A U Thor <author@example.com>
130 Date: Thu Apr 7 15:14:13 2005 -0700
65d9fb48 131
908a3203 132 ${indent}2nd
65d9fb48 133
908a3203
JH
134 Notes:
135 ${indent}b1
136 EOF
65d9fb48 137 ! (git cat-file commit HEAD | grep b1) &&
908a3203
JH
138 git log -1 >actual &&
139 test_cmp expect actual
65d9fb48
JS
140'
141
908a3203
JH
142test_expect_success 'show multi-line notes' '
143 test_commit 3rd &&
144 MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
145 cat >expect-multiline <<-EOF &&
146 commit d07d62e5208f22eb5695e7eb47667dc8b9860290
147 Author: A U Thor <author@example.com>
148 Date: Thu Apr 7 15:15:13 2005 -0700
65d9fb48 149
908a3203 150 ${indent}3rd
65d9fb48 151
908a3203
JH
152 Notes:
153 ${indent}b3
154 ${indent}c3c3c3c3
155 ${indent}d3d3d3
65d9fb48 156
908a3203
JH
157 EOF
158 cat expect >>expect-multiline &&
159 git log -2 >actual &&
160 test_cmp expect-multiline actual
65d9fb48 161'
d9246d43 162
908a3203
JH
163test_expect_success 'show -F notes' '
164 test_commit 4th &&
165 echo "xyzzy" >note5 &&
166 git notes add -F note5 &&
167 cat >expect-F <<-EOF &&
168 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
169 Author: A U Thor <author@example.com>
170 Date: Thu Apr 7 15:16:13 2005 -0700
d9246d43 171
908a3203 172 ${indent}4th
d9246d43 173
908a3203
JH
174 Notes:
175 ${indent}xyzzy
d9246d43 176
908a3203
JH
177 EOF
178 cat expect-multiline >>expect-F &&
179 git log -3 >actual &&
180 test_cmp expect-F actual
d9246d43 181'
65d9fb48 182
84a7e35e 183test_expect_success 'Re-adding -F notes without -f fails' '
908a3203 184 echo "zyxxy" >note5 &&
84a7e35e 185 test_must_fail git notes add -F note5 &&
908a3203
JH
186 git log -3 >actual &&
187 test_cmp expect-F actual
84a7e35e
JH
188'
189
66b2ed09 190test_expect_success 'git log --pretty=raw does not show notes' '
908a3203
JH
191 cat >expect <<-EOF &&
192 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
193 tree 05ac65288c4c4b3b709a020ae94b2ece2f2201ae
194 parent d07d62e5208f22eb5695e7eb47667dc8b9860290
195 author A U Thor <author@example.com> 1112912173 -0700
196 committer C O Mitter <committer@example.com> 1112912173 -0700
197
198 ${indent}4th
199 EOF
200 git log -1 --pretty=raw >actual &&
201 test_cmp expect actual
66b2ed09
JH
202'
203
66b2ed09 204test_expect_success 'git log --show-notes' '
908a3203
JH
205 cat >>expect <<-EOF &&
206
207 Notes:
208 ${indent}xyzzy
209 EOF
210 git log -1 --pretty=raw --show-notes >actual &&
211 test_cmp expect actual
66b2ed09
JH
212'
213
214test_expect_success 'git log --no-notes' '
908a3203
JH
215 git log -1 --no-notes >actual &&
216 ! grep xyzzy actual
66b2ed09
JH
217'
218
219test_expect_success 'git format-patch does not show notes' '
908a3203
JH
220 git format-patch -1 --stdout >actual &&
221 ! grep xyzzy actual
66b2ed09
JH
222'
223
224test_expect_success 'git format-patch --show-notes does show notes' '
908a3203
JH
225 git format-patch --show-notes -1 --stdout >actual &&
226 grep xyzzy actual
66b2ed09
JH
227'
228
7dccadf3
JH
229for pretty in \
230 "" --pretty --pretty=raw --pretty=short --pretty=medium \
231 --pretty=full --pretty=fuller --pretty=format:%s --oneline
66b2ed09
JH
232do
233 case "$pretty" in
234 "") p= not= negate="" ;;
7dccadf3 235 ?*) p="$pretty" not=" not" negate="!" ;;
66b2ed09
JH
236 esac
237 test_expect_success "git show $pretty does$not show notes" '
908a3203
JH
238 git show $p >actual &&
239 eval "$negate grep xyzzy actual"
66b2ed09
JH
240 '
241done
242
7249e912
JK
243test_expect_success 'setup alternate notes ref' '
244 git notes --ref=alternate add -m alternate
245'
246
247test_expect_success 'git log --notes shows default notes' '
908a3203
JH
248 git log -1 --notes >actual &&
249 grep xyzzy actual &&
250 ! grep alternate actual
7249e912
JK
251'
252
253test_expect_success 'git log --notes=X shows only X' '
908a3203
JH
254 git log -1 --notes=alternate >actual &&
255 ! grep xyzzy actual &&
256 grep alternate actual
7249e912
JK
257'
258
259test_expect_success 'git log --notes --notes=X shows both' '
908a3203
JH
260 git log -1 --notes --notes=alternate >actual &&
261 grep xyzzy actual &&
262 grep alternate actual
7249e912
JK
263'
264
92e0d425
JK
265test_expect_success 'git log --no-notes resets default state' '
266 git log -1 --notes --notes=alternate \
267 --no-notes --notes=alternate \
908a3203
JH
268 >actual &&
269 ! grep xyzzy actual &&
270 grep alternate actual
92e0d425
JK
271'
272
273test_expect_success 'git log --no-notes resets ref list' '
274 git log -1 --notes --notes=alternate \
275 --no-notes --notes \
908a3203
JH
276 >actual &&
277 grep xyzzy actual &&
278 ! grep alternate actual
cd067d3b
JH
279'
280
908a3203
JH
281test_expect_success 'show -m notes' '
282 test_commit 5th &&
283 git notes add -m spam -m "foo${LF}bar${LF}baz" &&
284 cat >expect-m <<-EOF &&
285 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
286 Author: A U Thor <author@example.com>
287 Date: Thu Apr 7 15:17:13 2005 -0700
288
289 ${indent}5th
290
291 Notes:
292 ${indent}spam
293 ${indent}
294 ${indent}foo
295 ${indent}bar
296 ${indent}baz
297
298 EOF
299 cat expect-F >>expect-m &&
300 git log -4 >actual &&
301 test_cmp expect-m actual
302'
303
304test_expect_success 'remove note with add -f -F /dev/null' '
305 git notes add -f -F /dev/null &&
306 cat >expect-rm-F <<-EOF &&
307 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
308 Author: A U Thor <author@example.com>
309 Date: Thu Apr 7 15:17:13 2005 -0700
310
311 ${indent}5th
312
313 EOF
314 cat expect-F >>expect-rm-F &&
315 git log -4 >actual &&
316 test_cmp expect-rm-F actual &&
ce14e0b2 317 test_must_fail git notes show
a0b4dfa9
JH
318'
319
908a3203
JH
320test_expect_success 'do not create empty note with -m ""' '
321 git notes add -m "" &&
322 git log -4 >actual &&
323 test_cmp expect-rm-F actual &&
ce14e0b2 324 test_must_fail git notes show
a0b4dfa9
JH
325'
326
908a3203
JH
327test_expect_success 'create note with combination of -m and -F' '
328 cat >expect-combine_m_and_F <<-EOF &&
329 foo
348f199b 330
908a3203 331 xyzzy
348f199b 332
908a3203 333 bar
348f199b 334
908a3203 335 zyxxy
348f199b 336
908a3203
JH
337 baz
338 EOF
339 echo "xyzzy" >note_a &&
340 echo "zyxxy" >note_b &&
348f199b 341 git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
908a3203
JH
342 git notes show >actual &&
343 test_cmp expect-combine_m_and_F actual
348f199b
JH
344'
345
908a3203 346test_expect_success 'remove note with "git notes remove"' '
348f199b 347 git notes remove HEAD^ &&
908a3203
JH
348 git notes remove &&
349 cat >expect-rm-remove <<-EOF &&
350 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
351 Author: A U Thor <author@example.com>
352 Date: Thu Apr 7 15:17:13 2005 -0700
92b3385f 353
908a3203 354 ${indent}5th
92b3385f 355
908a3203
JH
356 commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
357 Author: A U Thor <author@example.com>
358 Date: Thu Apr 7 15:16:13 2005 -0700
92b3385f 359
908a3203 360 ${indent}4th
92b3385f 361
908a3203
JH
362 EOF
363 cat expect-multiline >>expect-rm-remove &&
364 git log -4 >actual &&
365 test_cmp expect-rm-remove actual &&
ce14e0b2 366 test_must_fail git notes show HEAD^
92b3385f
JH
367'
368
1ee1e43d 369test_expect_success 'removing non-existing note should not create new commit' '
908a3203 370 git rev-parse --verify refs/notes/commits >before_commit &&
1ee1e43d 371 test_must_fail git notes remove HEAD^ &&
908a3203 372 git rev-parse --verify refs/notes/commits >after_commit &&
1ee1e43d
JH
373 test_cmp before_commit after_commit
374'
375
c3ab1a8e
JH
376test_expect_success 'removing more than one' '
377 before=$(git rev-parse --verify refs/notes/commits) &&
378 test_when_finished "git update-ref refs/notes/commits $before" &&
379
380 # We have only two -- add another and make sure it stays
381 git notes add -m "extra" &&
382 git notes list HEAD >after-removal-expect &&
383 git notes remove HEAD^^ HEAD^^^ &&
384 git notes list | sed -e "s/ .*//" >actual &&
385 test_cmp after-removal-expect actual
386'
387
388test_expect_success 'removing is atomic' '
389 before=$(git rev-parse --verify refs/notes/commits) &&
390 test_when_finished "git update-ref refs/notes/commits $before" &&
391 test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
392 after=$(git rev-parse --verify refs/notes/commits) &&
393 test "$before" = "$after"
394'
395
2d370d2f
JH
396test_expect_success 'removing with --ignore-missing' '
397 before=$(git rev-parse --verify refs/notes/commits) &&
398 test_when_finished "git update-ref refs/notes/commits $before" &&
399
400 # We have only two -- add another and make sure it stays
401 git notes add -m "extra" &&
402 git notes list HEAD >after-removal-expect &&
403 git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
404 git notes list | sed -e "s/ .*//" >actual &&
405 test_cmp after-removal-expect actual
406'
407
408test_expect_success 'removing with --ignore-missing but bogus ref' '
409 before=$(git rev-parse --verify refs/notes/commits) &&
410 test_when_finished "git update-ref refs/notes/commits $before" &&
411 test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
412 after=$(git rev-parse --verify refs/notes/commits) &&
413 test "$before" = "$after"
414'
415
46538012
JH
416test_expect_success 'remove reads from --stdin' '
417 before=$(git rev-parse --verify refs/notes/commits) &&
418 test_when_finished "git update-ref refs/notes/commits $before" &&
419
420 # We have only two -- add another and make sure it stays
421 git notes add -m "extra" &&
422 git notes list HEAD >after-removal-expect &&
423 git rev-parse HEAD^^ HEAD^^^ >input &&
424 git notes remove --stdin <input &&
425 git notes list | sed -e "s/ .*//" >actual &&
426 test_cmp after-removal-expect actual
427'
428
429test_expect_success 'remove --stdin is also atomic' '
430 before=$(git rev-parse --verify refs/notes/commits) &&
431 test_when_finished "git update-ref refs/notes/commits $before" &&
432 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
433 test_must_fail git notes remove --stdin <input &&
434 after=$(git rev-parse --verify refs/notes/commits) &&
435 test "$before" = "$after"
436'
437
438test_expect_success 'removing with --stdin --ignore-missing' '
439 before=$(git rev-parse --verify refs/notes/commits) &&
440 test_when_finished "git update-ref refs/notes/commits $before" &&
441
442 # We have only two -- add another and make sure it stays
443 git notes add -m "extra" &&
444 git notes list HEAD >after-removal-expect &&
445 git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
446 git notes remove --ignore-missing --stdin <input &&
447 git notes list | sed -e "s/ .*//" >actual &&
448 test_cmp after-removal-expect actual
449'
450
e397421a 451test_expect_success 'list notes with "git notes list"' '
908a3203
JH
452 cat >expect <<-EOF &&
453 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
454 c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
455 EOF
456 git notes list >actual &&
457 test_cmp expect actual
e397421a
JH
458'
459
460test_expect_success 'list notes with "git notes"' '
908a3203
JH
461 git notes >actual &&
462 test_cmp expect actual
e397421a
JH
463'
464
e397421a 465test_expect_success 'list specific note with "git notes list <object>"' '
908a3203
JH
466 cat >expect <<-EOF &&
467 c18dc024e14f08d18d14eea0d747ff692d66d6a3
468 EOF
469 git notes list HEAD^^ >actual &&
470 test_cmp expect actual
e397421a
JH
471'
472
e397421a 473test_expect_success 'listing non-existing notes fails' '
908a3203
JH
474 cat >expect <<-EOF &&
475 EOF
476 test_must_fail git notes list HEAD >actual &&
477 test_cmp expect actual
e397421a
JH
478'
479
2347fae5 480test_expect_success 'append to existing note with "git notes append"' '
908a3203
JH
481 cat >expect <<-EOF &&
482 Initial set of notes
483
484 More notes appended with git notes append
485 EOF
2347fae5
JH
486 git notes add -m "Initial set of notes" &&
487 git notes append -m "More notes appended with git notes append" &&
908a3203
JH
488 git notes show >actual &&
489 test_cmp expect actual
2347fae5
JH
490'
491
74884b52 492test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
908a3203
JH
493 cat >expect_list <<-EOF &&
494 c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
495 4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
496 c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
497 EOF
498 git notes list >actual &&
499 test_cmp expect_list actual
74884b52
SB
500'
501
2347fae5
JH
502test_expect_success 'appending empty string does not change existing note' '
503 git notes append -m "" &&
908a3203
JH
504 git notes show >actual &&
505 test_cmp expect actual
2347fae5
JH
506'
507
508test_expect_success 'git notes append == add when there is no existing note' '
509 git notes remove HEAD &&
510 test_must_fail git notes list HEAD &&
908a3203
JH
511 git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
512 git notes show >actual &&
513 test_cmp expect actual
2347fae5
JH
514'
515
516test_expect_success 'appending empty string to non-existing note does not create note' '
517 git notes remove HEAD &&
518 test_must_fail git notes list HEAD &&
519 git notes append -m "" &&
520 test_must_fail git notes list HEAD
521'
522
cd067d3b 523test_expect_success 'create other note on a different notes ref (setup)' '
908a3203
JH
524 test_commit 6th &&
525 GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
526 cat >expect-not-other <<-EOF &&
527 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
528 Author: A U Thor <author@example.com>
529 Date: Thu Apr 7 15:18:13 2005 -0700
cd067d3b 530
908a3203
JH
531 ${indent}6th
532 EOF
533 cp expect-not-other expect-other &&
534 cat >>expect-other <<-EOF
cd067d3b 535
908a3203
JH
536 Notes (other):
537 ${indent}other note
538 EOF
539'
3b78cdbe
JH
540
541test_expect_success 'Do not show note on other ref by default' '
908a3203
JH
542 git log -1 >actual &&
543 test_cmp expect-not-other actual
3b78cdbe
JH
544'
545
546test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
908a3203
JH
547 GIT_NOTES_REF="refs/notes/other" git log -1 >actual &&
548 test_cmp expect-other actual
3b78cdbe
JH
549'
550
551test_expect_success 'Do show note when ref is given in core.notesRef config' '
908a3203
JH
552 test_config core.notesRef "refs/notes/other" &&
553 git log -1 >actual &&
554 test_cmp expect-other actual
3b78cdbe
JH
555'
556
557test_expect_success 'Do not show note when core.notesRef is overridden' '
908a3203
JH
558 test_config core.notesRef "refs/notes/other" &&
559 GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual &&
560 test_cmp expect-not-other actual
3b78cdbe
JH
561'
562
908a3203
JH
563test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
564 cat >expect-both <<-EOF &&
565 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
566 Author: A U Thor <author@example.com>
567 Date: Thu Apr 7 15:18:13 2005 -0700
894a9d33 568
908a3203 569 ${indent}6th
894a9d33 570
908a3203
JH
571 Notes:
572 ${indent}order test
894a9d33 573
908a3203
JH
574 Notes (other):
575 ${indent}other note
894a9d33 576
908a3203
JH
577 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
578 Author: A U Thor <author@example.com>
579 Date: Thu Apr 7 15:17:13 2005 -0700
894a9d33 580
908a3203 581 ${indent}5th
894a9d33 582
908a3203
JH
583 Notes:
584 ${indent}replacement for deleted note
585 EOF
894a9d33
TR
586 GIT_NOTES_REF=refs/notes/commits git notes add \
587 -m"replacement for deleted note" HEAD^ &&
588 GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
908a3203
JH
589 test_unconfig core.notesRef &&
590 test_config notes.displayRef "refs/notes/*" &&
591 git log -2 >actual &&
592 test_cmp expect-both actual
894a9d33
TR
593'
594
595test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
908a3203
JH
596 test_config core.notesRef refs/notes/commits &&
597 test_config notes.displayRef refs/notes/other &&
598 git log -2 >actual &&
599 test_cmp expect-both actual
894a9d33
TR
600'
601
602test_expect_success 'notes.displayRef can be given more than once' '
908a3203
JH
603 test_unconfig core.notesRef &&
604 test_config notes.displayRef refs/notes/commits &&
894a9d33 605 git config --add notes.displayRef refs/notes/other &&
908a3203
JH
606 git log -2 >actual &&
607 test_cmp expect-both actual
894a9d33
TR
608'
609
908a3203
JH
610test_expect_success 'notes.displayRef respects order' '
611 cat >expect-both-reversed <<-EOF &&
612 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
613 Author: A U Thor <author@example.com>
614 Date: Thu Apr 7 15:18:13 2005 -0700
894a9d33 615
908a3203 616 ${indent}6th
894a9d33 617
908a3203
JH
618 Notes (other):
619 ${indent}other note
894a9d33 620
908a3203
JH
621 Notes:
622 ${indent}order test
623 EOF
624 test_config core.notesRef refs/notes/other &&
625 test_config notes.displayRef refs/notes/commits &&
626 git log -1 >actual &&
627 test_cmp expect-both-reversed actual
894a9d33
TR
628'
629
630test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
894a9d33 631 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
908a3203
JH
632 git log -2 >actual &&
633 test_cmp expect-both actual
894a9d33
TR
634'
635
908a3203
JH
636test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
637 cat >expect-none <<-EOF &&
638 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
639 Author: A U Thor <author@example.com>
640 Date: Thu Apr 7 15:18:13 2005 -0700
894a9d33 641
908a3203 642 ${indent}6th
894a9d33 643
908a3203
JH
644 commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
645 Author: A U Thor <author@example.com>
646 Date: Thu Apr 7 15:17:13 2005 -0700
894a9d33 647
908a3203
JH
648 ${indent}5th
649 EOF
650 test_config notes.displayRef "refs/notes/*" &&
651 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual &&
652 test_cmp expect-none actual
894a9d33
TR
653'
654
655test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
908a3203
JH
656 GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual &&
657 test_cmp expect-both actual
894a9d33
TR
658'
659
908a3203
JH
660test_expect_success '--no-standard-notes' '
661 cat >expect-commits <<EOF
662 commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
663 Author: A U Thor <author@example.com>
664 Date: Thu Apr 7 15:18:13 2005 -0700
894a9d33 665
908a3203 666 ${indent}6th
894a9d33 667
908a3203
JH
668 Notes:
669 ${indent}order test
670 EOF
671 git log --no-standard-notes --show-notes=commits -1 >actual &&
672 test_cmp expect-commits actual
894a9d33
TR
673'
674
675test_expect_success '--standard-notes' '
908a3203 676 test_config notes.displayRef "refs/notes/*" &&
894a9d33 677 git log --no-standard-notes --show-notes=commits \
908a3203
JH
678 --standard-notes -2 >actual &&
679 test_cmp expect-both actual
894a9d33
TR
680'
681
682test_expect_success '--show-notes=ref accumulates' '
683 git log --show-notes=other --show-notes=commits \
908a3203
JH
684 --no-standard-notes -1 >actual &&
685 test_cmp expect-both-reversed actual
894a9d33
TR
686'
687
b24bb997 688test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
908a3203
JH
689 test_config core.notesRef refs/notes/other &&
690 echo "Note on a tree" >expect &&
7aa4754e 691 git notes add -m "Note on a tree" HEAD: &&
908a3203 692 git notes show HEAD: >actual &&
b24bb997 693 test_cmp expect actual &&
908a3203 694 echo "Note on a blob" >expect &&
b24bb997 695 filename=$(git ls-tree --name-only HEAD | head -n1) &&
7aa4754e 696 git notes add -m "Note on a blob" HEAD:$filename &&
908a3203 697 git notes show HEAD:$filename >actual &&
b24bb997 698 test_cmp expect actual &&
908a3203 699 echo "Note on a tag" >expect &&
b24bb997 700 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
7aa4754e 701 git notes add -m "Note on a tag" foobar &&
908a3203 702 git notes show foobar >actual &&
b24bb997
JH
703 test_cmp expect actual
704'
705
908a3203
JH
706test_expect_success 'create note from other note with "git notes add -C"' '
707 cat >expect <<-EOF &&
708 commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c
709 Author: A U Thor <author@example.com>
710 Date: Thu Apr 7 15:19:13 2005 -0700
0691cff7 711
908a3203 712 ${indent}7th
0691cff7 713
908a3203
JH
714 Notes:
715 ${indent}order test
716 EOF
717 test_commit 7th &&
0691cff7 718 git notes add -C $(git notes list HEAD^) &&
908a3203 719 git log -1 >actual &&
0691cff7
JH
720 test_cmp expect actual &&
721 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
722'
723
724test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
908a3203 725 test_commit 8th &&
0691cff7
JH
726 test_must_fail git notes add -C deadbeef &&
727 test_must_fail git notes list HEAD
728'
729
ce8daa1e
JH
730test_expect_success 'create note from non-blob with "git notes add -C" fails' '
731 commit=$(git rev-parse --verify HEAD) &&
732 tree=$(git rev-parse --verify HEAD:) &&
733 test_must_fail git notes add -C $commit &&
734 test_must_fail git notes add -C $tree &&
735 test_must_fail git notes list HEAD
736'
737
908a3203
JH
738test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
739 cat >expect <<-EOF &&
740 commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf
741 Author: A U Thor <author@example.com>
742 Date: Thu Apr 7 15:20:13 2005 -0700
ce8daa1e 743
908a3203 744 ${indent}8th
ce8daa1e 745
908a3203
JH
746 Notes:
747 ${indent}This is a blob object
748 EOF
ce8daa1e
JH
749 blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
750 git notes add -C $blob &&
908a3203 751 git log -1 >actual &&
ce8daa1e
JH
752 test_cmp expect actual &&
753 test "$(git notes list HEAD)" = "$blob"
754'
755
908a3203
JH
756test_expect_success 'create note from other note with "git notes add -c"' '
757 cat >expect <<-EOF &&
758 commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
759 Author: A U Thor <author@example.com>
760 Date: Thu Apr 7 15:21:13 2005 -0700
0691cff7 761
908a3203 762 ${indent}9th
0691cff7 763
908a3203
JH
764 Notes:
765 ${indent}yet another note
766 EOF
767 test_commit 9th &&
0691cff7 768 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
908a3203 769 git log -1 >actual &&
0691cff7
JH
770 test_cmp expect actual
771'
772
773test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
908a3203 774 test_commit 10th &&
512477b1 775 test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
0691cff7
JH
776 test_must_fail git notes list HEAD
777'
778
0691cff7 779test_expect_success 'append to note from other note with "git notes append -C"' '
908a3203
JH
780 cat >expect <<-EOF &&
781 commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
782 Author: A U Thor <author@example.com>
783 Date: Thu Apr 7 15:21:13 2005 -0700
784
785 ${indent}9th
786
787 Notes:
788 ${indent}yet another note
789 ${indent}
790 ${indent}yet another note
791 EOF
0691cff7 792 git notes append -C $(git notes list HEAD^) HEAD^ &&
908a3203 793 git log -1 HEAD^ >actual &&
0691cff7
JH
794 test_cmp expect actual
795'
796
908a3203
JH
797test_expect_success 'create note from other note with "git notes append -c"' '
798 cat >expect <<-EOF &&
799 commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
800 Author: A U Thor <author@example.com>
801 Date: Thu Apr 7 15:22:13 2005 -0700
0691cff7 802
908a3203 803 ${indent}10th
0691cff7 804
908a3203
JH
805 Notes:
806 ${indent}other note
807 EOF
0691cff7 808 MSG="other note" git notes append -c $(git notes list HEAD^) &&
908a3203 809 git log -1 >actual &&
0691cff7
JH
810 test_cmp expect actual
811'
812
0691cff7 813test_expect_success 'append to note from other note with "git notes append -c"' '
908a3203
JH
814 cat >expect <<-EOF &&
815 commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
816 Author: A U Thor <author@example.com>
817 Date: Thu Apr 7 15:22:13 2005 -0700
818
819 ${indent}10th
820
821 Notes:
822 ${indent}other note
823 ${indent}
824 ${indent}yet another note
825 EOF
0691cff7 826 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
908a3203 827 git log -1 >actual &&
0691cff7
JH
828 test_cmp expect actual
829'
830
e73bbd96 831test_expect_success 'copy note with "git notes copy"' '
908a3203
JH
832 cat >expect <<-EOF &&
833 commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
834 Author: A U Thor <author@example.com>
835 Date: Thu Apr 7 15:23:13 2005 -0700
836
837 ${indent}11th
838
839 Notes:
840 ${indent}other note
841 ${indent}
842 ${indent}yet another note
843 EOF
844 test_commit 11th &&
e73bbd96 845 git notes copy HEAD^ HEAD &&
908a3203 846 git log -1 >actual &&
e73bbd96
JH
847 test_cmp expect actual &&
848 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
849'
850
851test_expect_success 'prevent overwrite with "git notes copy"' '
852 test_must_fail git notes copy HEAD~2 HEAD &&
908a3203 853 git log -1 >actual &&
e73bbd96
JH
854 test_cmp expect actual &&
855 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
856'
857
e73bbd96 858test_expect_success 'allow overwrite with "git notes copy -f"' '
908a3203
JH
859 cat >expect <<-EOF &&
860 commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
861 Author: A U Thor <author@example.com>
862 Date: Thu Apr 7 15:23:13 2005 -0700
863
864 ${indent}11th
865
866 Notes:
867 ${indent}yet another note
868 ${indent}
869 ${indent}yet another note
870 EOF
e73bbd96 871 git notes copy -f HEAD~2 HEAD &&
908a3203 872 git log -1 >actual &&
e73bbd96
JH
873 test_cmp expect actual &&
874 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
875'
876
877test_expect_success 'cannot copy note from object without notes' '
908a3203
JH
878 test_commit 12th &&
879 test_commit 13th &&
e73bbd96
JH
880 test_must_fail git notes copy HEAD^ HEAD
881'
882
908a3203
JH
883test_expect_success 'git notes copy --stdin' '
884 cat >expect <<-EOF &&
885 commit e871aa61182b1d95d0a6fb75445d891722863b6b
886 Author: A U Thor <author@example.com>
887 Date: Thu Apr 7 15:25:13 2005 -0700
160baa0d 888
908a3203 889 ${indent}13th
160baa0d 890
908a3203
JH
891 Notes:
892 ${indent}yet another note
893 ${indent}
894 ${indent}yet another note
160baa0d 895
908a3203
JH
896 commit 65e263ded02ae4e8839bc151095113737579dc12
897 Author: A U Thor <author@example.com>
898 Date: Thu Apr 7 15:24:13 2005 -0700
160baa0d 899
908a3203 900 ${indent}12th
160baa0d 901
908a3203
JH
902 Notes:
903 ${indent}other note
904 ${indent}
905 ${indent}yet another note
906 EOF
160baa0d
TR
907 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
908 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
909 git notes copy --stdin &&
908a3203
JH
910 git log -2 >actual &&
911 test_cmp expect actual &&
160baa0d
TR
912 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
913 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
914'
915
908a3203
JH
916test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
917 cat >expect <<-EOF &&
918 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
919 Author: A U Thor <author@example.com>
920 Date: Thu Apr 7 15:27:13 2005 -0700
6956f858 921
908a3203 922 ${indent}15th
6956f858 923
908a3203
JH
924 commit 07c85d77059393ed0154b8c96906547a59dfcddd
925 Author: A U Thor <author@example.com>
926 Date: Thu Apr 7 15:26:13 2005 -0700
6956f858 927
908a3203
JH
928 ${indent}14th
929 EOF
6956f858
TR
930 test_commit 14th &&
931 test_commit 15th &&
932 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
933 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
934 git notes copy --for-rewrite=foo &&
908a3203
JH
935 git log -2 >actual &&
936 test_cmp expect actual
6956f858
TR
937'
938
6956f858 939test_expect_success 'git notes copy --for-rewrite (enabled)' '
908a3203
JH
940 cat >expect <<-EOF &&
941 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
942 Author: A U Thor <author@example.com>
943 Date: Thu Apr 7 15:27:13 2005 -0700
944
945 ${indent}15th
946
947 Notes:
948 ${indent}yet another note
949 ${indent}
950 ${indent}yet another note
951
952 commit 07c85d77059393ed0154b8c96906547a59dfcddd
953 Author: A U Thor <author@example.com>
954 Date: Thu Apr 7 15:26:13 2005 -0700
955
956 ${indent}14th
957
958 Notes:
959 ${indent}other note
960 ${indent}
961 ${indent}yet another note
962 EOF
963 test_config notes.rewriteMode overwrite &&
964 test_config notes.rewriteRef "refs/notes/*" &&
6956f858
TR
965 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
966 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
967 git notes copy --for-rewrite=foo &&
908a3203
JH
968 git log -2 >actual &&
969 test_cmp expect actual
6956f858
TR
970'
971
972test_expect_success 'git notes copy --for-rewrite (disabled)' '
908a3203 973 test_config notes.rewrite.bar false &&
6956f858
TR
974 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
975 git notes copy --for-rewrite=bar &&
908a3203
JH
976 git log -2 >actual &&
977 test_cmp expect actual
6956f858
TR
978'
979
908a3203
JH
980test_expect_success 'git notes copy --for-rewrite (overwrite)' '
981 cat >expect <<-EOF &&
982 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
983 Author: A U Thor <author@example.com>
984 Date: Thu Apr 7 15:27:13 2005 -0700
6956f858 985
908a3203 986 ${indent}15th
6956f858 987
908a3203
JH
988 Notes:
989 ${indent}a fresh note
990 EOF
6956f858 991 git notes add -f -m"a fresh note" HEAD^ &&
908a3203
JH
992 test_config notes.rewriteMode overwrite &&
993 test_config notes.rewriteRef "refs/notes/*" &&
6956f858
TR
994 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
995 git notes copy --for-rewrite=foo &&
908a3203
JH
996 git log -1 >actual &&
997 test_cmp expect actual
6956f858
TR
998'
999
1000test_expect_success 'git notes copy --for-rewrite (ignore)' '
908a3203
JH
1001 test_config notes.rewriteMode ignore &&
1002 test_config notes.rewriteRef "refs/notes/*" &&
6956f858
TR
1003 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1004 git notes copy --for-rewrite=foo &&
908a3203
JH
1005 git log -1 >actual &&
1006 test_cmp expect actual
6956f858
TR
1007'
1008
6956f858 1009test_expect_success 'git notes copy --for-rewrite (append)' '
908a3203
JH
1010 cat >expect <<-EOF &&
1011 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1012 Author: A U Thor <author@example.com>
1013 Date: Thu Apr 7 15:27:13 2005 -0700
1014
1015 ${indent}15th
1016
1017 Notes:
1018 ${indent}a fresh note
1019 ${indent}
1020 ${indent}another fresh note
1021 EOF
6956f858 1022 git notes add -f -m"another fresh note" HEAD^ &&
908a3203
JH
1023 test_config notes.rewriteMode concatenate &&
1024 test_config notes.rewriteRef "refs/notes/*" &&
6956f858
TR
1025 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1026 git notes copy --for-rewrite=foo &&
908a3203
JH
1027 git log -1 >actual &&
1028 test_cmp expect actual
6956f858
TR
1029'
1030
6956f858 1031test_expect_success 'git notes copy --for-rewrite (append two to one)' '
908a3203
JH
1032 cat >expect <<-EOF &&
1033 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1034 Author: A U Thor <author@example.com>
1035 Date: Thu Apr 7 15:27:13 2005 -0700
1036
1037 ${indent}15th
1038
1039 Notes:
1040 ${indent}a fresh note
1041 ${indent}
1042 ${indent}another fresh note
1043 ${indent}
1044 ${indent}append 1
1045 ${indent}
1046 ${indent}append 2
1047 EOF
6956f858
TR
1048 git notes add -f -m"append 1" HEAD^ &&
1049 git notes add -f -m"append 2" HEAD^^ &&
908a3203
JH
1050 test_config notes.rewriteMode concatenate &&
1051 test_config notes.rewriteRef "refs/notes/*" &&
6956f858
TR
1052 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
1053 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1054 git notes copy --for-rewrite=foo &&
908a3203
JH
1055 git log -1 >actual &&
1056 test_cmp expect actual
6956f858
TR
1057'
1058
1059test_expect_success 'git notes copy --for-rewrite (append empty)' '
1060 git notes remove HEAD^ &&
908a3203
JH
1061 test_config notes.rewriteMode concatenate &&
1062 test_config notes.rewriteRef "refs/notes/*" &&
6956f858
TR
1063 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1064 git notes copy --for-rewrite=foo &&
908a3203
JH
1065 git log -1 >actual &&
1066 test_cmp expect actual
6956f858
TR
1067'
1068
6956f858 1069test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
908a3203
JH
1070 cat >expect <<-EOF &&
1071 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1072 Author: A U Thor <author@example.com>
1073 Date: Thu Apr 7 15:27:13 2005 -0700
1074
1075 ${indent}15th
1076
1077 Notes:
1078 ${indent}replacement note 1
1079 EOF
1080 test_config notes.rewriteMode concatenate &&
1081 test_config notes.rewriteRef "refs/notes/*" &&
6956f858
TR
1082 git notes add -f -m"replacement note 1" HEAD^ &&
1083 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1084 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
908a3203
JH
1085 git log -1 >actual &&
1086 test_cmp expect actual
6956f858
TR
1087'
1088
908a3203
JH
1089test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1090 cat >expect <<-EOF &&
1091 commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1092 Author: A U Thor <author@example.com>
1093 Date: Thu Apr 7 15:27:13 2005 -0700
6956f858 1094
908a3203 1095 ${indent}15th
6956f858 1096
908a3203
JH
1097 Notes:
1098 ${indent}replacement note 2
1099 EOF
6956f858 1100 git notes add -f -m"replacement note 2" HEAD^ &&
908a3203
JH
1101 test_config notes.rewriteMode overwrite &&
1102 test_unconfig notes.rewriteRef &&
6956f858
TR
1103 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1104 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1105 git notes copy --for-rewrite=foo &&
908a3203
JH
1106 git log -1 >actual &&
1107 test_cmp expect actual
6956f858
TR
1108'
1109
1110test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
6956f858 1111 git notes add -f -m"replacement note 3" HEAD^ &&
908a3203
JH
1112 test_config notes.rewriteMode overwrite &&
1113 test_config notes.rewriteRef refs/notes/other &&
6956f858
TR
1114 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1115 GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
908a3203
JH
1116 git log -1 >actual &&
1117 test_cmp expect actual
6956f858 1118'
bbb1b8a3
JK
1119
1120test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1121 test_must_fail git notes copy &&
1122 test_must_fail git notes copy one two three
1123'
1124
618cd757 1125test_expect_success 'git notes get-ref (no overrides)' '
908a3203 1126 test_unconfig core.notesRef &&
ed40ec55 1127 sane_unset GIT_NOTES_REF &&
618cd757
JH
1128 test "$(git notes get-ref)" = "refs/notes/commits"
1129'
1130
1131test_expect_success 'git notes get-ref (core.notesRef)' '
908a3203 1132 test_config core.notesRef refs/notes/foo &&
618cd757
JH
1133 test "$(git notes get-ref)" = "refs/notes/foo"
1134'
1135
1136test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
1137 test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar"
1138'
1139
1140test_expect_success 'git notes get-ref (--ref)' '
1141 test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz"
1142'
1143
d0923b6d
JH
1144test_expect_success 'setup testing of empty notes' '
1145 test_unconfig core.notesRef &&
1146 test_commit 16th &&
d73a5b93
JH
1147 empty_blob=$(git hash-object -w /dev/null) &&
1148 echo "$empty_blob" >expect_empty
d0923b6d
JH
1149'
1150
1151while read cmd
1152do
1153 test_expect_success "'git notes $cmd' removes empty note" "
1154 test_might_fail git notes remove HEAD &&
1155 MSG= git notes $cmd &&
1156 test_must_fail git notes list HEAD
1157 "
d73a5b93
JH
1158
1159 test_expect_success "'git notes $cmd --allow-empty' stores empty note" "
1160 test_might_fail git notes remove HEAD &&
1161 MSG= git notes $cmd --allow-empty &&
1162 git notes list HEAD >actual &&
1163 test_cmp expect_empty actual
1164 "
d0923b6d
JH
1165done <<\EOF
1166add
1167add -F /dev/null
1168add -m ""
1169add -c "$empty_blob"
1170add -C "$empty_blob"
1171append
1172append -F /dev/null
1173append -m ""
1174append -c "$empty_blob"
1175append -C "$empty_blob"
1176edit
1177EOF
1178
8a4acd69
JH
1179test_expect_success 'empty notes are displayed by git log' '
1180 test_commit 17th &&
1181 git log -1 >expect &&
908a3203 1182 cat >>expect <<-EOF &&
8a4acd69 1183
908a3203
JH
1184 Notes:
1185 EOF
8a4acd69
JH
1186 git notes add -C "$empty_blob" --allow-empty &&
1187 git log -1 >actual &&
1188 test_cmp expect actual
1189'
1190
65d9fb48 1191test_done