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