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