]>
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 | 364 | test_expect_success 'create note with combination of -m and -F' ' |
90bc19b3 | 365 | test_when_finished git notes remove HEAD && |
908a3203 JH |
366 | cat >expect-combine_m_and_F <<-EOF && |
367 | foo | |
348f199b | 368 | |
908a3203 | 369 | xyzzy |
348f199b | 370 | |
908a3203 | 371 | bar |
348f199b | 372 | |
908a3203 | 373 | zyxxy |
348f199b | 374 | |
908a3203 JH |
375 | baz |
376 | EOF | |
377 | echo "xyzzy" >note_a && | |
378 | echo "zyxxy" >note_b && | |
348f199b | 379 | git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" && |
908a3203 JH |
380 | git notes show >actual && |
381 | test_cmp expect-combine_m_and_F actual | |
348f199b JH |
382 | ' |
383 | ||
90bc19b3 | 384 | test_expect_success 'create note with combination of -m and -F and --separator' ' |
3d6a3164 | 385 | test_when_finished git notes remove HEAD && |
90bc19b3 TL |
386 | cat >expect-combine_m_and_F <<-\EOF && |
387 | foo | |
388 | ------- | |
389 | xyzzy | |
390 | ------- | |
391 | bar | |
392 | ------- | |
393 | zyxxy | |
394 | ------- | |
395 | baz | |
396 | EOF | |
397 | echo "xyzzy" >note_a && | |
398 | echo "zyxxy" >note_b && | |
3d6a3164 TL |
399 | git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --separator="-------" && |
400 | git notes show >actual && | |
401 | test_cmp expect-combine_m_and_F actual | |
402 | ' | |
403 | ||
404 | test_expect_success 'create note with combination of -m and -F and --no-separator' ' | |
405 | cat >expect-combine_m_and_F <<-\EOF && | |
406 | foo | |
407 | xyzzy | |
408 | bar | |
409 | zyxxy | |
410 | baz | |
411 | EOF | |
412 | echo "xyzzy" >note_a && | |
413 | echo "zyxxy" >note_b && | |
414 | git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --no-separator && | |
90bc19b3 TL |
415 | git notes show >actual && |
416 | test_cmp expect-combine_m_and_F actual | |
417 | ' | |
418 | ||
908a3203 | 419 | test_expect_success 'remove note with "git notes remove"' ' |
348f199b | 420 | git notes remove HEAD^ && |
908a3203 | 421 | git notes remove && |
b408cf8c | 422 | commit=$(git rev-parse HEAD) && |
423 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 424 | cat >expect-rm-remove <<-EOF && |
b408cf8c | 425 | commit $commit |
908a3203 JH |
426 | Author: A U Thor <author@example.com> |
427 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
92b3385f | 428 | |
908a3203 | 429 | ${indent}5th |
92b3385f | 430 | |
b408cf8c | 431 | commit $parent |
908a3203 JH |
432 | Author: A U Thor <author@example.com> |
433 | Date: Thu Apr 7 15:16:13 2005 -0700 | |
92b3385f | 434 | |
908a3203 | 435 | ${indent}4th |
92b3385f | 436 | |
908a3203 JH |
437 | EOF |
438 | cat expect-multiline >>expect-rm-remove && | |
439 | git log -4 >actual && | |
440 | test_cmp expect-rm-remove actual && | |
ce14e0b2 | 441 | test_must_fail git notes show HEAD^ |
92b3385f JH |
442 | ' |
443 | ||
1ee1e43d | 444 | test_expect_success 'removing non-existing note should not create new commit' ' |
908a3203 | 445 | git rev-parse --verify refs/notes/commits >before_commit && |
1ee1e43d | 446 | test_must_fail git notes remove HEAD^ && |
908a3203 | 447 | git rev-parse --verify refs/notes/commits >after_commit && |
1ee1e43d JH |
448 | test_cmp before_commit after_commit |
449 | ' | |
450 | ||
c3ab1a8e JH |
451 | test_expect_success 'removing more than one' ' |
452 | before=$(git rev-parse --verify refs/notes/commits) && | |
453 | test_when_finished "git update-ref refs/notes/commits $before" && | |
454 | ||
455 | # We have only two -- add another and make sure it stays | |
456 | git notes add -m "extra" && | |
457 | git notes list HEAD >after-removal-expect && | |
458 | git notes remove HEAD^^ HEAD^^^ && | |
459 | git notes list | sed -e "s/ .*//" >actual && | |
460 | test_cmp after-removal-expect actual | |
461 | ' | |
462 | ||
463 | test_expect_success 'removing is atomic' ' | |
464 | before=$(git rev-parse --verify refs/notes/commits) && | |
465 | test_when_finished "git update-ref refs/notes/commits $before" && | |
466 | test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ && | |
467 | after=$(git rev-parse --verify refs/notes/commits) && | |
468 | test "$before" = "$after" | |
469 | ' | |
470 | ||
2d370d2f JH |
471 | test_expect_success 'removing with --ignore-missing' ' |
472 | before=$(git rev-parse --verify refs/notes/commits) && | |
473 | test_when_finished "git update-ref refs/notes/commits $before" && | |
474 | ||
475 | # We have only two -- add another and make sure it stays | |
476 | git notes add -m "extra" && | |
477 | git notes list HEAD >after-removal-expect && | |
478 | git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ && | |
479 | git notes list | sed -e "s/ .*//" >actual && | |
480 | test_cmp after-removal-expect actual | |
481 | ' | |
482 | ||
483 | test_expect_success 'removing with --ignore-missing but bogus ref' ' | |
484 | before=$(git rev-parse --verify refs/notes/commits) && | |
485 | test_when_finished "git update-ref refs/notes/commits $before" && | |
486 | test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT && | |
487 | after=$(git rev-parse --verify refs/notes/commits) && | |
488 | test "$before" = "$after" | |
489 | ' | |
490 | ||
46538012 JH |
491 | test_expect_success 'remove reads from --stdin' ' |
492 | before=$(git rev-parse --verify refs/notes/commits) && | |
493 | test_when_finished "git update-ref refs/notes/commits $before" && | |
494 | ||
495 | # We have only two -- add another and make sure it stays | |
496 | git notes add -m "extra" && | |
497 | git notes list HEAD >after-removal-expect && | |
498 | git rev-parse HEAD^^ HEAD^^^ >input && | |
499 | git notes remove --stdin <input && | |
500 | git notes list | sed -e "s/ .*//" >actual && | |
501 | test_cmp after-removal-expect actual | |
502 | ' | |
503 | ||
504 | test_expect_success 'remove --stdin is also atomic' ' | |
505 | before=$(git rev-parse --verify refs/notes/commits) && | |
506 | test_when_finished "git update-ref refs/notes/commits $before" && | |
507 | git rev-parse HEAD^^ HEAD^^^ HEAD^ >input && | |
508 | test_must_fail git notes remove --stdin <input && | |
509 | after=$(git rev-parse --verify refs/notes/commits) && | |
510 | test "$before" = "$after" | |
511 | ' | |
512 | ||
513 | test_expect_success 'removing with --stdin --ignore-missing' ' | |
514 | before=$(git rev-parse --verify refs/notes/commits) && | |
515 | test_when_finished "git update-ref refs/notes/commits $before" && | |
516 | ||
517 | # We have only two -- add another and make sure it stays | |
518 | git notes add -m "extra" && | |
519 | git notes list HEAD >after-removal-expect && | |
520 | git rev-parse HEAD^^ HEAD^^^ HEAD^ >input && | |
521 | git notes remove --ignore-missing --stdin <input && | |
522 | git notes list | sed -e "s/ .*//" >actual && | |
523 | test_cmp after-removal-expect actual | |
524 | ' | |
525 | ||
e397421a | 526 | test_expect_success 'list notes with "git notes list"' ' |
b408cf8c | 527 | commit_2=$(git rev-parse 2nd) && |
528 | commit_3=$(git rev-parse 3rd) && | |
29a40b5a DL |
529 | note_2=$(git rev-parse refs/notes/commits:$commit_2) && |
530 | note_3=$(git rev-parse refs/notes/commits:$commit_3) && | |
b408cf8c | 531 | sort -t" " -k2 >expect <<-EOF && |
29a40b5a DL |
532 | $note_2 $commit_2 |
533 | $note_3 $commit_3 | |
908a3203 JH |
534 | EOF |
535 | git notes list >actual && | |
536 | test_cmp expect actual | |
e397421a JH |
537 | ' |
538 | ||
539 | test_expect_success 'list notes with "git notes"' ' | |
908a3203 JH |
540 | git notes >actual && |
541 | test_cmp expect actual | |
e397421a JH |
542 | ' |
543 | ||
9e4658d5 SG |
544 | test_expect_success '"git notes" without subcommand does not take arguments' ' |
545 | test_expect_code 129 git notes HEAD^^ 2>err && | |
546 | grep "^error: unknown subcommand" err | |
547 | ' | |
548 | ||
e397421a | 549 | test_expect_success 'list specific note with "git notes list <object>"' ' |
29a40b5a | 550 | git rev-parse refs/notes/commits:$commit_3 >expect && |
908a3203 JH |
551 | git notes list HEAD^^ >actual && |
552 | test_cmp expect actual | |
e397421a JH |
553 | ' |
554 | ||
e397421a | 555 | test_expect_success 'listing non-existing notes fails' ' |
908a3203 | 556 | test_must_fail git notes list HEAD >actual && |
1c5e94f4 | 557 | test_must_be_empty actual |
e397421a JH |
558 | ' |
559 | ||
3d6a3164 | 560 | test_expect_success 'append: specify a separator with an empty arg' ' |
90bc19b3 TL |
561 | test_when_finished git notes remove HEAD && |
562 | cat >expect <<-\EOF && | |
563 | notes-1 | |
564 | ||
565 | notes-2 | |
566 | EOF | |
567 | ||
568 | git notes add -m "notes-1" && | |
569 | git notes append --separator="" -m "notes-2" && | |
570 | git notes show >actual && | |
571 | test_cmp expect actual | |
572 | ' | |
573 | ||
3d6a3164 TL |
574 | test_expect_success 'append: specify a separator without arg' ' |
575 | test_when_finished git notes remove HEAD && | |
576 | cat >expect <<-\EOF && | |
577 | notes-1 | |
578 | ||
579 | notes-2 | |
580 | EOF | |
581 | ||
582 | git notes add -m "notes-1" && | |
583 | git notes append --separator -m "notes-2" && | |
584 | git notes show >actual && | |
585 | test_cmp expect actual | |
586 | ' | |
587 | ||
588 | test_expect_success 'append: specify as --no-separator' ' | |
589 | test_when_finished git notes remove HEAD && | |
590 | cat >expect <<-\EOF && | |
591 | notes-1 | |
592 | notes-2 | |
593 | EOF | |
594 | ||
595 | git notes add -m "notes-1" && | |
596 | git notes append --no-separator -m "notes-2" && | |
597 | git notes show >actual && | |
598 | test_cmp expect actual | |
599 | ' | |
600 | ||
90bc19b3 TL |
601 | test_expect_success 'append: specify separator with line break' ' |
602 | test_when_finished git notes remove HEAD && | |
603 | cat >expect <<-\EOF && | |
604 | notes-1 | |
605 | ------- | |
606 | notes-2 | |
607 | EOF | |
608 | ||
609 | git notes add -m "notes-1" && | |
610 | git notes append --separator="-------$LF" -m "notes-2" && | |
611 | git notes show >actual && | |
612 | test_cmp expect actual | |
613 | ' | |
614 | ||
615 | test_expect_success 'append: specify separator without line break' ' | |
616 | test_when_finished git notes remove HEAD && | |
617 | cat >expect <<-\EOF && | |
618 | notes-1 | |
619 | ------- | |
620 | notes-2 | |
621 | EOF | |
622 | ||
623 | git notes add -m "notes-1" && | |
624 | git notes append --separator="-------" -m "notes-2" && | |
625 | git notes show >actual && | |
626 | test_cmp expect actual | |
627 | ' | |
628 | ||
629 | test_expect_success 'append: specify separator with multiple messages' ' | |
630 | test_when_finished git notes remove HEAD && | |
631 | cat >expect <<-\EOF && | |
632 | notes-1 | |
633 | ------- | |
634 | notes-2 | |
635 | ------- | |
636 | notes-3 | |
637 | EOF | |
638 | ||
639 | git notes add -m "notes-1" && | |
640 | git notes append --separator="-------" -m "notes-2" -m "notes-3" && | |
641 | git notes show >actual && | |
642 | test_cmp expect actual | |
643 | ' | |
644 | ||
645 | test_expect_success 'append note with combination of -m and -F and --separator' ' | |
646 | test_when_finished git notes remove HEAD && | |
647 | cat >expect-combine_m_and_F <<-\EOF && | |
648 | m-notes-1 | |
649 | ------- | |
650 | f-notes-1 | |
651 | ------- | |
652 | m-notes-2 | |
653 | ------- | |
654 | f-notes-2 | |
655 | ------- | |
656 | m-notes-3 | |
657 | EOF | |
658 | ||
659 | echo "f-notes-1" >note_a && | |
660 | echo "f-notes-2" >note_b && | |
3d6a3164 | 661 | git notes append -m "m-notes-1" -F note_a -m "m-notes-2" -F note_b -m "m-notes-3" --separator="-------" && |
90bc19b3 TL |
662 | git notes show >actual && |
663 | test_cmp expect-combine_m_and_F actual | |
664 | ' | |
665 | ||
2347fae5 | 666 | test_expect_success 'append to existing note with "git notes append"' ' |
908a3203 JH |
667 | cat >expect <<-EOF && |
668 | Initial set of notes | |
669 | ||
670 | More notes appended with git notes append | |
671 | EOF | |
2347fae5 JH |
672 | git notes add -m "Initial set of notes" && |
673 | git notes append -m "More notes appended with git notes append" && | |
908a3203 JH |
674 | git notes show >actual && |
675 | test_cmp expect actual | |
2347fae5 JH |
676 | ' |
677 | ||
74884b52 | 678 | test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' |
b408cf8c | 679 | commit_5=$(git rev-parse 5th) && |
29a40b5a | 680 | note_5=$(git rev-parse refs/notes/commits:$commit_5) && |
b408cf8c | 681 | sort -t" " -k2 >expect_list <<-EOF && |
29a40b5a DL |
682 | $note_2 $commit_2 |
683 | $note_3 $commit_3 | |
684 | $note_5 $commit_5 | |
908a3203 JH |
685 | EOF |
686 | git notes list >actual && | |
687 | test_cmp expect_list actual | |
74884b52 SB |
688 | ' |
689 | ||
2347fae5 JH |
690 | test_expect_success 'appending empty string does not change existing note' ' |
691 | git notes append -m "" && | |
908a3203 JH |
692 | git notes show >actual && |
693 | test_cmp expect actual | |
2347fae5 JH |
694 | ' |
695 | ||
696 | test_expect_success 'git notes append == add when there is no existing note' ' | |
697 | git notes remove HEAD && | |
698 | test_must_fail git notes list HEAD && | |
908a3203 JH |
699 | git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" && |
700 | git notes show >actual && | |
701 | test_cmp expect actual | |
2347fae5 JH |
702 | ' |
703 | ||
704 | test_expect_success 'appending empty string to non-existing note does not create note' ' | |
705 | git notes remove HEAD && | |
706 | test_must_fail git notes list HEAD && | |
707 | git notes append -m "" && | |
708 | test_must_fail git notes list HEAD | |
709 | ' | |
710 | ||
cd067d3b | 711 | test_expect_success 'create other note on a different notes ref (setup)' ' |
908a3203 JH |
712 | test_commit 6th && |
713 | GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" && | |
b408cf8c | 714 | commit=$(git rev-parse HEAD) && |
908a3203 | 715 | cat >expect-not-other <<-EOF && |
b408cf8c | 716 | commit $commit |
908a3203 JH |
717 | Author: A U Thor <author@example.com> |
718 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
cd067d3b | 719 | |
908a3203 JH |
720 | ${indent}6th |
721 | EOF | |
722 | cp expect-not-other expect-other && | |
723 | cat >>expect-other <<-EOF | |
cd067d3b | 724 | |
908a3203 JH |
725 | Notes (other): |
726 | ${indent}other note | |
727 | EOF | |
728 | ' | |
3b78cdbe JH |
729 | |
730 | test_expect_success 'Do not show note on other ref by default' ' | |
908a3203 JH |
731 | git log -1 >actual && |
732 | test_cmp expect-not-other actual | |
3b78cdbe JH |
733 | ' |
734 | ||
735 | test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' ' | |
908a3203 JH |
736 | GIT_NOTES_REF="refs/notes/other" git log -1 >actual && |
737 | test_cmp expect-other actual | |
3b78cdbe JH |
738 | ' |
739 | ||
740 | test_expect_success 'Do show note when ref is given in core.notesRef config' ' | |
908a3203 JH |
741 | test_config core.notesRef "refs/notes/other" && |
742 | git log -1 >actual && | |
743 | test_cmp expect-other actual | |
3b78cdbe JH |
744 | ' |
745 | ||
746 | test_expect_success 'Do not show note when core.notesRef is overridden' ' | |
908a3203 JH |
747 | test_config core.notesRef "refs/notes/other" && |
748 | GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual && | |
749 | test_cmp expect-not-other actual | |
3b78cdbe JH |
750 | ' |
751 | ||
908a3203 | 752 | test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' ' |
b408cf8c | 753 | commit=$(git rev-parse HEAD) && |
754 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 755 | cat >expect-both <<-EOF && |
b408cf8c | 756 | commit $commit |
908a3203 JH |
757 | Author: A U Thor <author@example.com> |
758 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 759 | |
908a3203 | 760 | ${indent}6th |
894a9d33 | 761 | |
908a3203 JH |
762 | Notes: |
763 | ${indent}order test | |
894a9d33 | 764 | |
908a3203 JH |
765 | Notes (other): |
766 | ${indent}other note | |
894a9d33 | 767 | |
b408cf8c | 768 | commit $parent |
908a3203 JH |
769 | Author: A U Thor <author@example.com> |
770 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
894a9d33 | 771 | |
908a3203 | 772 | ${indent}5th |
894a9d33 | 773 | |
908a3203 JH |
774 | Notes: |
775 | ${indent}replacement for deleted note | |
776 | EOF | |
894a9d33 TR |
777 | GIT_NOTES_REF=refs/notes/commits git notes add \ |
778 | -m"replacement for deleted note" HEAD^ && | |
779 | GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" && | |
908a3203 JH |
780 | test_unconfig core.notesRef && |
781 | test_config notes.displayRef "refs/notes/*" && | |
782 | git log -2 >actual && | |
783 | test_cmp expect-both actual | |
894a9d33 TR |
784 | ' |
785 | ||
786 | test_expect_success 'core.notesRef is implicitly in notes.displayRef' ' | |
908a3203 JH |
787 | test_config core.notesRef refs/notes/commits && |
788 | test_config notes.displayRef refs/notes/other && | |
789 | git log -2 >actual && | |
790 | test_cmp expect-both actual | |
894a9d33 TR |
791 | ' |
792 | ||
793 | test_expect_success 'notes.displayRef can be given more than once' ' | |
908a3203 JH |
794 | test_unconfig core.notesRef && |
795 | test_config notes.displayRef refs/notes/commits && | |
894a9d33 | 796 | git config --add notes.displayRef refs/notes/other && |
908a3203 JH |
797 | git log -2 >actual && |
798 | test_cmp expect-both actual | |
894a9d33 TR |
799 | ' |
800 | ||
908a3203 | 801 | test_expect_success 'notes.displayRef respects order' ' |
b408cf8c | 802 | commit=$(git rev-parse HEAD) && |
908a3203 | 803 | cat >expect-both-reversed <<-EOF && |
b408cf8c | 804 | commit $commit |
908a3203 JH |
805 | Author: A U Thor <author@example.com> |
806 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 807 | |
908a3203 | 808 | ${indent}6th |
894a9d33 | 809 | |
908a3203 JH |
810 | Notes (other): |
811 | ${indent}other note | |
894a9d33 | 812 | |
908a3203 JH |
813 | Notes: |
814 | ${indent}order test | |
815 | EOF | |
816 | test_config core.notesRef refs/notes/other && | |
817 | test_config notes.displayRef refs/notes/commits && | |
818 | git log -1 >actual && | |
819 | test_cmp expect-both-reversed actual | |
894a9d33 TR |
820 | ' |
821 | ||
45fef159 NA |
822 | test_expect_success 'notes.displayRef with no value handled gracefully' ' |
823 | test_must_fail git -c notes.displayRef log -0 --notes && | |
824 | test_must_fail git -c notes.displayRef diff-tree --notes HEAD | |
825 | ' | |
826 | ||
894a9d33 | 827 | test_expect_success 'GIT_NOTES_DISPLAY_REF works' ' |
894a9d33 | 828 | GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \ |
908a3203 JH |
829 | git log -2 >actual && |
830 | test_cmp expect-both actual | |
894a9d33 TR |
831 | ' |
832 | ||
908a3203 | 833 | test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' ' |
b408cf8c | 834 | commit=$(git rev-parse HEAD) && |
835 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 836 | cat >expect-none <<-EOF && |
b408cf8c | 837 | commit $commit |
908a3203 JH |
838 | Author: A U Thor <author@example.com> |
839 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 840 | |
908a3203 | 841 | ${indent}6th |
894a9d33 | 842 | |
b408cf8c | 843 | commit $parent |
908a3203 JH |
844 | Author: A U Thor <author@example.com> |
845 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
894a9d33 | 846 | |
908a3203 JH |
847 | ${indent}5th |
848 | EOF | |
849 | test_config notes.displayRef "refs/notes/*" && | |
850 | GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual && | |
851 | test_cmp expect-none actual | |
894a9d33 TR |
852 | ' |
853 | ||
854 | test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' ' | |
908a3203 JH |
855 | GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual && |
856 | test_cmp expect-both actual | |
894a9d33 TR |
857 | ' |
858 | ||
908a3203 | 859 | test_expect_success '--no-standard-notes' ' |
b408cf8c | 860 | commit=$(git rev-parse HEAD) && |
85cb1d0b | 861 | cat >expect-commits <<-EOF && |
b408cf8c | 862 | commit $commit |
908a3203 JH |
863 | Author: A U Thor <author@example.com> |
864 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 865 | |
908a3203 | 866 | ${indent}6th |
894a9d33 | 867 | |
908a3203 JH |
868 | Notes: |
869 | ${indent}order test | |
870 | EOF | |
871 | git log --no-standard-notes --show-notes=commits -1 >actual && | |
872 | test_cmp expect-commits actual | |
894a9d33 TR |
873 | ' |
874 | ||
875 | test_expect_success '--standard-notes' ' | |
908a3203 | 876 | test_config notes.displayRef "refs/notes/*" && |
894a9d33 | 877 | git log --no-standard-notes --show-notes=commits \ |
908a3203 JH |
878 | --standard-notes -2 >actual && |
879 | test_cmp expect-both actual | |
894a9d33 TR |
880 | ' |
881 | ||
882 | test_expect_success '--show-notes=ref accumulates' ' | |
883 | git log --show-notes=other --show-notes=commits \ | |
908a3203 JH |
884 | --no-standard-notes -1 >actual && |
885 | test_cmp expect-both-reversed actual | |
894a9d33 TR |
886 | ' |
887 | ||
b24bb997 | 888 | test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' |
908a3203 JH |
889 | test_config core.notesRef refs/notes/other && |
890 | echo "Note on a tree" >expect && | |
7aa4754e | 891 | git notes add -m "Note on a tree" HEAD: && |
908a3203 | 892 | git notes show HEAD: >actual && |
b24bb997 | 893 | test_cmp expect actual && |
908a3203 | 894 | echo "Note on a blob" >expect && |
29a40b5a DL |
895 | git ls-tree --name-only HEAD >files && |
896 | filename=$(head -n1 files) && | |
7aa4754e | 897 | git notes add -m "Note on a blob" HEAD:$filename && |
908a3203 | 898 | git notes show HEAD:$filename >actual && |
b24bb997 | 899 | test_cmp expect actual && |
908a3203 | 900 | echo "Note on a tag" >expect && |
b24bb997 | 901 | git tag -a -m "This is an annotated tag" foobar HEAD^ && |
7aa4754e | 902 | git notes add -m "Note on a tag" foobar && |
908a3203 | 903 | git notes show foobar >actual && |
b24bb997 JH |
904 | test_cmp expect actual |
905 | ' | |
906 | ||
908a3203 | 907 | test_expect_success 'create note from other note with "git notes add -C"' ' |
b408cf8c | 908 | test_commit 7th && |
909 | commit=$(git rev-parse HEAD) && | |
908a3203 | 910 | cat >expect <<-EOF && |
b408cf8c | 911 | commit $commit |
908a3203 JH |
912 | Author: A U Thor <author@example.com> |
913 | Date: Thu Apr 7 15:19:13 2005 -0700 | |
0691cff7 | 914 | |
908a3203 | 915 | ${indent}7th |
0691cff7 | 916 | |
908a3203 JH |
917 | Notes: |
918 | ${indent}order test | |
919 | EOF | |
29a40b5a DL |
920 | note=$(git notes list HEAD^) && |
921 | git notes add -C $note && | |
908a3203 | 922 | git log -1 >actual && |
0691cff7 | 923 | test_cmp expect actual && |
29a40b5a DL |
924 | git notes list HEAD^ >expect && |
925 | git notes list HEAD >actual && | |
926 | test_cmp expect actual | |
0691cff7 JH |
927 | ' |
928 | ||
929 | test_expect_success 'create note from non-existing note with "git notes add -C" fails' ' | |
908a3203 | 930 | test_commit 8th && |
0691cff7 JH |
931 | test_must_fail git notes add -C deadbeef && |
932 | test_must_fail git notes list HEAD | |
933 | ' | |
934 | ||
ce8daa1e JH |
935 | test_expect_success 'create note from non-blob with "git notes add -C" fails' ' |
936 | commit=$(git rev-parse --verify HEAD) && | |
937 | tree=$(git rev-parse --verify HEAD:) && | |
938 | test_must_fail git notes add -C $commit && | |
939 | test_must_fail git notes add -C $tree && | |
940 | test_must_fail git notes list HEAD | |
941 | ' | |
942 | ||
908a3203 | 943 | test_expect_success 'create note from blob with "git notes add -C" reuses blob id' ' |
b408cf8c | 944 | commit=$(git rev-parse HEAD) && |
908a3203 | 945 | cat >expect <<-EOF && |
b408cf8c | 946 | commit $commit |
908a3203 JH |
947 | Author: A U Thor <author@example.com> |
948 | Date: Thu Apr 7 15:20:13 2005 -0700 | |
ce8daa1e | 949 | |
908a3203 | 950 | ${indent}8th |
ce8daa1e | 951 | |
908a3203 JH |
952 | Notes: |
953 | ${indent}This is a blob object | |
954 | EOF | |
29a40b5a DL |
955 | echo "This is a blob object" | git hash-object -w --stdin >blob && |
956 | git notes add -C $(cat blob) && | |
908a3203 | 957 | git log -1 >actual && |
ce8daa1e | 958 | test_cmp expect actual && |
29a40b5a DL |
959 | git notes list HEAD >actual && |
960 | test_cmp blob actual | |
ce8daa1e JH |
961 | ' |
962 | ||
90bc19b3 TL |
963 | test_expect_success 'create note from blob with "-C", also specify "-m", "-F" and "--separator"' ' |
964 | # 8th will be reuseed in following tests, so rollback when the test is done | |
965 | test_when_finished "git notes remove && git notes add -C $(cat blob)" && | |
966 | commit=$(git rev-parse HEAD) && | |
967 | cat >expect <<-EOF && | |
968 | commit $commit | |
969 | Author: A U Thor <author@example.com> | |
970 | Date: Thu Apr 7 15:20:13 2005 -0700 | |
971 | ||
972 | ${indent}8th | |
973 | ||
974 | Notes: | |
975 | ${indent}This is a blob object | |
976 | ${indent}------- | |
977 | ${indent}This is created by -m | |
978 | ${indent}------- | |
979 | ${indent}This is created by -F | |
980 | EOF | |
981 | ||
982 | git notes remove && | |
983 | echo "This is a blob object" | git hash-object -w --stdin >blob && | |
984 | echo "This is created by -F" >note_a && | |
985 | git notes add -C $(cat blob) -m "This is created by -m" -F note_a --separator="-------" && | |
986 | git log -1 >actual && | |
987 | test_cmp expect actual | |
988 | ' | |
989 | ||
908a3203 | 990 | test_expect_success 'create note from other note with "git notes add -c"' ' |
b408cf8c | 991 | test_commit 9th && |
992 | commit=$(git rev-parse HEAD) && | |
908a3203 | 993 | cat >expect <<-EOF && |
b408cf8c | 994 | commit $commit |
908a3203 JH |
995 | Author: A U Thor <author@example.com> |
996 | Date: Thu Apr 7 15:21:13 2005 -0700 | |
0691cff7 | 997 | |
908a3203 | 998 | ${indent}9th |
0691cff7 | 999 | |
908a3203 JH |
1000 | Notes: |
1001 | ${indent}yet another note | |
1002 | EOF | |
29a40b5a DL |
1003 | note=$(git notes list HEAD^^) && |
1004 | MSG="yet another note" git notes add -c $note && | |
908a3203 | 1005 | git log -1 >actual && |
0691cff7 JH |
1006 | test_cmp expect actual |
1007 | ' | |
1008 | ||
1009 | test_expect_success 'create note from non-existing note with "git notes add -c" fails' ' | |
908a3203 | 1010 | test_commit 10th && |
512477b1 | 1011 | test_must_fail env MSG="yet another note" git notes add -c deadbeef && |
0691cff7 JH |
1012 | test_must_fail git notes list HEAD |
1013 | ' | |
1014 | ||
0691cff7 | 1015 | test_expect_success 'append to note from other note with "git notes append -C"' ' |
b408cf8c | 1016 | commit=$(git rev-parse HEAD^) && |
908a3203 | 1017 | cat >expect <<-EOF && |
b408cf8c | 1018 | commit $commit |
908a3203 JH |
1019 | Author: A U Thor <author@example.com> |
1020 | Date: Thu Apr 7 15:21:13 2005 -0700 | |
1021 | ||
1022 | ${indent}9th | |
1023 | ||
1024 | Notes: | |
1025 | ${indent}yet another note | |
1026 | ${indent} | |
1027 | ${indent}yet another note | |
1028 | EOF | |
29a40b5a DL |
1029 | note=$(git notes list HEAD^) && |
1030 | git notes append -C $note HEAD^ && | |
908a3203 | 1031 | git log -1 HEAD^ >actual && |
0691cff7 JH |
1032 | test_cmp expect actual |
1033 | ' | |
1034 | ||
908a3203 | 1035 | test_expect_success 'create note from other note with "git notes append -c"' ' |
b408cf8c | 1036 | commit=$(git rev-parse HEAD) && |
908a3203 | 1037 | cat >expect <<-EOF && |
b408cf8c | 1038 | commit $commit |
908a3203 JH |
1039 | Author: A U Thor <author@example.com> |
1040 | Date: Thu Apr 7 15:22:13 2005 -0700 | |
0691cff7 | 1041 | |
908a3203 | 1042 | ${indent}10th |
0691cff7 | 1043 | |
908a3203 JH |
1044 | Notes: |
1045 | ${indent}other note | |
1046 | EOF | |
29a40b5a DL |
1047 | note=$(git notes list HEAD^) && |
1048 | MSG="other note" git notes append -c $note && | |
908a3203 | 1049 | git log -1 >actual && |
0691cff7 JH |
1050 | test_cmp expect actual |
1051 | ' | |
1052 | ||
0691cff7 | 1053 | test_expect_success 'append to note from other note with "git notes append -c"' ' |
b408cf8c | 1054 | commit=$(git rev-parse HEAD) && |
908a3203 | 1055 | cat >expect <<-EOF && |
b408cf8c | 1056 | commit $commit |
908a3203 JH |
1057 | Author: A U Thor <author@example.com> |
1058 | Date: Thu Apr 7 15:22:13 2005 -0700 | |
1059 | ||
1060 | ${indent}10th | |
1061 | ||
1062 | Notes: | |
1063 | ${indent}other note | |
1064 | ${indent} | |
1065 | ${indent}yet another note | |
1066 | EOF | |
29a40b5a DL |
1067 | note=$(git notes list HEAD) && |
1068 | MSG="yet another note" git notes append -c $note && | |
908a3203 | 1069 | git log -1 >actual && |
0691cff7 JH |
1070 | test_cmp expect actual |
1071 | ' | |
1072 | ||
e73bbd96 | 1073 | test_expect_success 'copy note with "git notes copy"' ' |
d58deb9c ĐTCD |
1074 | commit=$(git rev-parse 4th) && |
1075 | cat >expect <<-EOF && | |
1076 | commit $commit | |
1077 | Author: A U Thor <author@example.com> | |
1078 | Date: Thu Apr 7 15:16:13 2005 -0700 | |
1079 | ||
1080 | ${indent}4th | |
1081 | ||
1082 | Notes: | |
1083 | ${indent}This is a blob object | |
1084 | EOF | |
1085 | git notes copy 8th 4th && | |
1086 | git log 3rd..4th >actual && | |
1087 | test_cmp expect actual && | |
29a40b5a DL |
1088 | git notes list 4th >expect && |
1089 | git notes list 8th >actual && | |
1090 | test_cmp expect actual | |
d58deb9c ĐTCD |
1091 | ' |
1092 | ||
1093 | test_expect_success 'copy note with "git notes copy" with default' ' | |
b408cf8c | 1094 | test_commit 11th && |
1095 | commit=$(git rev-parse HEAD) && | |
908a3203 | 1096 | cat >expect <<-EOF && |
b408cf8c | 1097 | commit $commit |
908a3203 JH |
1098 | Author: A U Thor <author@example.com> |
1099 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
1100 | ||
1101 | ${indent}11th | |
1102 | ||
1103 | Notes: | |
1104 | ${indent}other note | |
1105 | ${indent} | |
1106 | ${indent}yet another note | |
1107 | EOF | |
d58deb9c | 1108 | git notes copy HEAD^ && |
908a3203 | 1109 | git log -1 >actual && |
e73bbd96 | 1110 | test_cmp expect actual && |
29a40b5a DL |
1111 | git notes list HEAD^ >expect && |
1112 | git notes list HEAD >actual && | |
1113 | test_cmp expect actual | |
e73bbd96 JH |
1114 | ' |
1115 | ||
1116 | test_expect_success 'prevent overwrite with "git notes copy"' ' | |
1117 | test_must_fail git notes copy HEAD~2 HEAD && | |
29a40b5a DL |
1118 | cat >expect <<-EOF && |
1119 | commit $commit | |
1120 | Author: A U Thor <author@example.com> | |
1121 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
1122 | ||
1123 | ${indent}11th | |
1124 | ||
1125 | Notes: | |
1126 | ${indent}other note | |
1127 | ${indent} | |
1128 | ${indent}yet another note | |
1129 | EOF | |
908a3203 | 1130 | git log -1 >actual && |
e73bbd96 | 1131 | test_cmp expect actual && |
29a40b5a DL |
1132 | git notes list HEAD^ >expect && |
1133 | git notes list HEAD >actual && | |
1134 | test_cmp expect actual | |
e73bbd96 JH |
1135 | ' |
1136 | ||
e73bbd96 | 1137 | test_expect_success 'allow overwrite with "git notes copy -f"' ' |
d58deb9c ĐTCD |
1138 | commit=$(git rev-parse HEAD) && |
1139 | cat >expect <<-EOF && | |
1140 | commit $commit | |
1141 | Author: A U Thor <author@example.com> | |
1142 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
1143 | ||
1144 | ${indent}11th | |
1145 | ||
1146 | Notes: | |
1147 | ${indent}This is a blob object | |
1148 | EOF | |
1149 | git notes copy -f HEAD~3 HEAD && | |
1150 | git log -1 >actual && | |
1151 | test_cmp expect actual && | |
29a40b5a DL |
1152 | git notes list HEAD~3 >expect && |
1153 | git notes list HEAD >actual && | |
1154 | test_cmp expect actual | |
d58deb9c ĐTCD |
1155 | ' |
1156 | ||
1157 | test_expect_success 'allow overwrite with "git notes copy -f" with default' ' | |
b408cf8c | 1158 | commit=$(git rev-parse HEAD) && |
908a3203 | 1159 | cat >expect <<-EOF && |
b408cf8c | 1160 | commit $commit |
908a3203 JH |
1161 | Author: A U Thor <author@example.com> |
1162 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
1163 | ||
1164 | ${indent}11th | |
1165 | ||
1166 | Notes: | |
1167 | ${indent}yet another note | |
1168 | ${indent} | |
1169 | ${indent}yet another note | |
1170 | EOF | |
d58deb9c | 1171 | git notes copy -f HEAD~2 && |
908a3203 | 1172 | git log -1 >actual && |
e73bbd96 | 1173 | test_cmp expect actual && |
29a40b5a DL |
1174 | git notes list HEAD~2 >expect && |
1175 | git notes list HEAD >actual && | |
1176 | test_cmp expect actual | |
e73bbd96 JH |
1177 | ' |
1178 | ||
1179 | test_expect_success 'cannot copy note from object without notes' ' | |
908a3203 JH |
1180 | test_commit 12th && |
1181 | test_commit 13th && | |
e73bbd96 JH |
1182 | test_must_fail git notes copy HEAD^ HEAD |
1183 | ' | |
1184 | ||
908a3203 | 1185 | test_expect_success 'git notes copy --stdin' ' |
b408cf8c | 1186 | commit=$(git rev-parse HEAD) && |
1187 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 1188 | cat >expect <<-EOF && |
b408cf8c | 1189 | commit $commit |
908a3203 JH |
1190 | Author: A U Thor <author@example.com> |
1191 | Date: Thu Apr 7 15:25:13 2005 -0700 | |
160baa0d | 1192 | |
908a3203 | 1193 | ${indent}13th |
160baa0d | 1194 | |
908a3203 JH |
1195 | Notes: |
1196 | ${indent}yet another note | |
1197 | ${indent} | |
1198 | ${indent}yet another note | |
160baa0d | 1199 | |
b408cf8c | 1200 | commit $parent |
908a3203 JH |
1201 | Author: A U Thor <author@example.com> |
1202 | Date: Thu Apr 7 15:24:13 2005 -0700 | |
160baa0d | 1203 | |
908a3203 | 1204 | ${indent}12th |
160baa0d | 1205 | |
908a3203 JH |
1206 | Notes: |
1207 | ${indent}other note | |
1208 | ${indent} | |
1209 | ${indent}yet another note | |
1210 | EOF | |
29a40b5a DL |
1211 | from=$(git rev-parse HEAD~3) && |
1212 | to=$(git rev-parse HEAD^) && | |
1213 | echo "$from" "$to" >copy && | |
1214 | from=$(git rev-parse HEAD~2) && | |
1215 | to=$(git rev-parse HEAD) && | |
1216 | echo "$from" "$to" >>copy && | |
1217 | git notes copy --stdin <copy && | |
908a3203 JH |
1218 | git log -2 >actual && |
1219 | test_cmp expect actual && | |
29a40b5a DL |
1220 | git notes list HEAD~2 >expect && |
1221 | git notes list HEAD >actual && | |
1222 | test_cmp expect actual && | |
1223 | git notes list HEAD~3 >expect && | |
1224 | git notes list HEAD^ >actual && | |
1225 | test_cmp expect actual | |
160baa0d TR |
1226 | ' |
1227 | ||
908a3203 | 1228 | test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' |
b408cf8c | 1229 | test_commit 14th && |
1230 | test_commit 15th && | |
1231 | commit=$(git rev-parse HEAD) && | |
1232 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 1233 | cat >expect <<-EOF && |
b408cf8c | 1234 | commit $commit |
908a3203 JH |
1235 | Author: A U Thor <author@example.com> |
1236 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 1237 | |
908a3203 | 1238 | ${indent}15th |
6956f858 | 1239 | |
b408cf8c | 1240 | commit $parent |
908a3203 JH |
1241 | Author: A U Thor <author@example.com> |
1242 | Date: Thu Apr 7 15:26:13 2005 -0700 | |
6956f858 | 1243 | |
908a3203 JH |
1244 | ${indent}14th |
1245 | EOF | |
29a40b5a DL |
1246 | from=$(git rev-parse HEAD~3) && |
1247 | to=$(git rev-parse HEAD^) && | |
1248 | echo "$from" "$to" >copy && | |
1249 | from=$(git rev-parse HEAD~2) && | |
1250 | to=$(git rev-parse HEAD) && | |
1251 | echo "$from" "$to" >>copy && | |
1252 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1253 | git log -2 >actual && |
1254 | test_cmp expect actual | |
6956f858 TR |
1255 | ' |
1256 | ||
6956f858 | 1257 | test_expect_success 'git notes copy --for-rewrite (enabled)' ' |
b408cf8c | 1258 | commit=$(git rev-parse HEAD) && |
1259 | parent=$(git rev-parse HEAD^) && | |
908a3203 | 1260 | cat >expect <<-EOF && |
b408cf8c | 1261 | commit $commit |
908a3203 JH |
1262 | Author: A U Thor <author@example.com> |
1263 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1264 | ||
1265 | ${indent}15th | |
1266 | ||
1267 | Notes: | |
1268 | ${indent}yet another note | |
1269 | ${indent} | |
1270 | ${indent}yet another note | |
1271 | ||
b408cf8c | 1272 | commit $parent |
908a3203 JH |
1273 | Author: A U Thor <author@example.com> |
1274 | Date: Thu Apr 7 15:26:13 2005 -0700 | |
1275 | ||
1276 | ${indent}14th | |
1277 | ||
1278 | Notes: | |
1279 | ${indent}other note | |
1280 | ${indent} | |
1281 | ${indent}yet another note | |
1282 | EOF | |
1283 | test_config notes.rewriteMode overwrite && | |
1284 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1285 | from=$(git rev-parse HEAD~3) && |
1286 | to=$(git rev-parse HEAD^) && | |
1287 | echo "$from" "$to" >copy && | |
1288 | from=$(git rev-parse HEAD~2) && | |
1289 | to=$(git rev-parse HEAD) && | |
1290 | echo "$from" "$to" >>copy && | |
1291 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1292 | git log -2 >actual && |
1293 | test_cmp expect actual | |
6956f858 TR |
1294 | ' |
1295 | ||
1296 | test_expect_success 'git notes copy --for-rewrite (disabled)' ' | |
908a3203 | 1297 | test_config notes.rewrite.bar false && |
29a40b5a DL |
1298 | from=$(git rev-parse HEAD~3) && |
1299 | to=$(git rev-parse HEAD) && | |
1300 | echo "$from" "$to" >copy && | |
1301 | git notes copy --for-rewrite=bar <copy && | |
908a3203 JH |
1302 | git log -2 >actual && |
1303 | test_cmp expect actual | |
6956f858 TR |
1304 | ' |
1305 | ||
908a3203 | 1306 | test_expect_success 'git notes copy --for-rewrite (overwrite)' ' |
b408cf8c | 1307 | commit=$(git rev-parse HEAD) && |
908a3203 | 1308 | cat >expect <<-EOF && |
b408cf8c | 1309 | commit $commit |
908a3203 JH |
1310 | Author: A U Thor <author@example.com> |
1311 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 1312 | |
908a3203 | 1313 | ${indent}15th |
6956f858 | 1314 | |
908a3203 JH |
1315 | Notes: |
1316 | ${indent}a fresh note | |
1317 | EOF | |
6956f858 | 1318 | git notes add -f -m"a fresh note" HEAD^ && |
908a3203 JH |
1319 | test_config notes.rewriteMode overwrite && |
1320 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1321 | from=$(git rev-parse HEAD^) && |
1322 | to=$(git rev-parse HEAD) && | |
1323 | echo "$from" "$to" >copy && | |
1324 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1325 | git log -1 >actual && |
1326 | test_cmp expect actual | |
6956f858 TR |
1327 | ' |
1328 | ||
1329 | test_expect_success 'git notes copy --for-rewrite (ignore)' ' | |
908a3203 JH |
1330 | test_config notes.rewriteMode ignore && |
1331 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1332 | from=$(git rev-parse HEAD^) && |
1333 | to=$(git rev-parse HEAD) && | |
1334 | echo "$from" "$to" >copy && | |
1335 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1336 | git log -1 >actual && |
1337 | test_cmp expect actual | |
6956f858 TR |
1338 | ' |
1339 | ||
6956f858 | 1340 | test_expect_success 'git notes copy --for-rewrite (append)' ' |
b408cf8c | 1341 | commit=$(git rev-parse HEAD) && |
908a3203 | 1342 | cat >expect <<-EOF && |
b408cf8c | 1343 | commit $commit |
908a3203 JH |
1344 | Author: A U Thor <author@example.com> |
1345 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1346 | ||
1347 | ${indent}15th | |
1348 | ||
1349 | Notes: | |
1350 | ${indent}a fresh note | |
1351 | ${indent} | |
1352 | ${indent}another fresh note | |
1353 | EOF | |
6956f858 | 1354 | git notes add -f -m"another fresh note" HEAD^ && |
908a3203 JH |
1355 | test_config notes.rewriteMode concatenate && |
1356 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1357 | from=$(git rev-parse HEAD^) && |
1358 | to=$(git rev-parse HEAD) && | |
1359 | echo "$from" "$to" >copy && | |
1360 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1361 | git log -1 >actual && |
1362 | test_cmp expect actual | |
6956f858 TR |
1363 | ' |
1364 | ||
6956f858 | 1365 | test_expect_success 'git notes copy --for-rewrite (append two to one)' ' |
b408cf8c | 1366 | commit=$(git rev-parse HEAD) && |
908a3203 | 1367 | cat >expect <<-EOF && |
b408cf8c | 1368 | commit $commit |
908a3203 JH |
1369 | Author: A U Thor <author@example.com> |
1370 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1371 | ||
1372 | ${indent}15th | |
1373 | ||
1374 | Notes: | |
1375 | ${indent}a fresh note | |
1376 | ${indent} | |
1377 | ${indent}another fresh note | |
1378 | ${indent} | |
1379 | ${indent}append 1 | |
1380 | ${indent} | |
1381 | ${indent}append 2 | |
1382 | EOF | |
6956f858 TR |
1383 | git notes add -f -m"append 1" HEAD^ && |
1384 | git notes add -f -m"append 2" HEAD^^ && | |
908a3203 JH |
1385 | test_config notes.rewriteMode concatenate && |
1386 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1387 | from=$(git rev-parse HEAD^) && |
1388 | to=$(git rev-parse HEAD) && | |
1389 | echo "$from" "$to" >copy && | |
1390 | from=$(git rev-parse HEAD^^) && | |
1391 | to=$(git rev-parse HEAD) && | |
1392 | echo "$from" "$to" >>copy && | |
1393 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1394 | git log -1 >actual && |
1395 | test_cmp expect actual | |
6956f858 TR |
1396 | ' |
1397 | ||
1398 | test_expect_success 'git notes copy --for-rewrite (append empty)' ' | |
1399 | git notes remove HEAD^ && | |
908a3203 JH |
1400 | test_config notes.rewriteMode concatenate && |
1401 | test_config notes.rewriteRef "refs/notes/*" && | |
29a40b5a DL |
1402 | from=$(git rev-parse HEAD^) && |
1403 | to=$(git rev-parse HEAD) && | |
1404 | echo "$from" "$to" >copy && | |
1405 | git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1406 | git log -1 >actual && |
1407 | test_cmp expect actual | |
6956f858 TR |
1408 | ' |
1409 | ||
6956f858 | 1410 | test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' |
b408cf8c | 1411 | commit=$(git rev-parse HEAD) && |
908a3203 | 1412 | cat >expect <<-EOF && |
b408cf8c | 1413 | commit $commit |
908a3203 JH |
1414 | Author: A U Thor <author@example.com> |
1415 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1416 | ||
1417 | ${indent}15th | |
1418 | ||
1419 | Notes: | |
1420 | ${indent}replacement note 1 | |
1421 | EOF | |
1422 | test_config notes.rewriteMode concatenate && | |
1423 | test_config notes.rewriteRef "refs/notes/*" && | |
6956f858 | 1424 | git notes add -f -m"replacement note 1" HEAD^ && |
29a40b5a DL |
1425 | from=$(git rev-parse HEAD^) && |
1426 | to=$(git rev-parse HEAD) && | |
1427 | echo "$from" "$to" >copy && | |
1428 | GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy && | |
908a3203 JH |
1429 | git log -1 >actual && |
1430 | test_cmp expect actual | |
6956f858 TR |
1431 | ' |
1432 | ||
908a3203 | 1433 | test_expect_success 'GIT_NOTES_REWRITE_REF works' ' |
b408cf8c | 1434 | commit=$(git rev-parse HEAD) && |
908a3203 | 1435 | cat >expect <<-EOF && |
b408cf8c | 1436 | commit $commit |
908a3203 JH |
1437 | Author: A U Thor <author@example.com> |
1438 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 1439 | |
908a3203 | 1440 | ${indent}15th |
6956f858 | 1441 | |
908a3203 JH |
1442 | Notes: |
1443 | ${indent}replacement note 2 | |
1444 | EOF | |
6956f858 | 1445 | git notes add -f -m"replacement note 2" HEAD^ && |
908a3203 JH |
1446 | test_config notes.rewriteMode overwrite && |
1447 | test_unconfig notes.rewriteRef && | |
29a40b5a DL |
1448 | from=$(git rev-parse HEAD^) && |
1449 | to=$(git rev-parse HEAD) && | |
1450 | echo "$from" "$to" >copy && | |
6956f858 | 1451 | GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ |
29a40b5a | 1452 | git notes copy --for-rewrite=foo <copy && |
908a3203 JH |
1453 | git log -1 >actual && |
1454 | test_cmp expect actual | |
6956f858 TR |
1455 | ' |
1456 | ||
1457 | test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' | |
6956f858 | 1458 | git notes add -f -m"replacement note 3" HEAD^ && |
908a3203 JH |
1459 | test_config notes.rewriteMode overwrite && |
1460 | test_config notes.rewriteRef refs/notes/other && | |
29a40b5a DL |
1461 | from=$(git rev-parse HEAD^) && |
1462 | to=$(git rev-parse HEAD) && | |
1463 | echo "$from" "$to" >copy && | |
dbe7b410 | 1464 | GIT_NOTES_REWRITE_REF=refs/notes/commits \ |
29a40b5a | 1465 | git notes copy --for-rewrite=foo <copy && |
908a3203 | 1466 | git log -1 >actual && |
dbe7b410 | 1467 | grep "replacement note 3" actual |
6956f858 | 1468 | ' |
bbb1b8a3 | 1469 | |
b8657347 | 1470 | test_expect_success 'git notes copy diagnoses too many or too few arguments' ' |
8af69cf3 | 1471 | test_must_fail git notes copy 2>error && |
6789275d | 1472 | test_grep "too few arguments" error && |
8af69cf3 | 1473 | test_must_fail git notes copy one two three 2>error && |
6789275d | 1474 | test_grep "too many arguments" error |
bbb1b8a3 JK |
1475 | ' |
1476 | ||
d6c6b108 | 1477 | test_expect_success 'git notes get-ref expands refs/heads/main to refs/notes/refs/heads/main' ' |
e14c92e8 JK |
1478 | test_unconfig core.notesRef && |
1479 | sane_unset GIT_NOTES_REF && | |
d6c6b108 JS |
1480 | echo refs/notes/refs/heads/main >expect && |
1481 | git notes --ref=refs/heads/main get-ref >actual && | |
29a40b5a | 1482 | test_cmp expect actual |
e14c92e8 JK |
1483 | ' |
1484 | ||
618cd757 | 1485 | test_expect_success 'git notes get-ref (no overrides)' ' |
908a3203 | 1486 | test_unconfig core.notesRef && |
ed40ec55 | 1487 | sane_unset GIT_NOTES_REF && |
29a40b5a DL |
1488 | echo refs/notes/commits >expect && |
1489 | git notes get-ref >actual && | |
1490 | test_cmp expect actual | |
618cd757 JH |
1491 | ' |
1492 | ||
1493 | test_expect_success 'git notes get-ref (core.notesRef)' ' | |
908a3203 | 1494 | test_config core.notesRef refs/notes/foo && |
29a40b5a DL |
1495 | echo refs/notes/foo >expect && |
1496 | git notes get-ref >actual && | |
1497 | test_cmp expect actual | |
618cd757 JH |
1498 | ' |
1499 | ||
1500 | test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' | |
29a40b5a DL |
1501 | echo refs/notes/bar >expect && |
1502 | GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual && | |
1503 | test_cmp expect actual | |
618cd757 JH |
1504 | ' |
1505 | ||
1506 | test_expect_success 'git notes get-ref (--ref)' ' | |
29a40b5a DL |
1507 | echo refs/notes/baz >expect && |
1508 | GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual && | |
1509 | test_cmp expect actual | |
618cd757 JH |
1510 | ' |
1511 | ||
d0923b6d JH |
1512 | test_expect_success 'setup testing of empty notes' ' |
1513 | test_unconfig core.notesRef && | |
1514 | test_commit 16th && | |
d73a5b93 JH |
1515 | empty_blob=$(git hash-object -w /dev/null) && |
1516 | echo "$empty_blob" >expect_empty | |
d0923b6d JH |
1517 | ' |
1518 | ||
1519 | while read cmd | |
1520 | do | |
1521 | test_expect_success "'git notes $cmd' removes empty note" " | |
1522 | test_might_fail git notes remove HEAD && | |
1523 | MSG= git notes $cmd && | |
1524 | test_must_fail git notes list HEAD | |
1525 | " | |
d73a5b93 JH |
1526 | |
1527 | test_expect_success "'git notes $cmd --allow-empty' stores empty note" " | |
1528 | test_might_fail git notes remove HEAD && | |
1529 | MSG= git notes $cmd --allow-empty && | |
1530 | git notes list HEAD >actual && | |
1531 | test_cmp expect_empty actual | |
1532 | " | |
d0923b6d JH |
1533 | done <<\EOF |
1534 | add | |
1535 | add -F /dev/null | |
1536 | add -m "" | |
1537 | add -c "$empty_blob" | |
1538 | add -C "$empty_blob" | |
1539 | append | |
1540 | append -F /dev/null | |
1541 | append -m "" | |
1542 | append -c "$empty_blob" | |
1543 | append -C "$empty_blob" | |
1544 | edit | |
1545 | EOF | |
1546 | ||
8a4acd69 JH |
1547 | test_expect_success 'empty notes are displayed by git log' ' |
1548 | test_commit 17th && | |
1549 | git log -1 >expect && | |
908a3203 | 1550 | cat >>expect <<-EOF && |
8a4acd69 | 1551 | |
908a3203 JH |
1552 | Notes: |
1553 | EOF | |
8a4acd69 JH |
1554 | git notes add -C "$empty_blob" --allow-empty && |
1555 | git log -1 >actual && | |
1556 | test_cmp expect actual | |
1557 | ' | |
1558 | ||
65d9fb48 | 1559 | test_done |