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