]>
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 | ||
908a3203 JH |
10 | write_script fake_editor <<\EOF |
11 | echo "$MSG" >"$1" | |
12 | echo "$MSG" >&2 | |
65d9fb48 | 13 | EOF |
908a3203 | 14 | GIT_EDITOR=./fake_editor |
cd067d3b | 15 | export GIT_EDITOR |
65d9fb48 | 16 | |
908a3203 JH |
17 | indent=" " |
18 | ||
65d9fb48 | 19 | test_expect_success 'cannot annotate non-existing HEAD' ' |
512477b1 | 20 | test_must_fail env MSG=3 git notes add |
65d9fb48 JS |
21 | ' |
22 | ||
908a3203 JH |
23 | test_expect_success 'setup' ' |
24 | test_commit 1st && | |
25 | test_commit 2nd | |
65d9fb48 JS |
26 | ' |
27 | ||
28 | test_expect_success 'need valid notes ref' ' | |
512477b1 DT |
29 | test_must_fail env MSG=1 GIT_NOTES_REF=/ git notes show && |
30 | test_must_fail env MSG=2 GIT_NOTES_REF=/ git notes show | |
65d9fb48 JS |
31 | ' |
32 | ||
7aa4754e | 33 | test_expect_success 'refusing to add notes in refs/heads/' ' |
512477b1 | 34 | test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add |
65d9fb48 JS |
35 | ' |
36 | ||
7aa4754e | 37 | test_expect_success 'refusing to edit notes in refs/remotes/' ' |
512477b1 | 38 | test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit |
65d9fb48 JS |
39 | ' |
40 | ||
41 | # 1 indicates caught gracefully by die, 128 means git-show barked | |
42 | test_expect_success 'handle empty notes gracefully' ' | |
0155a64e | 43 | test_expect_code 1 git notes show |
65d9fb48 JS |
44 | ' |
45 | ||
636db2c0 | 46 | test_expect_success 'show non-existent notes entry with %N' ' |
908a3203 JH |
47 | test_write_lines A B >expect && |
48 | git show -s --format="A%n%NB" >actual && | |
49 | test_cmp expect actual | |
636db2c0 JH |
50 | ' |
51 | ||
65d9fb48 | 52 | test_expect_success 'create notes' ' |
7aa4754e | 53 | MSG=b4 git notes add && |
908a3203 JH |
54 | test_path_is_missing .git/NOTES_EDITMSG && |
55 | git ls-tree -r refs/notes/commits >actual && | |
56 | test_line_count = 1 actual && | |
29a40b5a DL |
57 | echo b4 >expect && |
58 | git notes show >actual && | |
59 | test_cmp expect actual && | |
cd067d3b JH |
60 | git show HEAD^ && |
61 | test_must_fail git notes show HEAD^ | |
62 | ' | |
63 | ||
636db2c0 | 64 | test_expect_success 'show notes entry with %N' ' |
908a3203 JH |
65 | test_write_lines A b4 B >expect && |
66 | git show -s --format="A%n%NB" >actual && | |
67 | test_cmp expect actual | |
636db2c0 JH |
68 | ' |
69 | ||
b2e256b0 | 70 | test_expect_success 'create reflog entry' ' |
b408cf8c | 71 | ref=$(git rev-parse --short refs/notes/commits) && |
908a3203 | 72 | cat <<-EOF >expect && |
b408cf8c | 73 | $ref refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\'' |
908a3203 JH |
74 | EOF |
75 | git reflog show refs/notes/commits >actual && | |
76 | test_cmp expect actual | |
4d80fa8f MG |
77 | ' |
78 | ||
cd067d3b | 79 | test_expect_success 'edit existing notes' ' |
7aa4754e | 80 | MSG=b3 git notes edit && |
908a3203 JH |
81 | test_path_is_missing .git/NOTES_EDITMSG && |
82 | git ls-tree -r refs/notes/commits >actual && | |
83 | test_line_count = 1 actual && | |
29a40b5a DL |
84 | echo b3 >expect && |
85 | git notes show >actual && | |
86 | test_cmp expect actual && | |
7aa4754e JH |
87 | git show HEAD^ && |
88 | test_must_fail git notes show HEAD^ | |
89 | ' | |
90 | ||
ee76f92f | 91 | test_expect_success 'show notes from treeish' ' |
29a40b5a DL |
92 | echo b3 >expect && |
93 | git notes --ref commits^{tree} show >actual && | |
94 | test_cmp expect actual && | |
95 | ||
96 | echo b4 >expect && | |
97 | git notes --ref commits@{1} show >actual && | |
98 | test_cmp expect actual | |
ee76f92f MH |
99 | ' |
100 | ||
101 | test_expect_success 'cannot edit notes from non-ref' ' | |
102 | test_must_fail git notes --ref commits^{tree} edit && | |
103 | test_must_fail git notes --ref commits@{1} edit | |
104 | ' | |
105 | ||
84a7e35e JH |
106 | test_expect_success 'cannot "git notes add -m" where notes already exists' ' |
107 | test_must_fail git notes add -m "b2" && | |
908a3203 JH |
108 | test_path_is_missing .git/NOTES_EDITMSG && |
109 | git ls-tree -r refs/notes/commits >actual && | |
110 | test_line_count = 1 actual && | |
29a40b5a DL |
111 | echo b3 >expect && |
112 | git notes show >actual && | |
113 | test_cmp expect actual && | |
7aa4754e JH |
114 | git show HEAD^ && |
115 | test_must_fail git notes show HEAD^ | |
116 | ' | |
117 | ||
84a7e35e JH |
118 | test_expect_success 'can overwrite existing note with "git notes add -f -m"' ' |
119 | git notes add -f -m "b1" && | |
908a3203 JH |
120 | test_path_is_missing .git/NOTES_EDITMSG && |
121 | git ls-tree -r refs/notes/commits >actual && | |
122 | test_line_count = 1 actual && | |
29a40b5a DL |
123 | echo b1 >expect && |
124 | git notes show >actual && | |
125 | test_cmp expect actual && | |
84a7e35e JH |
126 | git show HEAD^ && |
127 | test_must_fail git notes show HEAD^ | |
128 | ' | |
129 | ||
130 | test_expect_success 'add w/no options on existing note morphs into edit' ' | |
131 | MSG=b2 git notes add && | |
908a3203 JH |
132 | test_path_is_missing .git/NOTES_EDITMSG && |
133 | git ls-tree -r refs/notes/commits >actual && | |
134 | test_line_count = 1 actual && | |
29a40b5a DL |
135 | echo b2 >expect && |
136 | git notes show >actual && | |
137 | test_cmp expect actual && | |
84a7e35e JH |
138 | git show HEAD^ && |
139 | test_must_fail git notes show HEAD^ | |
140 | ' | |
141 | ||
7aa4754e JH |
142 | test_expect_success 'can overwrite existing note with "git notes add -f"' ' |
143 | MSG=b1 git notes add -f && | |
908a3203 JH |
144 | test_path_is_missing .git/NOTES_EDITMSG && |
145 | git ls-tree -r refs/notes/commits >actual && | |
146 | test_line_count = 1 actual && | |
29a40b5a DL |
147 | echo b1 >expect && |
148 | git notes show >actual && | |
149 | test_cmp expect actual && | |
65d9fb48 JS |
150 | git show HEAD^ && |
151 | test_must_fail git notes show HEAD^ | |
152 | ' | |
153 | ||
908a3203 | 154 | test_expect_success 'show notes' ' |
b408cf8c | 155 | commit=$(git rev-parse HEAD) && |
908a3203 | 156 | cat >expect <<-EOF && |
b408cf8c | 157 | commit $commit |
908a3203 JH |
158 | Author: A U Thor <author@example.com> |
159 | Date: Thu Apr 7 15:14:13 2005 -0700 | |
65d9fb48 | 160 | |
908a3203 | 161 | ${indent}2nd |
65d9fb48 | 162 | |
908a3203 JH |
163 | Notes: |
164 | ${indent}b1 | |
165 | EOF | |
29a40b5a DL |
166 | git cat-file commit HEAD >commits && |
167 | ! grep b1 commits && | |
908a3203 JH |
168 | git log -1 >actual && |
169 | test_cmp expect actual | |
65d9fb48 JS |
170 | ' |
171 | ||
908a3203 JH |
172 | test_expect_success 'show multi-line notes' ' |
173 | test_commit 3rd && | |
174 | MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add && | |
b408cf8c | 175 | commit=$(git rev-parse HEAD) && |
908a3203 | 176 | cat >expect-multiline <<-EOF && |
b408cf8c | 177 | commit $commit |
908a3203 JH |
178 | Author: A U Thor <author@example.com> |
179 | Date: Thu Apr 7 15:15:13 2005 -0700 | |
65d9fb48 | 180 | |
908a3203 | 181 | ${indent}3rd |
65d9fb48 | 182 | |
908a3203 JH |
183 | Notes: |
184 | ${indent}b3 | |
185 | ${indent}c3c3c3c3 | |
186 | ${indent}d3d3d3 | |
65d9fb48 | 187 | |
908a3203 JH |
188 | EOF |
189 | cat expect >>expect-multiline && | |
190 | git log -2 >actual && | |
191 | test_cmp expect-multiline actual | |
65d9fb48 | 192 | ' |
d9246d43 | 193 | |
908a3203 JH |
194 | test_expect_success 'show -F notes' ' |
195 | test_commit 4th && | |
196 | echo "xyzzy" >note5 && | |
197 | git notes add -F note5 && | |
b408cf8c | 198 | commit=$(git rev-parse HEAD) && |
908a3203 | 199 | cat >expect-F <<-EOF && |
b408cf8c | 200 | commit $commit |
908a3203 JH |
201 | Author: A U Thor <author@example.com> |
202 | Date: Thu Apr 7 15:16:13 2005 -0700 | |
d9246d43 | 203 | |
908a3203 | 204 | ${indent}4th |
d9246d43 | 205 | |
908a3203 JH |
206 | Notes: |
207 | ${indent}xyzzy | |
d9246d43 | 208 | |
908a3203 JH |
209 | EOF |
210 | cat expect-multiline >>expect-F && | |
211 | git log -3 >actual && | |
212 | test_cmp expect-F actual | |
d9246d43 | 213 | ' |
65d9fb48 | 214 | |
84a7e35e | 215 | test_expect_success 'Re-adding -F notes without -f fails' ' |
908a3203 | 216 | echo "zyxxy" >note5 && |
84a7e35e | 217 | test_must_fail git notes add -F note5 && |
908a3203 JH |
218 | git log -3 >actual && |
219 | test_cmp expect-F actual | |
84a7e35e JH |
220 | ' |
221 | ||
66b2ed09 | 222 | test_expect_success 'git log --pretty=raw does not show notes' ' |
b408cf8c | 223 | commit=$(git rev-parse HEAD) && |
224 | tree=$(git rev-parse HEAD^{tree}) && | |
225 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 226 | cat >expect <<-EOF && |
b408cf8c | 227 | commit $commit |
228 | tree $tree | |
229 | parent $parent | |
908a3203 JH |
230 | author A U Thor <author@example.com> 1112912173 -0700 |
231 | committer C O Mitter <committer@example.com> 1112912173 -0700 | |
232 | ||
233 | ${indent}4th | |
234 | EOF | |
235 | git log -1 --pretty=raw >actual && | |
236 | test_cmp expect actual | |
66b2ed09 JH |
237 | ' |
238 | ||
66b2ed09 | 239 | test_expect_success 'git log --show-notes' ' |
908a3203 JH |
240 | cat >>expect <<-EOF && |
241 | ||
242 | Notes: | |
243 | ${indent}xyzzy | |
244 | EOF | |
245 | git log -1 --pretty=raw --show-notes >actual && | |
246 | test_cmp expect actual | |
66b2ed09 JH |
247 | ' |
248 | ||
249 | test_expect_success 'git log --no-notes' ' | |
908a3203 JH |
250 | git log -1 --no-notes >actual && |
251 | ! grep xyzzy actual | |
66b2ed09 JH |
252 | ' |
253 | ||
254 | test_expect_success 'git format-patch does not show notes' ' | |
908a3203 JH |
255 | git format-patch -1 --stdout >actual && |
256 | ! grep xyzzy actual | |
66b2ed09 JH |
257 | ' |
258 | ||
259 | test_expect_success 'git format-patch --show-notes does show notes' ' | |
908a3203 JH |
260 | git format-patch --show-notes -1 --stdout >actual && |
261 | grep xyzzy actual | |
66b2ed09 JH |
262 | ' |
263 | ||
7dccadf3 JH |
264 | for pretty in \ |
265 | "" --pretty --pretty=raw --pretty=short --pretty=medium \ | |
266 | --pretty=full --pretty=fuller --pretty=format:%s --oneline | |
66b2ed09 JH |
267 | do |
268 | case "$pretty" in | |
269 | "") p= not= negate="" ;; | |
7dccadf3 | 270 | ?*) p="$pretty" not=" not" negate="!" ;; |
66b2ed09 JH |
271 | esac |
272 | test_expect_success "git show $pretty does$not show notes" ' | |
908a3203 JH |
273 | git show $p >actual && |
274 | eval "$negate grep xyzzy actual" | |
66b2ed09 JH |
275 | ' |
276 | done | |
277 | ||
7249e912 JK |
278 | test_expect_success 'setup alternate notes ref' ' |
279 | git notes --ref=alternate add -m alternate | |
280 | ' | |
281 | ||
282 | test_expect_success 'git log --notes shows default notes' ' | |
908a3203 JH |
283 | git log -1 --notes >actual && |
284 | grep xyzzy actual && | |
285 | ! grep alternate actual | |
7249e912 JK |
286 | ' |
287 | ||
288 | test_expect_success 'git log --notes=X shows only X' ' | |
908a3203 JH |
289 | git log -1 --notes=alternate >actual && |
290 | ! grep xyzzy actual && | |
291 | grep alternate actual | |
7249e912 JK |
292 | ' |
293 | ||
294 | test_expect_success 'git log --notes --notes=X shows both' ' | |
908a3203 JH |
295 | git log -1 --notes --notes=alternate >actual && |
296 | grep xyzzy actual && | |
297 | grep alternate actual | |
7249e912 JK |
298 | ' |
299 | ||
92e0d425 JK |
300 | test_expect_success 'git log --no-notes resets default state' ' |
301 | git log -1 --notes --notes=alternate \ | |
302 | --no-notes --notes=alternate \ | |
908a3203 JH |
303 | >actual && |
304 | ! grep xyzzy actual && | |
305 | grep alternate actual | |
92e0d425 JK |
306 | ' |
307 | ||
308 | test_expect_success 'git log --no-notes resets ref list' ' | |
309 | git log -1 --notes --notes=alternate \ | |
310 | --no-notes --notes \ | |
908a3203 JH |
311 | >actual && |
312 | grep xyzzy actual && | |
313 | ! grep alternate actual | |
cd067d3b JH |
314 | ' |
315 | ||
908a3203 JH |
316 | test_expect_success 'show -m notes' ' |
317 | test_commit 5th && | |
318 | git notes add -m spam -m "foo${LF}bar${LF}baz" && | |
b408cf8c | 319 | commit=$(git rev-parse HEAD) && |
908a3203 | 320 | cat >expect-m <<-EOF && |
b408cf8c | 321 | commit $commit |
908a3203 JH |
322 | Author: A U Thor <author@example.com> |
323 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
324 | ||
325 | ${indent}5th | |
326 | ||
327 | Notes: | |
328 | ${indent}spam | |
329 | ${indent} | |
330 | ${indent}foo | |
331 | ${indent}bar | |
332 | ${indent}baz | |
333 | ||
334 | EOF | |
335 | cat expect-F >>expect-m && | |
336 | git log -4 >actual && | |
337 | test_cmp expect-m actual | |
338 | ' | |
339 | ||
340 | test_expect_success 'remove note with add -f -F /dev/null' ' | |
341 | git notes add -f -F /dev/null && | |
b408cf8c | 342 | commit=$(git rev-parse HEAD) && |
908a3203 | 343 | cat >expect-rm-F <<-EOF && |
b408cf8c | 344 | commit $commit |
908a3203 JH |
345 | Author: A U Thor <author@example.com> |
346 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
347 | ||
348 | ${indent}5th | |
349 | ||
350 | EOF | |
351 | cat expect-F >>expect-rm-F && | |
352 | git log -4 >actual && | |
353 | test_cmp expect-rm-F actual && | |
ce14e0b2 | 354 | test_must_fail git notes show |
a0b4dfa9 JH |
355 | ' |
356 | ||
908a3203 JH |
357 | test_expect_success 'do not create empty note with -m ""' ' |
358 | git notes add -m "" && | |
359 | git log -4 >actual && | |
360 | test_cmp expect-rm-F actual && | |
ce14e0b2 | 361 | test_must_fail git notes show |
a0b4dfa9 JH |
362 | ' |
363 | ||
908a3203 JH |
364 | test_expect_success 'create note with combination of -m and -F' ' |
365 | cat >expect-combine_m_and_F <<-EOF && | |
366 | foo | |
348f199b | 367 | |
908a3203 | 368 | xyzzy |
348f199b | 369 | |
908a3203 | 370 | bar |
348f199b | 371 | |
908a3203 | 372 | zyxxy |
348f199b | 373 | |
908a3203 JH |
374 | baz |
375 | EOF | |
376 | echo "xyzzy" >note_a && | |
377 | echo "zyxxy" >note_b && | |
348f199b | 378 | git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" && |
908a3203 JH |
379 | git notes show >actual && |
380 | test_cmp expect-combine_m_and_F actual | |
348f199b JH |
381 | ' |
382 | ||
908a3203 | 383 | test_expect_success 'remove note with "git notes remove"' ' |
348f199b | 384 | git notes remove HEAD^ && |
908a3203 | 385 | git notes remove && |
b408cf8c | 386 | commit=$(git rev-parse HEAD) && |
387 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 388 | cat >expect-rm-remove <<-EOF && |
b408cf8c | 389 | commit $commit |
908a3203 JH |
390 | Author: A U Thor <author@example.com> |
391 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
92b3385f | 392 | |
908a3203 | 393 | ${indent}5th |
92b3385f | 394 | |
b408cf8c | 395 | commit $parent |
908a3203 JH |
396 | Author: A U Thor <author@example.com> |
397 | Date: Thu Apr 7 15:16:13 2005 -0700 | |
92b3385f | 398 | |
908a3203 | 399 | ${indent}4th |
92b3385f | 400 | |
908a3203 JH |
401 | EOF |
402 | cat expect-multiline >>expect-rm-remove && | |
403 | git log -4 >actual && | |
404 | test_cmp expect-rm-remove actual && | |
ce14e0b2 | 405 | test_must_fail git notes show HEAD^ |
92b3385f JH |
406 | ' |
407 | ||
1ee1e43d | 408 | test_expect_success 'removing non-existing note should not create new commit' ' |
908a3203 | 409 | git rev-parse --verify refs/notes/commits >before_commit && |
1ee1e43d | 410 | test_must_fail git notes remove HEAD^ && |
908a3203 | 411 | git rev-parse --verify refs/notes/commits >after_commit && |
1ee1e43d JH |
412 | test_cmp before_commit after_commit |
413 | ' | |
414 | ||
c3ab1a8e JH |
415 | test_expect_success 'removing more than one' ' |
416 | before=$(git rev-parse --verify refs/notes/commits) && | |
417 | test_when_finished "git update-ref refs/notes/commits $before" && | |
418 | ||
419 | # We have only two -- add another and make sure it stays | |
420 | git notes add -m "extra" && | |
421 | git notes list HEAD >after-removal-expect && | |
422 | git notes remove HEAD^^ HEAD^^^ && | |
423 | git notes list | sed -e "s/ .*//" >actual && | |
424 | test_cmp after-removal-expect actual | |
425 | ' | |
426 | ||
427 | test_expect_success 'removing is atomic' ' | |
428 | before=$(git rev-parse --verify refs/notes/commits) && | |
429 | test_when_finished "git update-ref refs/notes/commits $before" && | |
430 | test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ && | |
431 | after=$(git rev-parse --verify refs/notes/commits) && | |
432 | test "$before" = "$after" | |
433 | ' | |
434 | ||
2d370d2f JH |
435 | test_expect_success 'removing with --ignore-missing' ' |
436 | before=$(git rev-parse --verify refs/notes/commits) && | |
437 | test_when_finished "git update-ref refs/notes/commits $before" && | |
438 | ||
439 | # We have only two -- add another and make sure it stays | |
440 | git notes add -m "extra" && | |
441 | git notes list HEAD >after-removal-expect && | |
442 | git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ && | |
443 | git notes list | sed -e "s/ .*//" >actual && | |
444 | test_cmp after-removal-expect actual | |
445 | ' | |
446 | ||
447 | test_expect_success 'removing with --ignore-missing but bogus ref' ' | |
448 | before=$(git rev-parse --verify refs/notes/commits) && | |
449 | test_when_finished "git update-ref refs/notes/commits $before" && | |
450 | test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT && | |
451 | after=$(git rev-parse --verify refs/notes/commits) && | |
452 | test "$before" = "$after" | |
453 | ' | |
454 | ||
46538012 JH |
455 | test_expect_success 'remove reads from --stdin' ' |
456 | before=$(git rev-parse --verify refs/notes/commits) && | |
457 | test_when_finished "git update-ref refs/notes/commits $before" && | |
458 | ||
459 | # We have only two -- add another and make sure it stays | |
460 | git notes add -m "extra" && | |
461 | git notes list HEAD >after-removal-expect && | |
462 | git rev-parse HEAD^^ HEAD^^^ >input && | |
463 | git notes remove --stdin <input && | |
464 | git notes list | sed -e "s/ .*//" >actual && | |
465 | test_cmp after-removal-expect actual | |
466 | ' | |
467 | ||
468 | test_expect_success 'remove --stdin is also atomic' ' | |
469 | before=$(git rev-parse --verify refs/notes/commits) && | |
470 | test_when_finished "git update-ref refs/notes/commits $before" && | |
471 | git rev-parse HEAD^^ HEAD^^^ HEAD^ >input && | |
472 | test_must_fail git notes remove --stdin <input && | |
473 | after=$(git rev-parse --verify refs/notes/commits) && | |
474 | test "$before" = "$after" | |
475 | ' | |
476 | ||
477 | test_expect_success 'removing with --stdin --ignore-missing' ' | |
478 | before=$(git rev-parse --verify refs/notes/commits) && | |
479 | test_when_finished "git update-ref refs/notes/commits $before" && | |
480 | ||
481 | # We have only two -- add another and make sure it stays | |
482 | git notes add -m "extra" && | |
483 | git notes list HEAD >after-removal-expect && | |
484 | git rev-parse HEAD^^ HEAD^^^ HEAD^ >input && | |
485 | git notes remove --ignore-missing --stdin <input && | |
486 | git notes list | sed -e "s/ .*//" >actual && | |
487 | test_cmp after-removal-expect actual | |
488 | ' | |
489 | ||
e397421a | 490 | test_expect_success 'list notes with "git notes list"' ' |
b408cf8c | 491 | commit_2=$(git rev-parse 2nd) && |
492 | commit_3=$(git rev-parse 3rd) && | |
29a40b5a DL |
493 | note_2=$(git rev-parse refs/notes/commits:$commit_2) && |
494 | note_3=$(git rev-parse refs/notes/commits:$commit_3) && | |
b408cf8c | 495 | sort -t" " -k2 >expect <<-EOF && |
29a40b5a DL |
496 | $note_2 $commit_2 |
497 | $note_3 $commit_3 | |
908a3203 JH |
498 | EOF |
499 | git notes list >actual && | |
500 | test_cmp expect actual | |
e397421a JH |
501 | ' |
502 | ||
503 | test_expect_success 'list notes with "git notes"' ' | |
908a3203 JH |
504 | git notes >actual && |
505 | test_cmp expect actual | |
e397421a JH |
506 | ' |
507 | ||
9e4658d5 SG |
508 | test_expect_success '"git notes" without subcommand does not take arguments' ' |
509 | test_expect_code 129 git notes HEAD^^ 2>err && | |
510 | grep "^error: unknown subcommand" err | |
511 | ' | |
512 | ||
e397421a | 513 | test_expect_success 'list specific note with "git notes list <object>"' ' |
29a40b5a | 514 | git rev-parse refs/notes/commits:$commit_3 >expect && |
908a3203 JH |
515 | git notes list HEAD^^ >actual && |
516 | test_cmp expect actual | |
e397421a JH |
517 | ' |
518 | ||
e397421a | 519 | test_expect_success 'listing non-existing notes fails' ' |
908a3203 | 520 | test_must_fail git notes list HEAD >actual && |
1c5e94f4 | 521 | test_must_be_empty actual |
e397421a JH |
522 | ' |
523 | ||
2347fae5 | 524 | test_expect_success 'append to existing note with "git notes append"' ' |
908a3203 JH |
525 | cat >expect <<-EOF && |
526 | Initial set of notes | |
527 | ||
528 | More notes appended with git notes append | |
529 | EOF | |
2347fae5 JH |
530 | git notes add -m "Initial set of notes" && |
531 | git notes append -m "More notes appended with git notes append" && | |
908a3203 JH |
532 | git notes show >actual && |
533 | test_cmp expect actual | |
2347fae5 JH |
534 | ' |
535 | ||
74884b52 | 536 | test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' |
b408cf8c | 537 | commit_5=$(git rev-parse 5th) && |
29a40b5a | 538 | note_5=$(git rev-parse refs/notes/commits:$commit_5) && |
b408cf8c | 539 | sort -t" " -k2 >expect_list <<-EOF && |
29a40b5a DL |
540 | $note_2 $commit_2 |
541 | $note_3 $commit_3 | |
542 | $note_5 $commit_5 | |
908a3203 JH |
543 | EOF |
544 | git notes list >actual && | |
545 | test_cmp expect_list actual | |
74884b52 SB |
546 | ' |
547 | ||
2347fae5 JH |
548 | test_expect_success 'appending empty string does not change existing note' ' |
549 | git notes append -m "" && | |
908a3203 JH |
550 | git notes show >actual && |
551 | test_cmp expect actual | |
2347fae5 JH |
552 | ' |
553 | ||
554 | test_expect_success 'git notes append == add when there is no existing note' ' | |
555 | git notes remove HEAD && | |
556 | test_must_fail git notes list HEAD && | |
908a3203 JH |
557 | git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" && |
558 | git notes show >actual && | |
559 | test_cmp expect actual | |
2347fae5 JH |
560 | ' |
561 | ||
562 | test_expect_success 'appending empty string to non-existing note does not create note' ' | |
563 | git notes remove HEAD && | |
564 | test_must_fail git notes list HEAD && | |
565 | git notes append -m "" && | |
566 | test_must_fail git notes list HEAD | |
567 | ' | |
568 | ||
cd067d3b | 569 | test_expect_success 'create other note on a different notes ref (setup)' ' |
908a3203 JH |
570 | test_commit 6th && |
571 | GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" && | |
b408cf8c | 572 | commit=$(git rev-parse HEAD) && |
908a3203 | 573 | cat >expect-not-other <<-EOF && |
b408cf8c | 574 | commit $commit |
908a3203 JH |
575 | Author: A U Thor <author@example.com> |
576 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
cd067d3b | 577 | |
908a3203 JH |
578 | ${indent}6th |
579 | EOF | |
580 | cp expect-not-other expect-other && | |
581 | cat >>expect-other <<-EOF | |
cd067d3b | 582 | |
908a3203 JH |
583 | Notes (other): |
584 | ${indent}other note | |
585 | EOF | |
586 | ' | |
3b78cdbe JH |
587 | |
588 | test_expect_success 'Do not show note on other ref by default' ' | |
908a3203 JH |
589 | git log -1 >actual && |
590 | test_cmp expect-not-other actual | |
3b78cdbe JH |
591 | ' |
592 | ||
593 | test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' ' | |
908a3203 JH |
594 | GIT_NOTES_REF="refs/notes/other" git log -1 >actual && |
595 | test_cmp expect-other actual | |
3b78cdbe JH |
596 | ' |
597 | ||
598 | test_expect_success 'Do show note when ref is given in core.notesRef config' ' | |
908a3203 JH |
599 | test_config core.notesRef "refs/notes/other" && |
600 | git log -1 >actual && | |
601 | test_cmp expect-other actual | |
3b78cdbe JH |
602 | ' |
603 | ||
604 | test_expect_success 'Do not show note when core.notesRef is overridden' ' | |
908a3203 JH |
605 | test_config core.notesRef "refs/notes/other" && |
606 | GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual && | |
607 | test_cmp expect-not-other actual | |
3b78cdbe JH |
608 | ' |
609 | ||
908a3203 | 610 | test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' ' |
b408cf8c | 611 | commit=$(git rev-parse HEAD) && |
612 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 613 | cat >expect-both <<-EOF && |
b408cf8c | 614 | commit $commit |
908a3203 JH |
615 | Author: A U Thor <author@example.com> |
616 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 617 | |
908a3203 | 618 | ${indent}6th |
894a9d33 | 619 | |
908a3203 JH |
620 | Notes: |
621 | ${indent}order test | |
894a9d33 | 622 | |
908a3203 JH |
623 | Notes (other): |
624 | ${indent}other note | |
894a9d33 | 625 | |
b408cf8c | 626 | commit $parent |
908a3203 JH |
627 | Author: A U Thor <author@example.com> |
628 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
894a9d33 | 629 | |
908a3203 | 630 | ${indent}5th |
894a9d33 | 631 | |
908a3203 JH |
632 | Notes: |
633 | ${indent}replacement for deleted note | |
634 | EOF | |
894a9d33 TR |
635 | GIT_NOTES_REF=refs/notes/commits git notes add \ |
636 | -m"replacement for deleted note" HEAD^ && | |
637 | GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" && | |
908a3203 JH |
638 | test_unconfig core.notesRef && |
639 | test_config notes.displayRef "refs/notes/*" && | |
640 | git log -2 >actual && | |
641 | test_cmp expect-both actual | |
894a9d33 TR |
642 | ' |
643 | ||
644 | test_expect_success 'core.notesRef is implicitly in notes.displayRef' ' | |
908a3203 JH |
645 | test_config core.notesRef refs/notes/commits && |
646 | test_config notes.displayRef refs/notes/other && | |
647 | git log -2 >actual && | |
648 | test_cmp expect-both actual | |
894a9d33 TR |
649 | ' |
650 | ||
651 | test_expect_success 'notes.displayRef can be given more than once' ' | |
908a3203 JH |
652 | test_unconfig core.notesRef && |
653 | test_config notes.displayRef refs/notes/commits && | |
894a9d33 | 654 | git config --add notes.displayRef refs/notes/other && |
908a3203 JH |
655 | git log -2 >actual && |
656 | test_cmp expect-both actual | |
894a9d33 TR |
657 | ' |
658 | ||
908a3203 | 659 | test_expect_success 'notes.displayRef respects order' ' |
b408cf8c | 660 | commit=$(git rev-parse HEAD) && |
908a3203 | 661 | cat >expect-both-reversed <<-EOF && |
b408cf8c | 662 | commit $commit |
908a3203 JH |
663 | Author: A U Thor <author@example.com> |
664 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 665 | |
908a3203 | 666 | ${indent}6th |
894a9d33 | 667 | |
908a3203 JH |
668 | Notes (other): |
669 | ${indent}other note | |
894a9d33 | 670 | |
908a3203 JH |
671 | Notes: |
672 | ${indent}order test | |
673 | EOF | |
674 | test_config core.notesRef refs/notes/other && | |
675 | test_config notes.displayRef refs/notes/commits && | |
676 | git log -1 >actual && | |
677 | test_cmp expect-both-reversed actual | |
894a9d33 TR |
678 | ' |
679 | ||
45fef159 NA |
680 | test_expect_success 'notes.displayRef with no value handled gracefully' ' |
681 | test_must_fail git -c notes.displayRef log -0 --notes && | |
682 | test_must_fail git -c notes.displayRef diff-tree --notes HEAD | |
683 | ' | |
684 | ||
894a9d33 | 685 | test_expect_success 'GIT_NOTES_DISPLAY_REF works' ' |
894a9d33 | 686 | GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \ |
908a3203 JH |
687 | git log -2 >actual && |
688 | test_cmp expect-both actual | |
894a9d33 TR |
689 | ' |
690 | ||
908a3203 | 691 | test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' ' |
b408cf8c | 692 | commit=$(git rev-parse HEAD) && |
693 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 694 | cat >expect-none <<-EOF && |
b408cf8c | 695 | commit $commit |
908a3203 JH |
696 | Author: A U Thor <author@example.com> |
697 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 698 | |
908a3203 | 699 | ${indent}6th |
894a9d33 | 700 | |
b408cf8c | 701 | commit $parent |
908a3203 JH |
702 | Author: A U Thor <author@example.com> |
703 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
894a9d33 | 704 | |
908a3203 JH |
705 | ${indent}5th |
706 | EOF | |
707 | test_config notes.displayRef "refs/notes/*" && | |
708 | GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual && | |
709 | test_cmp expect-none actual | |
894a9d33 TR |
710 | ' |
711 | ||
712 | test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' ' | |
908a3203 JH |
713 | GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual && |
714 | test_cmp expect-both actual | |
894a9d33 TR |
715 | ' |
716 | ||
908a3203 | 717 | test_expect_success '--no-standard-notes' ' |
b408cf8c | 718 | commit=$(git rev-parse HEAD) && |
85cb1d0b | 719 | cat >expect-commits <<-EOF && |
b408cf8c | 720 | commit $commit |
908a3203 JH |
721 | Author: A U Thor <author@example.com> |
722 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 723 | |
908a3203 | 724 | ${indent}6th |
894a9d33 | 725 | |
908a3203 JH |
726 | Notes: |
727 | ${indent}order test | |
728 | EOF | |
729 | git log --no-standard-notes --show-notes=commits -1 >actual && | |
730 | test_cmp expect-commits actual | |
894a9d33 TR |
731 | ' |
732 | ||
733 | test_expect_success '--standard-notes' ' | |
908a3203 | 734 | test_config notes.displayRef "refs/notes/*" && |
894a9d33 | 735 | git log --no-standard-notes --show-notes=commits \ |
908a3203 JH |
736 | --standard-notes -2 >actual && |
737 | test_cmp expect-both actual | |
894a9d33 TR |
738 | ' |
739 | ||
740 | test_expect_success '--show-notes=ref accumulates' ' | |
741 | git log --show-notes=other --show-notes=commits \ | |
908a3203 JH |
742 | --no-standard-notes -1 >actual && |
743 | test_cmp expect-both-reversed actual | |
894a9d33 TR |
744 | ' |
745 | ||
b24bb997 | 746 | test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' |
908a3203 JH |
747 | test_config core.notesRef refs/notes/other && |
748 | echo "Note on a tree" >expect && | |
7aa4754e | 749 | git notes add -m "Note on a tree" HEAD: && |
908a3203 | 750 | git notes show HEAD: >actual && |
b24bb997 | 751 | test_cmp expect actual && |
908a3203 | 752 | echo "Note on a blob" >expect && |
29a40b5a DL |
753 | git ls-tree --name-only HEAD >files && |
754 | filename=$(head -n1 files) && | |
7aa4754e | 755 | git notes add -m "Note on a blob" HEAD:$filename && |
908a3203 | 756 | git notes show HEAD:$filename >actual && |
b24bb997 | 757 | test_cmp expect actual && |
908a3203 | 758 | echo "Note on a tag" >expect && |
b24bb997 | 759 | git tag -a -m "This is an annotated tag" foobar HEAD^ && |
7aa4754e | 760 | git notes add -m "Note on a tag" foobar && |
908a3203 | 761 | git notes show foobar >actual && |
b24bb997 JH |
762 | test_cmp expect actual |
763 | ' | |
764 | ||
908a3203 | 765 | test_expect_success 'create note from other note with "git notes add -C"' ' |
b408cf8c | 766 | test_commit 7th && |
767 | commit=$(git rev-parse HEAD) && | |
908a3203 | 768 | cat >expect <<-EOF && |
b408cf8c | 769 | commit $commit |
908a3203 JH |
770 | Author: A U Thor <author@example.com> |
771 | Date: Thu Apr 7 15:19:13 2005 -0700 | |
0691cff7 | 772 | |
908a3203 | 773 | ${indent}7th |
0691cff7 | 774 | |
908a3203 JH |
775 | Notes: |
776 | ${indent}order test | |
777 | EOF | |
29a40b5a DL |
778 | note=$(git notes list HEAD^) && |
779 | git notes add -C $note && | |
908a3203 | 780 | git log -1 >actual && |
0691cff7 | 781 | test_cmp expect actual && |
29a40b5a DL |
782 | git notes list HEAD^ >expect && |
783 | git notes list HEAD >actual && | |
784 | test_cmp expect actual | |
0691cff7 JH |
785 | ' |
786 | ||
787 | test_expect_success 'create note from non-existing note with "git notes add -C" fails' ' | |
908a3203 | 788 | test_commit 8th && |
0691cff7 JH |
789 | test_must_fail git notes add -C deadbeef && |
790 | test_must_fail git notes list HEAD | |
791 | ' | |
792 | ||
ce8daa1e JH |
793 | test_expect_success 'create note from non-blob with "git notes add -C" fails' ' |
794 | commit=$(git rev-parse --verify HEAD) && | |
795 | tree=$(git rev-parse --verify HEAD:) && | |
796 | test_must_fail git notes add -C $commit && | |
797 | test_must_fail git notes add -C $tree && | |
798 | test_must_fail git notes list HEAD | |
799 | ' | |
800 | ||
908a3203 | 801 | test_expect_success 'create note from blob with "git notes add -C" reuses blob id' ' |
b408cf8c | 802 | commit=$(git rev-parse HEAD) && |
908a3203 | 803 | cat >expect <<-EOF && |
b408cf8c | 804 | commit $commit |
908a3203 JH |
805 | Author: A U Thor <author@example.com> |
806 | Date: Thu Apr 7 15:20:13 2005 -0700 | |
ce8daa1e | 807 | |
908a3203 | 808 | ${indent}8th |
ce8daa1e | 809 | |
908a3203 JH |
810 | Notes: |
811 | ${indent}This is a blob object | |
812 | EOF | |
29a40b5a DL |
813 | echo "This is a blob object" | git hash-object -w --stdin >blob && |
814 | git notes add -C $(cat blob) && | |
908a3203 | 815 | git log -1 >actual && |
ce8daa1e | 816 | test_cmp expect actual && |
29a40b5a DL |
817 | git notes list HEAD >actual && |
818 | test_cmp blob actual | |
ce8daa1e JH |
819 | ' |
820 | ||
908a3203 | 821 | test_expect_success 'create note from other note with "git notes add -c"' ' |
b408cf8c | 822 | test_commit 9th && |
823 | commit=$(git rev-parse HEAD) && | |
908a3203 | 824 | cat >expect <<-EOF && |
b408cf8c | 825 | commit $commit |
908a3203 JH |
826 | Author: A U Thor <author@example.com> |
827 | Date: Thu Apr 7 15:21:13 2005 -0700 | |
0691cff7 | 828 | |
908a3203 | 829 | ${indent}9th |
0691cff7 | 830 | |
908a3203 JH |
831 | Notes: |
832 | ${indent}yet another note | |
833 | EOF | |
29a40b5a DL |
834 | note=$(git notes list HEAD^^) && |
835 | MSG="yet another note" git notes add -c $note && | |
908a3203 | 836 | git log -1 >actual && |
0691cff7 JH |
837 | test_cmp expect actual |
838 | ' | |
839 | ||
840 | test_expect_success 'create note from non-existing note with "git notes add -c" fails' ' | |
908a3203 | 841 | test_commit 10th && |
512477b1 | 842 | test_must_fail env MSG="yet another note" git notes add -c deadbeef && |
0691cff7 JH |
843 | test_must_fail git notes list HEAD |
844 | ' | |
845 | ||
0691cff7 | 846 | test_expect_success 'append to note from other note with "git notes append -C"' ' |
b408cf8c | 847 | commit=$(git rev-parse HEAD^) && |
908a3203 | 848 | cat >expect <<-EOF && |
b408cf8c | 849 | commit $commit |
908a3203 JH |
850 | Author: A U Thor <author@example.com> |
851 | Date: Thu Apr 7 15:21:13 2005 -0700 | |
852 | ||
853 | ${indent}9th | |
854 | ||
855 | Notes: | |
856 | ${indent}yet another note | |
857 | ${indent} | |
858 | ${indent}yet another note | |
859 | EOF | |
29a40b5a DL |
860 | note=$(git notes list HEAD^) && |
861 | git notes append -C $note HEAD^ && | |
908a3203 | 862 | git log -1 HEAD^ >actual && |
0691cff7 JH |
863 | test_cmp expect actual |
864 | ' | |
865 | ||
908a3203 | 866 | test_expect_success 'create note from other note with "git notes append -c"' ' |
b408cf8c | 867 | commit=$(git rev-parse HEAD) && |
908a3203 | 868 | cat >expect <<-EOF && |
b408cf8c | 869 | commit $commit |
908a3203 JH |
870 | Author: A U Thor <author@example.com> |
871 | Date: Thu Apr 7 15:22:13 2005 -0700 | |
0691cff7 | 872 | |
908a3203 | 873 | ${indent}10th |
0691cff7 | 874 | |
908a3203 JH |
875 | Notes: |
876 | ${indent}other note | |
877 | EOF | |
29a40b5a DL |
878 | note=$(git notes list HEAD^) && |
879 | MSG="other note" git notes append -c $note && | |
908a3203 | 880 | git log -1 >actual && |
0691cff7 JH |
881 | test_cmp expect actual |
882 | ' | |
883 | ||
0691cff7 | 884 | test_expect_success 'append to note from other note with "git notes append -c"' ' |
b408cf8c | 885 | commit=$(git rev-parse HEAD) && |
908a3203 | 886 | cat >expect <<-EOF && |
b408cf8c | 887 | commit $commit |
908a3203 JH |
888 | Author: A U Thor <author@example.com> |
889 | Date: Thu Apr 7 15:22:13 2005 -0700 | |
890 | ||
891 | ${indent}10th | |
892 | ||
893 | Notes: | |
894 | ${indent}other note | |
895 | ${indent} | |
896 | ${indent}yet another note | |
897 | EOF | |
29a40b5a DL |
898 | note=$(git notes list HEAD) && |
899 | MSG="yet another note" git notes append -c $note && | |
908a3203 | 900 | git log -1 >actual && |
0691cff7 JH |
901 | test_cmp expect actual |
902 | ' | |
903 | ||
e73bbd96 | 904 | test_expect_success 'copy note with "git notes copy"' ' |
d58deb9c ĐTCD |
905 | commit=$(git rev-parse 4th) && |
906 | cat >expect <<-EOF && | |
907 | commit $commit | |
908 | Author: A U Thor <author@example.com> | |
909 | Date: Thu Apr 7 15:16:13 2005 -0700 | |
910 | ||
911 | ${indent}4th | |
912 | ||
913 | Notes: | |
914 | ${indent}This is a blob object | |
915 | EOF | |
916 | git notes copy 8th 4th && | |
917 | git log 3rd..4th >actual && | |
918 | test_cmp expect actual && | |
29a40b5a DL |
919 | git notes list 4th >expect && |
920 | git notes list 8th >actual && | |
921 | test_cmp expect actual | |
d58deb9c ĐTCD |
922 | ' |
923 | ||
924 | test_expect_success 'copy note with "git notes copy" with default' ' | |
b408cf8c | 925 | test_commit 11th && |
926 | commit=$(git rev-parse HEAD) && | |
908a3203 | 927 | cat >expect <<-EOF && |
b408cf8c | 928 | commit $commit |
908a3203 JH |
929 | Author: A U Thor <author@example.com> |
930 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
931 | ||
932 | ${indent}11th | |
933 | ||
934 | Notes: | |
935 | ${indent}other note | |
936 | ${indent} | |
937 | ${indent}yet another note | |
938 | EOF | |
d58deb9c | 939 | git notes copy HEAD^ && |
908a3203 | 940 | git log -1 >actual && |
e73bbd96 | 941 | test_cmp expect actual && |
29a40b5a DL |
942 | git notes list HEAD^ >expect && |
943 | git notes list HEAD >actual && | |
944 | test_cmp expect actual | |
e73bbd96 JH |
945 | ' |
946 | ||
947 | test_expect_success 'prevent overwrite with "git notes copy"' ' | |
948 | test_must_fail git notes copy HEAD~2 HEAD && | |
29a40b5a DL |
949 | cat >expect <<-EOF && |
950 | commit $commit | |
951 | Author: A U Thor <author@example.com> | |
952 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
953 | ||
954 | ${indent}11th | |
955 | ||
956 | Notes: | |
957 | ${indent}other note | |
958 | ${indent} | |
959 | ${indent}yet another note | |
960 | EOF | |
908a3203 | 961 | git log -1 >actual && |
e73bbd96 | 962 | test_cmp expect actual && |
29a40b5a DL |
963 | git notes list HEAD^ >expect && |
964 | git notes list HEAD >actual && | |
965 | test_cmp expect actual | |
e73bbd96 JH |
966 | ' |
967 | ||
e73bbd96 | 968 | test_expect_success 'allow overwrite with "git notes copy -f"' ' |
d58deb9c ĐTCD |
969 | commit=$(git rev-parse HEAD) && |
970 | cat >expect <<-EOF && | |
971 | commit $commit | |
972 | Author: A U Thor <author@example.com> | |
973 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
974 | ||
975 | ${indent}11th | |
976 | ||
977 | Notes: | |
978 | ${indent}This is a blob object | |
979 | EOF | |
980 | git notes copy -f HEAD~3 HEAD && | |
981 | git log -1 >actual && | |
982 | test_cmp expect actual && | |
29a40b5a DL |
983 | git notes list HEAD~3 >expect && |
984 | git notes list HEAD >actual && | |
985 | test_cmp expect actual | |
d58deb9c ĐTCD |
986 | ' |
987 | ||
988 | test_expect_success 'allow overwrite with "git notes copy -f" with default' ' | |
b408cf8c | 989 | commit=$(git rev-parse HEAD) && |
908a3203 | 990 | cat >expect <<-EOF && |
b408cf8c | 991 | commit $commit |
908a3203 JH |
992 | Author: A U Thor <author@example.com> |
993 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
994 | ||
995 | ${indent}11th | |
996 | ||
997 | Notes: | |
998 | ${indent}yet another note | |
999 | ${indent} | |
1000 | ${indent}yet another note | |
1001 | EOF | |
d58deb9c | 1002 | git notes copy -f HEAD~2 && |
908a3203 | 1003 | git log -1 >actual && |
e73bbd96 | 1004 | test_cmp expect actual && |
29a40b5a DL |
1005 | git notes list HEAD~2 >expect && |
1006 | git notes list HEAD >actual && | |
1007 | test_cmp expect actual | |
e73bbd96 JH |
1008 | ' |
1009 | ||
1010 | test_expect_success 'cannot copy note from object without notes' ' | |
908a3203 JH |
1011 | test_commit 12th && |
1012 | test_commit 13th && | |
e73bbd96 JH |
1013 | test_must_fail git notes copy HEAD^ HEAD |
1014 | ' | |
1015 | ||
908a3203 | 1016 | test_expect_success 'git notes copy --stdin' ' |
b408cf8c | 1017 | commit=$(git rev-parse HEAD) && |
1018 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 1019 | cat >expect <<-EOF && |
b408cf8c | 1020 | commit $commit |
908a3203 JH |
1021 | Author: A U Thor <author@example.com> |
1022 | Date: Thu Apr 7 15:25:13 2005 -0700 | |
160baa0d | 1023 | |
908a3203 | 1024 | ${indent}13th |
160baa0d | 1025 | |
908a3203 JH |
1026 | Notes: |
1027 | ${indent}yet another note | |
1028 | ${indent} | |
1029 | ${indent}yet another note | |
160baa0d | 1030 | |
b408cf8c | 1031 | commit $parent |
908a3203 JH |
1032 | Author: A U Thor <author@example.com> |
1033 | Date: Thu Apr 7 15:24:13 2005 -0700 | |
160baa0d | 1034 | |
908a3203 | 1035 | ${indent}12th |
160baa0d | 1036 | |
908a3203 JH |
1037 | Notes: |
1038 | ${indent}other note | |
1039 | ${indent} | |
1040 | ${indent}yet another note | |
1041 | EOF | |
29a40b5a DL |
1042 | from=$(git rev-parse HEAD~3) && |
1043 | to=$(git rev-parse HEAD^) && | |
1044 | echo "$from" "$to" >copy && | |
1045 | from=$(git rev-parse HEAD~2) && | |
1046 | to=$(git rev-parse HEAD) && | |
1047 | echo "$from" "$to" >>copy && | |
1048 | git notes copy --stdin <copy && | |
908a3203 JH |
1049 | git log -2 >actual && |
1050 | test_cmp expect actual && | |
29a40b5a DL |
1051 | git notes list HEAD~2 >expect && |
1052 | git notes list HEAD >actual && | |
1053 | test_cmp expect actual && | |
1054 | git notes list HEAD~3 >expect && | |
1055 | git notes list HEAD^ >actual && | |
1056 | test_cmp expect actual | |
160baa0d TR |
1057 | ' |
1058 | ||
908a3203 | 1059 | test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' |
b408cf8c | 1060 | test_commit 14th && |
1061 | test_commit 15th && | |
1062 | commit=$(git rev-parse HEAD) && | |
1063 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 1064 | cat >expect <<-EOF && |
b408cf8c | 1065 | commit $commit |
908a3203 JH |
1066 | Author: A U Thor <author@example.com> |
1067 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 1068 | |
908a3203 | 1069 | ${indent}15th |
6956f858 | 1070 | |
b408cf8c | 1071 | commit $parent |
908a3203 JH |
1072 | Author: A U Thor <author@example.com> |
1073 | Date: Thu Apr 7 15:26:13 2005 -0700 | |
6956f858 | 1074 | |
908a3203 JH |
1075 | ${indent}14th |
1076 | EOF | |
29a40b5a DL |
1077 | from=$(git rev-parse HEAD~3) && |
1078 | to=$(git rev-parse HEAD^) && | |
1079 | echo "$from" "$to" >copy && | |
1080 | from=$(git rev-parse HEAD~2) && | |
1081 | to=$(git rev-parse HEAD) && | |
1082 | echo "$from" "$to" >>copy && | |
1083 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1084 | git log -2 >actual && |
1085 | test_cmp expect actual | |
6956f858 TR |
1086 | ' |
1087 | ||
6956f858 | 1088 | test_expect_success 'git notes copy --for-rewrite (enabled)' ' |
b408cf8c | 1089 | commit=$(git rev-parse HEAD) && |
1090 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 1091 | cat >expect <<-EOF && |
b408cf8c | 1092 | commit $commit |
908a3203 JH |
1093 | Author: A U Thor <author@example.com> |
1094 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1095 | ||
1096 | ${indent}15th | |
1097 | ||
1098 | Notes: | |
1099 | ${indent}yet another note | |
1100 | ${indent} | |
1101 | ${indent}yet another note | |
1102 | ||
b408cf8c | 1103 | commit $parent |
908a3203 JH |
1104 | Author: A U Thor <author@example.com> |
1105 | Date: Thu Apr 7 15:26:13 2005 -0700 | |
1106 | ||
1107 | ${indent}14th | |
1108 | ||
1109 | Notes: | |
1110 | ${indent}other note | |
1111 | ${indent} | |
1112 | ${indent}yet another note | |
1113 | EOF | |
1114 | test_config notes.rewriteMode overwrite && | |
1115 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1116 | from=$(git rev-parse HEAD~3) && |
1117 | to=$(git rev-parse HEAD^) && | |
1118 | echo "$from" "$to" >copy && | |
1119 | from=$(git rev-parse HEAD~2) && | |
1120 | to=$(git rev-parse HEAD) && | |
1121 | echo "$from" "$to" >>copy && | |
1122 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1123 | git log -2 >actual && |
1124 | test_cmp expect actual | |
6956f858 TR |
1125 | ' |
1126 | ||
1127 | test_expect_success 'git notes copy --for-rewrite (disabled)' ' | |
908a3203 | 1128 | test_config notes.rewrite.bar false && |
29a40b5a DL |
1129 | from=$(git rev-parse HEAD~3) && |
1130 | to=$(git rev-parse HEAD) && | |
1131 | echo "$from" "$to" >copy && | |
1132 | git notes copy --for-rewrite=bar <copy && | |
908a3203 JH |
1133 | git log -2 >actual && |
1134 | test_cmp expect actual | |
6956f858 TR |
1135 | ' |
1136 | ||
908a3203 | 1137 | test_expect_success 'git notes copy --for-rewrite (overwrite)' ' |
b408cf8c | 1138 | commit=$(git rev-parse HEAD) && |
908a3203 | 1139 | cat >expect <<-EOF && |
b408cf8c | 1140 | commit $commit |
908a3203 JH |
1141 | Author: A U Thor <author@example.com> |
1142 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 1143 | |
908a3203 | 1144 | ${indent}15th |
6956f858 | 1145 | |
908a3203 JH |
1146 | Notes: |
1147 | ${indent}a fresh note | |
1148 | EOF | |
6956f858 | 1149 | git notes add -f -m"a fresh note" HEAD^ && |
908a3203 JH |
1150 | test_config notes.rewriteMode overwrite && |
1151 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1152 | from=$(git rev-parse HEAD^) && |
1153 | to=$(git rev-parse HEAD) && | |
1154 | echo "$from" "$to" >copy && | |
1155 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1156 | git log -1 >actual && |
1157 | test_cmp expect actual | |
6956f858 TR |
1158 | ' |
1159 | ||
1160 | test_expect_success 'git notes copy --for-rewrite (ignore)' ' | |
908a3203 JH |
1161 | test_config notes.rewriteMode ignore && |
1162 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1163 | from=$(git rev-parse HEAD^) && |
1164 | to=$(git rev-parse HEAD) && | |
1165 | echo "$from" "$to" >copy && | |
1166 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1167 | git log -1 >actual && |
1168 | test_cmp expect actual | |
6956f858 TR |
1169 | ' |
1170 | ||
6956f858 | 1171 | test_expect_success 'git notes copy --for-rewrite (append)' ' |
b408cf8c | 1172 | commit=$(git rev-parse HEAD) && |
908a3203 | 1173 | cat >expect <<-EOF && |
b408cf8c | 1174 | commit $commit |
908a3203 JH |
1175 | Author: A U Thor <author@example.com> |
1176 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1177 | ||
1178 | ${indent}15th | |
1179 | ||
1180 | Notes: | |
1181 | ${indent}a fresh note | |
1182 | ${indent} | |
1183 | ${indent}another fresh note | |
1184 | EOF | |
6956f858 | 1185 | git notes add -f -m"another fresh note" HEAD^ && |
908a3203 JH |
1186 | test_config notes.rewriteMode concatenate && |
1187 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1188 | from=$(git rev-parse HEAD^) && |
1189 | to=$(git rev-parse HEAD) && | |
1190 | echo "$from" "$to" >copy && | |
1191 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1192 | git log -1 >actual && |
1193 | test_cmp expect actual | |
6956f858 TR |
1194 | ' |
1195 | ||
6956f858 | 1196 | test_expect_success 'git notes copy --for-rewrite (append two to one)' ' |
b408cf8c | 1197 | commit=$(git rev-parse HEAD) && |
908a3203 | 1198 | cat >expect <<-EOF && |
b408cf8c | 1199 | commit $commit |
908a3203 JH |
1200 | Author: A U Thor <author@example.com> |
1201 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1202 | ||
1203 | ${indent}15th | |
1204 | ||
1205 | Notes: | |
1206 | ${indent}a fresh note | |
1207 | ${indent} | |
1208 | ${indent}another fresh note | |
1209 | ${indent} | |
1210 | ${indent}append 1 | |
1211 | ${indent} | |
1212 | ${indent}append 2 | |
1213 | EOF | |
6956f858 TR |
1214 | git notes add -f -m"append 1" HEAD^ && |
1215 | git notes add -f -m"append 2" HEAD^^ && | |
908a3203 JH |
1216 | test_config notes.rewriteMode concatenate && |
1217 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1218 | from=$(git rev-parse HEAD^) && |
1219 | to=$(git rev-parse HEAD) && | |
1220 | echo "$from" "$to" >copy && | |
1221 | from=$(git rev-parse HEAD^^) && | |
1222 | to=$(git rev-parse HEAD) && | |
1223 | echo "$from" "$to" >>copy && | |
1224 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1225 | git log -1 >actual && |
1226 | test_cmp expect actual | |
6956f858 TR |
1227 | ' |
1228 | ||
1229 | test_expect_success 'git notes copy --for-rewrite (append empty)' ' | |
1230 | git notes remove HEAD^ && | |
908a3203 JH |
1231 | test_config notes.rewriteMode concatenate && |
1232 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1233 | from=$(git rev-parse HEAD^) && |
1234 | to=$(git rev-parse HEAD) && | |
1235 | echo "$from" "$to" >copy && | |
1236 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1237 | git log -1 >actual && |
1238 | test_cmp expect actual | |
6956f858 TR |
1239 | ' |
1240 | ||
6956f858 | 1241 | test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' |
b408cf8c | 1242 | commit=$(git rev-parse HEAD) && |
908a3203 | 1243 | cat >expect <<-EOF && |
b408cf8c | 1244 | commit $commit |
908a3203 JH |
1245 | Author: A U Thor <author@example.com> |
1246 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1247 | ||
1248 | ${indent}15th | |
1249 | ||
1250 | Notes: | |
1251 | ${indent}replacement note 1 | |
1252 | EOF | |
1253 | test_config notes.rewriteMode concatenate && | |
1254 | test_config notes.rewriteRef "refs/notes/*" && | |
6956f858 | 1255 | git notes add -f -m"replacement note 1" HEAD^ && |
29a40b5a DL |
1256 | from=$(git rev-parse HEAD^) && |
1257 | to=$(git rev-parse HEAD) && | |
1258 | echo "$from" "$to" >copy && | |
1259 | GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1260 | git log -1 >actual && |
1261 | test_cmp expect actual | |
6956f858 TR |
1262 | ' |
1263 | ||
908a3203 | 1264 | test_expect_success 'GIT_NOTES_REWRITE_REF works' ' |
b408cf8c | 1265 | commit=$(git rev-parse HEAD) && |
908a3203 | 1266 | cat >expect <<-EOF && |
b408cf8c | 1267 | commit $commit |
908a3203 JH |
1268 | Author: A U Thor <author@example.com> |
1269 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 1270 | |
908a3203 | 1271 | ${indent}15th |
6956f858 | 1272 | |
908a3203 JH |
1273 | Notes: |
1274 | ${indent}replacement note 2 | |
1275 | EOF | |
6956f858 | 1276 | git notes add -f -m"replacement note 2" HEAD^ && |
908a3203 JH |
1277 | test_config notes.rewriteMode overwrite && |
1278 | test_unconfig notes.rewriteRef && | |
29a40b5a DL |
1279 | from=$(git rev-parse HEAD^) && |
1280 | to=$(git rev-parse HEAD) && | |
1281 | echo "$from" "$to" >copy && | |
6956f858 | 1282 | GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ |
29a40b5a | 1283 | git notes copy --for-rewrite=foo <copy && |
908a3203 JH |
1284 | git log -1 >actual && |
1285 | test_cmp expect actual | |
6956f858 TR |
1286 | ' |
1287 | ||
1288 | test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' | |
6956f858 | 1289 | git notes add -f -m"replacement note 3" HEAD^ && |
908a3203 JH |
1290 | test_config notes.rewriteMode overwrite && |
1291 | test_config notes.rewriteRef refs/notes/other && | |
29a40b5a DL |
1292 | from=$(git rev-parse HEAD^) && |
1293 | to=$(git rev-parse HEAD) && | |
1294 | echo "$from" "$to" >copy && | |
dbe7b410 | 1295 | GIT_NOTES_REWRITE_REF=refs/notes/commits \ |
29a40b5a | 1296 | git notes copy --for-rewrite=foo <copy && |
908a3203 | 1297 | git log -1 >actual && |
dbe7b410 | 1298 | grep "replacement note 3" actual |
6956f858 | 1299 | ' |
bbb1b8a3 | 1300 | |
b8657347 | 1301 | test_expect_success 'git notes copy diagnoses too many or too few arguments' ' |
8af69cf3 | 1302 | test_must_fail git notes copy 2>error && |
b8657347 | 1303 | test_i18ngrep "too few arguments" error && |
8af69cf3 | 1304 | test_must_fail git notes copy one two three 2>error && |
b8657347 | 1305 | test_i18ngrep "too many arguments" error |
bbb1b8a3 JK |
1306 | ' |
1307 | ||
d6c6b108 | 1308 | test_expect_success 'git notes get-ref expands refs/heads/main to refs/notes/refs/heads/main' ' |
e14c92e8 JK |
1309 | test_unconfig core.notesRef && |
1310 | sane_unset GIT_NOTES_REF && | |
d6c6b108 JS |
1311 | echo refs/notes/refs/heads/main >expect && |
1312 | git notes --ref=refs/heads/main get-ref >actual && | |
29a40b5a | 1313 | test_cmp expect actual |
e14c92e8 JK |
1314 | ' |
1315 | ||
618cd757 | 1316 | test_expect_success 'git notes get-ref (no overrides)' ' |
908a3203 | 1317 | test_unconfig core.notesRef && |
ed40ec55 | 1318 | sane_unset GIT_NOTES_REF && |
29a40b5a DL |
1319 | echo refs/notes/commits >expect && |
1320 | git notes get-ref >actual && | |
1321 | test_cmp expect actual | |
618cd757 JH |
1322 | ' |
1323 | ||
1324 | test_expect_success 'git notes get-ref (core.notesRef)' ' | |
908a3203 | 1325 | test_config core.notesRef refs/notes/foo && |
29a40b5a DL |
1326 | echo refs/notes/foo >expect && |
1327 | git notes get-ref >actual && | |
1328 | test_cmp expect actual | |
618cd757 JH |
1329 | ' |
1330 | ||
1331 | test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' | |
29a40b5a DL |
1332 | echo refs/notes/bar >expect && |
1333 | GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual && | |
1334 | test_cmp expect actual | |
618cd757 JH |
1335 | ' |
1336 | ||
1337 | test_expect_success 'git notes get-ref (--ref)' ' | |
29a40b5a DL |
1338 | echo refs/notes/baz >expect && |
1339 | GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual && | |
1340 | test_cmp expect actual | |
618cd757 JH |
1341 | ' |
1342 | ||
d0923b6d JH |
1343 | test_expect_success 'setup testing of empty notes' ' |
1344 | test_unconfig core.notesRef && | |
1345 | test_commit 16th && | |
d73a5b93 JH |
1346 | empty_blob=$(git hash-object -w /dev/null) && |
1347 | echo "$empty_blob" >expect_empty | |
d0923b6d JH |
1348 | ' |
1349 | ||
1350 | while read cmd | |
1351 | do | |
1352 | test_expect_success "'git notes $cmd' removes empty note" " | |
1353 | test_might_fail git notes remove HEAD && | |
1354 | MSG= git notes $cmd && | |
1355 | test_must_fail git notes list HEAD | |
1356 | " | |
d73a5b93 JH |
1357 | |
1358 | test_expect_success "'git notes $cmd --allow-empty' stores empty note" " | |
1359 | test_might_fail git notes remove HEAD && | |
1360 | MSG= git notes $cmd --allow-empty && | |
1361 | git notes list HEAD >actual && | |
1362 | test_cmp expect_empty actual | |
1363 | " | |
d0923b6d JH |
1364 | done <<\EOF |
1365 | add | |
1366 | add -F /dev/null | |
1367 | add -m "" | |
1368 | add -c "$empty_blob" | |
1369 | add -C "$empty_blob" | |
1370 | append | |
1371 | append -F /dev/null | |
1372 | append -m "" | |
1373 | append -c "$empty_blob" | |
1374 | append -C "$empty_blob" | |
1375 | edit | |
1376 | EOF | |
1377 | ||
8a4acd69 JH |
1378 | test_expect_success 'empty notes are displayed by git log' ' |
1379 | test_commit 17th && | |
1380 | git log -1 >expect && | |
908a3203 | 1381 | cat >>expect <<-EOF && |
8a4acd69 | 1382 | |
908a3203 JH |
1383 | Notes: |
1384 | EOF | |
8a4acd69 JH |
1385 | git notes add -C "$empty_blob" --allow-empty && |
1386 | git log -1 >actual && | |
1387 | test_cmp expect actual | |
1388 | ' | |
1389 | ||
65d9fb48 | 1390 | test_done |