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