]>
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 | 484 | test_must_fail git notes list HEAD >actual && |
1c5e94f4 | 485 | test_must_be_empty actual |
e397421a JH |
486 | ' |
487 | ||
2347fae5 | 488 | test_expect_success 'append to existing note with "git notes append"' ' |
908a3203 JH |
489 | cat >expect <<-EOF && |
490 | Initial set of notes | |
491 | ||
492 | More notes appended with git notes append | |
493 | EOF | |
2347fae5 JH |
494 | git notes add -m "Initial set of notes" && |
495 | git notes append -m "More notes appended with git notes append" && | |
908a3203 JH |
496 | git notes show >actual && |
497 | test_cmp expect actual | |
2347fae5 JH |
498 | ' |
499 | ||
74884b52 | 500 | test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' |
908a3203 JH |
501 | cat >expect_list <<-EOF && |
502 | c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691 | |
503 | 4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 | |
504 | c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290 | |
505 | EOF | |
506 | git notes list >actual && | |
507 | test_cmp expect_list actual | |
74884b52 SB |
508 | ' |
509 | ||
2347fae5 JH |
510 | test_expect_success 'appending empty string does not change existing note' ' |
511 | git notes append -m "" && | |
908a3203 JH |
512 | git notes show >actual && |
513 | test_cmp expect actual | |
2347fae5 JH |
514 | ' |
515 | ||
516 | test_expect_success 'git notes append == add when there is no existing note' ' | |
517 | git notes remove HEAD && | |
518 | test_must_fail git notes list HEAD && | |
908a3203 JH |
519 | git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" && |
520 | git notes show >actual && | |
521 | test_cmp expect actual | |
2347fae5 JH |
522 | ' |
523 | ||
524 | test_expect_success 'appending empty string to non-existing note does not create note' ' | |
525 | git notes remove HEAD && | |
526 | test_must_fail git notes list HEAD && | |
527 | git notes append -m "" && | |
528 | test_must_fail git notes list HEAD | |
529 | ' | |
530 | ||
cd067d3b | 531 | test_expect_success 'create other note on a different notes ref (setup)' ' |
908a3203 JH |
532 | test_commit 6th && |
533 | GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" && | |
534 | cat >expect-not-other <<-EOF && | |
535 | commit 2c125331118caba0ff8238b7f4958ac6e93fe39c | |
536 | Author: A U Thor <author@example.com> | |
537 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
cd067d3b | 538 | |
908a3203 JH |
539 | ${indent}6th |
540 | EOF | |
541 | cp expect-not-other expect-other && | |
542 | cat >>expect-other <<-EOF | |
cd067d3b | 543 | |
908a3203 JH |
544 | Notes (other): |
545 | ${indent}other note | |
546 | EOF | |
547 | ' | |
3b78cdbe JH |
548 | |
549 | test_expect_success 'Do not show note on other ref by default' ' | |
908a3203 JH |
550 | git log -1 >actual && |
551 | test_cmp expect-not-other actual | |
3b78cdbe JH |
552 | ' |
553 | ||
554 | test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' ' | |
908a3203 JH |
555 | GIT_NOTES_REF="refs/notes/other" git log -1 >actual && |
556 | test_cmp expect-other actual | |
3b78cdbe JH |
557 | ' |
558 | ||
559 | test_expect_success 'Do show note when ref is given in core.notesRef config' ' | |
908a3203 JH |
560 | test_config core.notesRef "refs/notes/other" && |
561 | git log -1 >actual && | |
562 | test_cmp expect-other actual | |
3b78cdbe JH |
563 | ' |
564 | ||
565 | test_expect_success 'Do not show note when core.notesRef is overridden' ' | |
908a3203 JH |
566 | test_config core.notesRef "refs/notes/other" && |
567 | GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual && | |
568 | test_cmp expect-not-other actual | |
3b78cdbe JH |
569 | ' |
570 | ||
908a3203 JH |
571 | test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' ' |
572 | cat >expect-both <<-EOF && | |
573 | commit 2c125331118caba0ff8238b7f4958ac6e93fe39c | |
574 | Author: A U Thor <author@example.com> | |
575 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 576 | |
908a3203 | 577 | ${indent}6th |
894a9d33 | 578 | |
908a3203 JH |
579 | Notes: |
580 | ${indent}order test | |
894a9d33 | 581 | |
908a3203 JH |
582 | Notes (other): |
583 | ${indent}other note | |
894a9d33 | 584 | |
908a3203 JH |
585 | commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 |
586 | Author: A U Thor <author@example.com> | |
587 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
894a9d33 | 588 | |
908a3203 | 589 | ${indent}5th |
894a9d33 | 590 | |
908a3203 JH |
591 | Notes: |
592 | ${indent}replacement for deleted note | |
593 | EOF | |
894a9d33 TR |
594 | GIT_NOTES_REF=refs/notes/commits git notes add \ |
595 | -m"replacement for deleted note" HEAD^ && | |
596 | GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" && | |
908a3203 JH |
597 | test_unconfig core.notesRef && |
598 | test_config notes.displayRef "refs/notes/*" && | |
599 | git log -2 >actual && | |
600 | test_cmp expect-both actual | |
894a9d33 TR |
601 | ' |
602 | ||
603 | test_expect_success 'core.notesRef is implicitly in notes.displayRef' ' | |
908a3203 JH |
604 | test_config core.notesRef refs/notes/commits && |
605 | test_config notes.displayRef refs/notes/other && | |
606 | git log -2 >actual && | |
607 | test_cmp expect-both actual | |
894a9d33 TR |
608 | ' |
609 | ||
610 | test_expect_success 'notes.displayRef can be given more than once' ' | |
908a3203 JH |
611 | test_unconfig core.notesRef && |
612 | test_config notes.displayRef refs/notes/commits && | |
894a9d33 | 613 | git config --add notes.displayRef refs/notes/other && |
908a3203 JH |
614 | git log -2 >actual && |
615 | test_cmp expect-both actual | |
894a9d33 TR |
616 | ' |
617 | ||
908a3203 JH |
618 | test_expect_success 'notes.displayRef respects order' ' |
619 | cat >expect-both-reversed <<-EOF && | |
620 | commit 2c125331118caba0ff8238b7f4958ac6e93fe39c | |
621 | Author: A U Thor <author@example.com> | |
622 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 623 | |
908a3203 | 624 | ${indent}6th |
894a9d33 | 625 | |
908a3203 JH |
626 | Notes (other): |
627 | ${indent}other note | |
894a9d33 | 628 | |
908a3203 JH |
629 | Notes: |
630 | ${indent}order test | |
631 | EOF | |
632 | test_config core.notesRef refs/notes/other && | |
633 | test_config notes.displayRef refs/notes/commits && | |
634 | git log -1 >actual && | |
635 | test_cmp expect-both-reversed actual | |
894a9d33 TR |
636 | ' |
637 | ||
638 | test_expect_success 'GIT_NOTES_DISPLAY_REF works' ' | |
894a9d33 | 639 | GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \ |
908a3203 JH |
640 | git log -2 >actual && |
641 | test_cmp expect-both actual | |
894a9d33 TR |
642 | ' |
643 | ||
908a3203 JH |
644 | test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' ' |
645 | cat >expect-none <<-EOF && | |
646 | commit 2c125331118caba0ff8238b7f4958ac6e93fe39c | |
647 | Author: A U Thor <author@example.com> | |
648 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 649 | |
908a3203 | 650 | ${indent}6th |
894a9d33 | 651 | |
908a3203 JH |
652 | commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 |
653 | Author: A U Thor <author@example.com> | |
654 | Date: Thu Apr 7 15:17:13 2005 -0700 | |
894a9d33 | 655 | |
908a3203 JH |
656 | ${indent}5th |
657 | EOF | |
658 | test_config notes.displayRef "refs/notes/*" && | |
659 | GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual && | |
660 | test_cmp expect-none actual | |
894a9d33 TR |
661 | ' |
662 | ||
663 | test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' ' | |
908a3203 JH |
664 | GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual && |
665 | test_cmp expect-both actual | |
894a9d33 TR |
666 | ' |
667 | ||
908a3203 | 668 | test_expect_success '--no-standard-notes' ' |
85cb1d0b | 669 | cat >expect-commits <<-EOF && |
908a3203 JH |
670 | commit 2c125331118caba0ff8238b7f4958ac6e93fe39c |
671 | Author: A U Thor <author@example.com> | |
672 | Date: Thu Apr 7 15:18:13 2005 -0700 | |
894a9d33 | 673 | |
908a3203 | 674 | ${indent}6th |
894a9d33 | 675 | |
908a3203 JH |
676 | Notes: |
677 | ${indent}order test | |
678 | EOF | |
679 | git log --no-standard-notes --show-notes=commits -1 >actual && | |
680 | test_cmp expect-commits actual | |
894a9d33 TR |
681 | ' |
682 | ||
683 | test_expect_success '--standard-notes' ' | |
908a3203 | 684 | test_config notes.displayRef "refs/notes/*" && |
894a9d33 | 685 | git log --no-standard-notes --show-notes=commits \ |
908a3203 JH |
686 | --standard-notes -2 >actual && |
687 | test_cmp expect-both actual | |
894a9d33 TR |
688 | ' |
689 | ||
690 | test_expect_success '--show-notes=ref accumulates' ' | |
691 | git log --show-notes=other --show-notes=commits \ | |
908a3203 JH |
692 | --no-standard-notes -1 >actual && |
693 | test_cmp expect-both-reversed actual | |
894a9d33 TR |
694 | ' |
695 | ||
b24bb997 | 696 | test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' |
908a3203 JH |
697 | test_config core.notesRef refs/notes/other && |
698 | echo "Note on a tree" >expect && | |
7aa4754e | 699 | git notes add -m "Note on a tree" HEAD: && |
908a3203 | 700 | git notes show HEAD: >actual && |
b24bb997 | 701 | test_cmp expect actual && |
908a3203 | 702 | echo "Note on a blob" >expect && |
b24bb997 | 703 | filename=$(git ls-tree --name-only HEAD | head -n1) && |
7aa4754e | 704 | git notes add -m "Note on a blob" HEAD:$filename && |
908a3203 | 705 | git notes show HEAD:$filename >actual && |
b24bb997 | 706 | test_cmp expect actual && |
908a3203 | 707 | echo "Note on a tag" >expect && |
b24bb997 | 708 | git tag -a -m "This is an annotated tag" foobar HEAD^ && |
7aa4754e | 709 | git notes add -m "Note on a tag" foobar && |
908a3203 | 710 | git notes show foobar >actual && |
b24bb997 JH |
711 | test_cmp expect actual |
712 | ' | |
713 | ||
908a3203 JH |
714 | test_expect_success 'create note from other note with "git notes add -C"' ' |
715 | cat >expect <<-EOF && | |
716 | commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c | |
717 | Author: A U Thor <author@example.com> | |
718 | Date: Thu Apr 7 15:19:13 2005 -0700 | |
0691cff7 | 719 | |
908a3203 | 720 | ${indent}7th |
0691cff7 | 721 | |
908a3203 JH |
722 | Notes: |
723 | ${indent}order test | |
724 | EOF | |
725 | test_commit 7th && | |
0691cff7 | 726 | git notes add -C $(git notes list HEAD^) && |
908a3203 | 727 | git log -1 >actual && |
0691cff7 JH |
728 | test_cmp expect actual && |
729 | test "$(git notes list HEAD)" = "$(git notes list HEAD^)" | |
730 | ' | |
731 | ||
732 | test_expect_success 'create note from non-existing note with "git notes add -C" fails' ' | |
908a3203 | 733 | test_commit 8th && |
0691cff7 JH |
734 | test_must_fail git notes add -C deadbeef && |
735 | test_must_fail git notes list HEAD | |
736 | ' | |
737 | ||
ce8daa1e JH |
738 | test_expect_success 'create note from non-blob with "git notes add -C" fails' ' |
739 | commit=$(git rev-parse --verify HEAD) && | |
740 | tree=$(git rev-parse --verify HEAD:) && | |
741 | test_must_fail git notes add -C $commit && | |
742 | test_must_fail git notes add -C $tree && | |
743 | test_must_fail git notes list HEAD | |
744 | ' | |
745 | ||
908a3203 JH |
746 | test_expect_success 'create note from blob with "git notes add -C" reuses blob id' ' |
747 | cat >expect <<-EOF && | |
748 | commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf | |
749 | Author: A U Thor <author@example.com> | |
750 | Date: Thu Apr 7 15:20:13 2005 -0700 | |
ce8daa1e | 751 | |
908a3203 | 752 | ${indent}8th |
ce8daa1e | 753 | |
908a3203 JH |
754 | Notes: |
755 | ${indent}This is a blob object | |
756 | EOF | |
ce8daa1e JH |
757 | blob=$(echo "This is a blob object" | git hash-object -w --stdin) && |
758 | git notes add -C $blob && | |
908a3203 | 759 | git log -1 >actual && |
ce8daa1e JH |
760 | test_cmp expect actual && |
761 | test "$(git notes list HEAD)" = "$blob" | |
762 | ' | |
763 | ||
908a3203 JH |
764 | test_expect_success 'create note from other note with "git notes add -c"' ' |
765 | cat >expect <<-EOF && | |
766 | commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2 | |
767 | Author: A U Thor <author@example.com> | |
768 | Date: Thu Apr 7 15:21:13 2005 -0700 | |
0691cff7 | 769 | |
908a3203 | 770 | ${indent}9th |
0691cff7 | 771 | |
908a3203 JH |
772 | Notes: |
773 | ${indent}yet another note | |
774 | EOF | |
775 | test_commit 9th && | |
0691cff7 | 776 | MSG="yet another note" git notes add -c $(git notes list HEAD^^) && |
908a3203 | 777 | git log -1 >actual && |
0691cff7 JH |
778 | test_cmp expect actual |
779 | ' | |
780 | ||
781 | test_expect_success 'create note from non-existing note with "git notes add -c" fails' ' | |
908a3203 | 782 | test_commit 10th && |
512477b1 | 783 | test_must_fail env MSG="yet another note" git notes add -c deadbeef && |
0691cff7 JH |
784 | test_must_fail git notes list HEAD |
785 | ' | |
786 | ||
0691cff7 | 787 | test_expect_success 'append to note from other note with "git notes append -C"' ' |
908a3203 JH |
788 | cat >expect <<-EOF && |
789 | commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2 | |
790 | Author: A U Thor <author@example.com> | |
791 | Date: Thu Apr 7 15:21:13 2005 -0700 | |
792 | ||
793 | ${indent}9th | |
794 | ||
795 | Notes: | |
796 | ${indent}yet another note | |
797 | ${indent} | |
798 | ${indent}yet another note | |
799 | EOF | |
0691cff7 | 800 | git notes append -C $(git notes list HEAD^) HEAD^ && |
908a3203 | 801 | git log -1 HEAD^ >actual && |
0691cff7 JH |
802 | test_cmp expect actual |
803 | ' | |
804 | ||
908a3203 JH |
805 | test_expect_success 'create note from other note with "git notes append -c"' ' |
806 | cat >expect <<-EOF && | |
807 | commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406 | |
808 | Author: A U Thor <author@example.com> | |
809 | Date: Thu Apr 7 15:22:13 2005 -0700 | |
0691cff7 | 810 | |
908a3203 | 811 | ${indent}10th |
0691cff7 | 812 | |
908a3203 JH |
813 | Notes: |
814 | ${indent}other note | |
815 | EOF | |
0691cff7 | 816 | MSG="other note" git notes append -c $(git notes list HEAD^) && |
908a3203 | 817 | git log -1 >actual && |
0691cff7 JH |
818 | test_cmp expect actual |
819 | ' | |
820 | ||
0691cff7 | 821 | test_expect_success 'append to note from other note with "git notes append -c"' ' |
908a3203 JH |
822 | cat >expect <<-EOF && |
823 | commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406 | |
824 | Author: A U Thor <author@example.com> | |
825 | Date: Thu Apr 7 15:22:13 2005 -0700 | |
826 | ||
827 | ${indent}10th | |
828 | ||
829 | Notes: | |
830 | ${indent}other note | |
831 | ${indent} | |
832 | ${indent}yet another note | |
833 | EOF | |
0691cff7 | 834 | MSG="yet another note" git notes append -c $(git notes list HEAD) && |
908a3203 | 835 | git log -1 >actual && |
0691cff7 JH |
836 | test_cmp expect actual |
837 | ' | |
838 | ||
e73bbd96 | 839 | test_expect_success 'copy note with "git notes copy"' ' |
908a3203 JH |
840 | cat >expect <<-EOF && |
841 | commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5 | |
842 | Author: A U Thor <author@example.com> | |
843 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
844 | ||
845 | ${indent}11th | |
846 | ||
847 | Notes: | |
848 | ${indent}other note | |
849 | ${indent} | |
850 | ${indent}yet another note | |
851 | EOF | |
852 | test_commit 11th && | |
e73bbd96 | 853 | git notes copy HEAD^ HEAD && |
908a3203 | 854 | git log -1 >actual && |
e73bbd96 JH |
855 | test_cmp expect actual && |
856 | test "$(git notes list HEAD)" = "$(git notes list HEAD^)" | |
857 | ' | |
858 | ||
859 | test_expect_success 'prevent overwrite with "git notes copy"' ' | |
860 | test_must_fail git notes copy HEAD~2 HEAD && | |
908a3203 | 861 | git log -1 >actual && |
e73bbd96 JH |
862 | test_cmp expect actual && |
863 | test "$(git notes list HEAD)" = "$(git notes list HEAD^)" | |
864 | ' | |
865 | ||
e73bbd96 | 866 | test_expect_success 'allow overwrite with "git notes copy -f"' ' |
908a3203 JH |
867 | cat >expect <<-EOF && |
868 | commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5 | |
869 | Author: A U Thor <author@example.com> | |
870 | Date: Thu Apr 7 15:23:13 2005 -0700 | |
871 | ||
872 | ${indent}11th | |
873 | ||
874 | Notes: | |
875 | ${indent}yet another note | |
876 | ${indent} | |
877 | ${indent}yet another note | |
878 | EOF | |
e73bbd96 | 879 | git notes copy -f HEAD~2 HEAD && |
908a3203 | 880 | git log -1 >actual && |
e73bbd96 JH |
881 | test_cmp expect actual && |
882 | test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" | |
883 | ' | |
884 | ||
885 | test_expect_success 'cannot copy note from object without notes' ' | |
908a3203 JH |
886 | test_commit 12th && |
887 | test_commit 13th && | |
e73bbd96 JH |
888 | test_must_fail git notes copy HEAD^ HEAD |
889 | ' | |
890 | ||
908a3203 JH |
891 | test_expect_success 'git notes copy --stdin' ' |
892 | cat >expect <<-EOF && | |
893 | commit e871aa61182b1d95d0a6fb75445d891722863b6b | |
894 | Author: A U Thor <author@example.com> | |
895 | Date: Thu Apr 7 15:25:13 2005 -0700 | |
160baa0d | 896 | |
908a3203 | 897 | ${indent}13th |
160baa0d | 898 | |
908a3203 JH |
899 | Notes: |
900 | ${indent}yet another note | |
901 | ${indent} | |
902 | ${indent}yet another note | |
160baa0d | 903 | |
908a3203 JH |
904 | commit 65e263ded02ae4e8839bc151095113737579dc12 |
905 | Author: A U Thor <author@example.com> | |
906 | Date: Thu Apr 7 15:24:13 2005 -0700 | |
160baa0d | 907 | |
908a3203 | 908 | ${indent}12th |
160baa0d | 909 | |
908a3203 JH |
910 | Notes: |
911 | ${indent}other note | |
912 | ${indent} | |
913 | ${indent}yet another note | |
914 | EOF | |
3ea67379 | 915 | (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && |
160baa0d TR |
916 | echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | |
917 | git notes copy --stdin && | |
908a3203 JH |
918 | git log -2 >actual && |
919 | test_cmp expect actual && | |
160baa0d TR |
920 | test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && |
921 | test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" | |
922 | ' | |
923 | ||
908a3203 JH |
924 | test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' |
925 | cat >expect <<-EOF && | |
926 | commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 | |
927 | Author: A U Thor <author@example.com> | |
928 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 929 | |
908a3203 | 930 | ${indent}15th |
6956f858 | 931 | |
908a3203 JH |
932 | commit 07c85d77059393ed0154b8c96906547a59dfcddd |
933 | Author: A U Thor <author@example.com> | |
934 | Date: Thu Apr 7 15:26:13 2005 -0700 | |
6956f858 | 935 | |
908a3203 JH |
936 | ${indent}14th |
937 | EOF | |
6956f858 TR |
938 | test_commit 14th && |
939 | test_commit 15th && | |
3ea67379 | 940 | (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && |
6956f858 TR |
941 | echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | |
942 | git notes copy --for-rewrite=foo && | |
908a3203 JH |
943 | git log -2 >actual && |
944 | test_cmp expect actual | |
6956f858 TR |
945 | ' |
946 | ||
6956f858 | 947 | test_expect_success 'git notes copy --for-rewrite (enabled)' ' |
908a3203 JH |
948 | cat >expect <<-EOF && |
949 | commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 | |
950 | Author: A U Thor <author@example.com> | |
951 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
952 | ||
953 | ${indent}15th | |
954 | ||
955 | Notes: | |
956 | ${indent}yet another note | |
957 | ${indent} | |
958 | ${indent}yet another note | |
959 | ||
960 | commit 07c85d77059393ed0154b8c96906547a59dfcddd | |
961 | Author: A U Thor <author@example.com> | |
962 | Date: Thu Apr 7 15:26:13 2005 -0700 | |
963 | ||
964 | ${indent}14th | |
965 | ||
966 | Notes: | |
967 | ${indent}other note | |
968 | ${indent} | |
969 | ${indent}yet another note | |
970 | EOF | |
971 | test_config notes.rewriteMode overwrite && | |
972 | test_config notes.rewriteRef "refs/notes/*" && | |
3ea67379 | 973 | (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && |
6956f858 TR |
974 | echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | |
975 | git notes copy --for-rewrite=foo && | |
908a3203 JH |
976 | git log -2 >actual && |
977 | test_cmp expect actual | |
6956f858 TR |
978 | ' |
979 | ||
980 | test_expect_success 'git notes copy --for-rewrite (disabled)' ' | |
908a3203 | 981 | test_config notes.rewrite.bar false && |
6956f858 TR |
982 | echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) | |
983 | git notes copy --for-rewrite=bar && | |
908a3203 JH |
984 | git log -2 >actual && |
985 | test_cmp expect actual | |
6956f858 TR |
986 | ' |
987 | ||
908a3203 JH |
988 | test_expect_success 'git notes copy --for-rewrite (overwrite)' ' |
989 | cat >expect <<-EOF && | |
990 | commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 | |
991 | Author: A U Thor <author@example.com> | |
992 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 993 | |
908a3203 | 994 | ${indent}15th |
6956f858 | 995 | |
908a3203 JH |
996 | Notes: |
997 | ${indent}a fresh note | |
998 | EOF | |
6956f858 | 999 | git notes add -f -m"a fresh note" HEAD^ && |
908a3203 JH |
1000 | test_config notes.rewriteMode overwrite && |
1001 | test_config notes.rewriteRef "refs/notes/*" && | |
6956f858 TR |
1002 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
1003 | git notes copy --for-rewrite=foo && | |
908a3203 JH |
1004 | git log -1 >actual && |
1005 | test_cmp expect actual | |
6956f858 TR |
1006 | ' |
1007 | ||
1008 | test_expect_success 'git notes copy --for-rewrite (ignore)' ' | |
908a3203 JH |
1009 | test_config notes.rewriteMode ignore && |
1010 | test_config notes.rewriteRef "refs/notes/*" && | |
6956f858 TR |
1011 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
1012 | git notes copy --for-rewrite=foo && | |
908a3203 JH |
1013 | git log -1 >actual && |
1014 | test_cmp expect actual | |
6956f858 TR |
1015 | ' |
1016 | ||
6956f858 | 1017 | test_expect_success 'git notes copy --for-rewrite (append)' ' |
908a3203 JH |
1018 | cat >expect <<-EOF && |
1019 | commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 | |
1020 | Author: A U Thor <author@example.com> | |
1021 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1022 | ||
1023 | ${indent}15th | |
1024 | ||
1025 | Notes: | |
1026 | ${indent}a fresh note | |
1027 | ${indent} | |
1028 | ${indent}another fresh note | |
1029 | EOF | |
6956f858 | 1030 | git notes add -f -m"another fresh note" HEAD^ && |
908a3203 JH |
1031 | test_config notes.rewriteMode concatenate && |
1032 | test_config notes.rewriteRef "refs/notes/*" && | |
6956f858 TR |
1033 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
1034 | git notes copy --for-rewrite=foo && | |
908a3203 JH |
1035 | git log -1 >actual && |
1036 | test_cmp expect actual | |
6956f858 TR |
1037 | ' |
1038 | ||
6956f858 | 1039 | test_expect_success 'git notes copy --for-rewrite (append two to one)' ' |
908a3203 JH |
1040 | cat >expect <<-EOF && |
1041 | commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 | |
1042 | Author: A U Thor <author@example.com> | |
1043 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1044 | ||
1045 | ${indent}15th | |
1046 | ||
1047 | Notes: | |
1048 | ${indent}a fresh note | |
1049 | ${indent} | |
1050 | ${indent}another fresh note | |
1051 | ${indent} | |
1052 | ${indent}append 1 | |
1053 | ${indent} | |
1054 | ${indent}append 2 | |
1055 | EOF | |
6956f858 TR |
1056 | git notes add -f -m"append 1" HEAD^ && |
1057 | git notes add -f -m"append 2" HEAD^^ && | |
908a3203 JH |
1058 | test_config notes.rewriteMode concatenate && |
1059 | test_config notes.rewriteRef "refs/notes/*" && | |
3ea67379 | 1060 | (echo $(git rev-parse HEAD^) $(git rev-parse HEAD) && |
6956f858 TR |
1061 | echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) | |
1062 | git notes copy --for-rewrite=foo && | |
908a3203 JH |
1063 | git log -1 >actual && |
1064 | test_cmp expect actual | |
6956f858 TR |
1065 | ' |
1066 | ||
1067 | test_expect_success 'git notes copy --for-rewrite (append empty)' ' | |
1068 | git notes remove HEAD^ && | |
908a3203 JH |
1069 | test_config notes.rewriteMode concatenate && |
1070 | test_config notes.rewriteRef "refs/notes/*" && | |
6956f858 TR |
1071 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
1072 | git notes copy --for-rewrite=foo && | |
908a3203 JH |
1073 | git log -1 >actual && |
1074 | test_cmp expect actual | |
6956f858 TR |
1075 | ' |
1076 | ||
6956f858 | 1077 | test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' |
908a3203 JH |
1078 | cat >expect <<-EOF && |
1079 | commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 | |
1080 | Author: A U Thor <author@example.com> | |
1081 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
1082 | ||
1083 | ${indent}15th | |
1084 | ||
1085 | Notes: | |
1086 | ${indent}replacement note 1 | |
1087 | EOF | |
1088 | test_config notes.rewriteMode concatenate && | |
1089 | test_config notes.rewriteRef "refs/notes/*" && | |
6956f858 TR |
1090 | git notes add -f -m"replacement note 1" HEAD^ && |
1091 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | | |
1092 | GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo && | |
908a3203 JH |
1093 | git log -1 >actual && |
1094 | test_cmp expect actual | |
6956f858 TR |
1095 | ' |
1096 | ||
908a3203 JH |
1097 | test_expect_success 'GIT_NOTES_REWRITE_REF works' ' |
1098 | cat >expect <<-EOF && | |
1099 | commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 | |
1100 | Author: A U Thor <author@example.com> | |
1101 | Date: Thu Apr 7 15:27:13 2005 -0700 | |
6956f858 | 1102 | |
908a3203 | 1103 | ${indent}15th |
6956f858 | 1104 | |
908a3203 JH |
1105 | Notes: |
1106 | ${indent}replacement note 2 | |
1107 | EOF | |
6956f858 | 1108 | git notes add -f -m"replacement note 2" HEAD^ && |
908a3203 JH |
1109 | test_config notes.rewriteMode overwrite && |
1110 | test_unconfig notes.rewriteRef && | |
6956f858 TR |
1111 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
1112 | GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ | |
1113 | git notes copy --for-rewrite=foo && | |
908a3203 JH |
1114 | git log -1 >actual && |
1115 | test_cmp expect actual | |
6956f858 TR |
1116 | ' |
1117 | ||
1118 | test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' | |
6956f858 | 1119 | git notes add -f -m"replacement note 3" HEAD^ && |
908a3203 JH |
1120 | test_config notes.rewriteMode overwrite && |
1121 | test_config notes.rewriteRef refs/notes/other && | |
6956f858 TR |
1122 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
1123 | GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo && | |
908a3203 JH |
1124 | git log -1 >actual && |
1125 | test_cmp expect actual | |
6956f858 | 1126 | ' |
bbb1b8a3 JK |
1127 | |
1128 | test_expect_success 'git notes copy diagnoses too many or too few parameters' ' | |
1129 | test_must_fail git notes copy && | |
1130 | test_must_fail git notes copy one two three | |
1131 | ' | |
1132 | ||
e14c92e8 JK |
1133 | test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' ' |
1134 | test_unconfig core.notesRef && | |
1135 | sane_unset GIT_NOTES_REF && | |
1136 | test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master" | |
1137 | ' | |
1138 | ||
618cd757 | 1139 | test_expect_success 'git notes get-ref (no overrides)' ' |
908a3203 | 1140 | test_unconfig core.notesRef && |
ed40ec55 | 1141 | sane_unset GIT_NOTES_REF && |
618cd757 JH |
1142 | test "$(git notes get-ref)" = "refs/notes/commits" |
1143 | ' | |
1144 | ||
1145 | test_expect_success 'git notes get-ref (core.notesRef)' ' | |
908a3203 | 1146 | test_config core.notesRef refs/notes/foo && |
618cd757 JH |
1147 | test "$(git notes get-ref)" = "refs/notes/foo" |
1148 | ' | |
1149 | ||
1150 | test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' | |
1151 | test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar" | |
1152 | ' | |
1153 | ||
1154 | test_expect_success 'git notes get-ref (--ref)' ' | |
1155 | test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz" | |
1156 | ' | |
1157 | ||
d0923b6d JH |
1158 | test_expect_success 'setup testing of empty notes' ' |
1159 | test_unconfig core.notesRef && | |
1160 | test_commit 16th && | |
d73a5b93 JH |
1161 | empty_blob=$(git hash-object -w /dev/null) && |
1162 | echo "$empty_blob" >expect_empty | |
d0923b6d JH |
1163 | ' |
1164 | ||
1165 | while read cmd | |
1166 | do | |
1167 | test_expect_success "'git notes $cmd' removes empty note" " | |
1168 | test_might_fail git notes remove HEAD && | |
1169 | MSG= git notes $cmd && | |
1170 | test_must_fail git notes list HEAD | |
1171 | " | |
d73a5b93 JH |
1172 | |
1173 | test_expect_success "'git notes $cmd --allow-empty' stores empty note" " | |
1174 | test_might_fail git notes remove HEAD && | |
1175 | MSG= git notes $cmd --allow-empty && | |
1176 | git notes list HEAD >actual && | |
1177 | test_cmp expect_empty actual | |
1178 | " | |
d0923b6d JH |
1179 | done <<\EOF |
1180 | add | |
1181 | add -F /dev/null | |
1182 | add -m "" | |
1183 | add -c "$empty_blob" | |
1184 | add -C "$empty_blob" | |
1185 | append | |
1186 | append -F /dev/null | |
1187 | append -m "" | |
1188 | append -c "$empty_blob" | |
1189 | append -C "$empty_blob" | |
1190 | edit | |
1191 | EOF | |
1192 | ||
8a4acd69 JH |
1193 | test_expect_success 'empty notes are displayed by git log' ' |
1194 | test_commit 17th && | |
1195 | git log -1 >expect && | |
908a3203 | 1196 | cat >>expect <<-EOF && |
8a4acd69 | 1197 | |
908a3203 JH |
1198 | Notes: |
1199 | EOF | |
8a4acd69 JH |
1200 | git notes add -C "$empty_blob" --allow-empty && |
1201 | git log -1 >actual && | |
1202 | test_cmp expect actual | |
1203 | ' | |
1204 | ||
65d9fb48 | 1205 | test_done |