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