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