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