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