3 # Copyright (c) 2023 Teng Long
6 test_description
='Test commit notes with stripspace behavior'
8 TEST_PASSES_SANITIZE_LEAK
=true
12 write_script fake_editor
<<\EOF
16 GIT_EDITOR
=.
/fake_editor
19 test_expect_success
'setup the commit' '
23 test_expect_success
'add note by editor' '
24 test_when_finished "git notes remove" &&
31 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add &&
32 git notes show >actual &&
33 test_cmp expect actual
36 test_expect_success
'add note by specifying single "-m", "--stripspace" is the default behavior' '
37 test_when_finished "git notes remove" &&
44 git notes add -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
45 git notes show >actual &&
46 test_cmp expect actual &&
48 git notes add --stripspace -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
49 git notes show >actual &&
50 test_cmp expect actual
53 test_expect_success
'add note by specifying single "-m" and "--no-stripspace" ' '
54 test_when_finished "git notes remove" &&
56 ${LF}first-line${MULTI_LF}second-line
59 git notes add --no-stripspace \
60 -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
61 git notes show >actual &&
62 test_cmp expect actual
65 test_expect_success
'add note by specifying multiple "-m", "--stripspace" is the default behavior' '
66 test_when_finished "git notes remove" &&
73 git notes add -m "${LF}" \
78 git notes show >actual &&
79 test_cmp expect actual &&
81 git notes add --stripspace -m "${LF}" \
86 git notes show >actual &&
87 test_cmp expect actual
90 test_expect_success
'add notes by specifying multiple "-m" and "--no-stripspace"' '
91 test_when_finished "git notes remove" &&
99 git notes add --no-stripspace \
105 git notes show >actual &&
106 test_cmp expect actual
109 test_expect_success
'add note by specifying single "-F", "--stripspace" is the default behavior' '
110 test_when_finished "git notes remove" &&
111 cat >expect <<-EOF &&
117 cat >note-file <<-EOF &&
125 git notes add -F note-file &&
126 git notes show >actual &&
127 test_cmp expect actual &&
129 git notes add --stripspace -F note-file &&
130 git notes show >actual
133 test_expect_success
'add note by specifying single "-F" and "--no-stripspace"' '
134 test_when_finished "git notes remove" &&
135 cat >expect <<-EOF &&
143 cat >note-file <<-EOF &&
151 git notes add --no-stripspace -F note-file &&
152 git notes show >actual &&
153 test_cmp expect actual
156 test_expect_success
'add note by specifying multiple "-F", "--stripspace" is the default behavior' '
157 test_when_finished "git notes remove" &&
158 cat >expect <<-EOF &&
168 cat >note-file-1 <<-EOF &&
176 cat >note-file-2 <<-EOF &&
184 git notes add -F note-file-1 -F note-file-2 &&
185 git notes show >actual &&
186 test_cmp expect actual &&
188 git notes add --stripspace -F note-file-1 -F note-file-2 &&
189 git notes show >actual &&
190 test_cmp expect actual
193 test_expect_success
'add note by specifying multiple "-F" with "--no-stripspace"' '
194 test_when_finished "git notes remove" &&
195 cat >expect <<-EOF &&
209 cat >note-file-1 <<-EOF &&
217 cat >note-file-2 <<-EOF &&
225 git notes add --no-stripspace -F note-file-1 -F note-file-2 &&
226 git notes show >actual &&
227 test_cmp expect actual
230 test_expect_success
'append note by editor' '
231 test_when_finished "git notes remove" &&
232 cat >expect <<-EOF &&
238 git notes add -m "first-line" &&
239 MSG="${MULTI_LF}second-line${LF}" git notes append &&
240 git notes show >actual &&
241 test_cmp expect actual
244 test_expect_success
'append note by specifying single "-m"' '
245 test_when_finished "git notes remove" &&
246 cat >expect <<-EOF &&
252 git notes add -m "${LF}first-line" &&
253 git notes append -m "${MULTI_LF}second-line${LF}" &&
254 git notes show >actual &&
255 test_cmp expect actual
258 test_expect_success
'append note by specifying multiple "-m"' '
259 test_when_finished "git notes remove" &&
260 cat >expect <<-EOF &&
266 git notes add -m "${LF}first-line" &&
267 git notes append -m "${MULTI_LF}" \
270 git notes show >actual &&
271 test_cmp expect actual
274 test_expect_success
'add note by specifying single "-F"' '
275 test_when_finished "git notes remove" &&
276 cat >expect <<-EOF &&
282 cat >note-file <<-EOF &&
290 git notes add -F note-file &&
291 git notes show >actual &&
292 test_cmp expect actual
295 test_expect_success
'add notes by specifying multiple "-F"' '
296 test_when_finished "git notes remove" &&
297 cat >expect <<-EOF &&
307 cat >note-file-1 <<-EOF &&
315 cat >note-file-2 <<-EOF &&
323 git notes add -F note-file-1 -F note-file-2 &&
324 git notes show >actual &&
325 test_cmp expect actual
328 test_expect_success
'append note by specifying single "-F"' '
329 test_when_finished "git notes remove" &&
330 cat >expect <<-EOF &&
338 cat >note-file <<-EOF &&
346 git notes add -m "initial-line" &&
347 git notes append -F note-file &&
348 git notes show >actual &&
349 test_cmp expect actual
352 test_expect_success
'append notes by specifying multiple "-F"' '
353 test_when_finished "git notes remove" &&
354 cat >expect <<-EOF &&
366 cat >note-file-1 <<-EOF &&
374 cat >note-file-2 <<-EOF &&
382 git notes add -m "initial-line" &&
383 git notes append -F note-file-1 -F note-file-2 &&
384 git notes show >actual &&
385 test_cmp expect actual
388 test_expect_success
'append note by specifying multiple "-F" with "--no-stripspace"' '
389 test_when_finished "git notes remove" &&
390 cat >expect <<-EOF &&
405 cat >note-file-1 <<-EOF &&
413 cat >note-file-2 <<-EOF &&
421 git notes add -m "initial-line" &&
422 git notes append --no-stripspace -F note-file-1 -F note-file-2 &&
423 git notes show >actual &&
424 test_cmp expect actual
427 test_expect_success
'add notes with empty messages' '
428 rev=$(git rev-parse HEAD) &&
429 git notes add -m "${LF}" \
431 -m "${LF}" >actual 2>&1 &&
432 test_grep "Removing note for object" actual
435 test_expect_success
'add note by specifying "-C", "--no-stripspace" is the default behavior' '
436 test_when_finished "git notes remove" &&
437 cat >expect <<-EOF &&
445 git hash-object -w --stdin <expect >blob &&
446 git notes add -C $(cat blob) &&
447 git notes show >actual &&
448 test_cmp expect actual &&
450 git notes add --no-stripspace -C $(cat blob) &&
451 git notes show >actual &&
452 test_cmp expect actual
455 test_expect_success
'reuse note by specifying "-C" and "--stripspace"' '
456 test_when_finished "git notes remove" &&
465 cat >expect <<-EOF &&
471 git hash-object -w --stdin <data >blob &&
472 git notes add --stripspace -C $(cat blob) &&
473 git notes show >actual &&
474 test_cmp expect actual
477 test_expect_success
'reuse with "-C" and add note with "-m", "-m" will stripspace all together' '
478 test_when_finished "git notes remove" &&
487 cat >expect <<-EOF &&
495 git hash-object -w --stdin <data >blob &&
496 git notes add -C $(cat blob) -m "third-line" &&
497 git notes show >actual &&
498 test_cmp expect actual
501 test_expect_success
'add note with "-m" and reuse note with "-C", "-C" will not stripspace all together' '
502 test_when_finished "git notes remove" &&
508 cat >expect <<-EOF &&
514 git hash-object -w --stdin <data >blob &&
515 git notes add -m "first-line" -C $(cat blob) &&
516 git notes show >actual &&
517 test_cmp expect actual
520 test_expect_success
'add note by specifying "-c", "--stripspace" is the default behavior' '
521 test_when_finished "git notes remove" &&
522 cat >expect <<-EOF &&
528 echo "initial-line" | git hash-object -w --stdin >blob &&
529 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add -c $(cat blob) &&
530 git notes show >actual &&
531 test_cmp expect actual &&
533 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --stripspace -c $(cat blob) &&
534 git notes show >actual &&
535 test_cmp expect actual
538 test_expect_success
'add note by specifying "-c" with "--no-stripspace"' '
539 test_when_finished "git notes remove" &&
540 cat >expect <<-EOF &&
541 ${LF}first-line${MULTI_LF}second-line${LF}
544 echo "initial-line" | git hash-object -w --stdin >blob &&
545 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --no-stripspace -c $(cat blob) &&
546 git notes show >actual &&
547 test_cmp expect actual
550 test_expect_success
'edit note by specifying "-c", "--stripspace" is the default behavior' '
551 test_when_finished "git notes remove" &&
552 cat >expect <<-EOF &&
558 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit &&
559 git notes show >actual &&
560 test_cmp expect actual &&
562 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit --stripspace &&
563 git notes show >actual &&
564 test_cmp expect actual
567 test_expect_success
'edit note by specifying "-c" with "--no-stripspace"' '
568 test_when_finished "git notes remove" &&
569 cat >expect <<-EOF &&
570 ${LF}first-line${MULTI_LF}second-line${LF}
573 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --no-stripspace &&
574 git notes show >actual &&
575 test_cmp expect actual