]>
Commit | Line | Data |
---|---|---|
59587049 TL |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2023 Teng Long | |
4 | # | |
5 | ||
6 | test_description='Test commit notes with stripspace behavior' | |
7 | ||
bac3ccc2 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
59587049 TL |
9 | . ./test-lib.sh |
10 | ||
11 | MULTI_LF="$LF$LF$LF" | |
12 | write_script fake_editor <<\EOF | |
13 | echo "$MSG" >"$1" | |
14 | echo "$MSG" >&2 | |
15 | EOF | |
16 | GIT_EDITOR=./fake_editor | |
17 | export GIT_EDITOR | |
18 | ||
19 | test_expect_success 'setup the commit' ' | |
20 | test_commit 1st | |
21 | ' | |
22 | ||
23 | test_expect_success 'add note by editor' ' | |
24 | test_when_finished "git notes remove" && | |
25 | cat >expect <<-EOF && | |
26 | first-line | |
27 | ||
28 | second-line | |
29 | EOF | |
30 | ||
31 | MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add && | |
32 | git notes show >actual && | |
33 | test_cmp expect actual | |
34 | ' | |
35 | ||
c4e2aa7d | 36 | test_expect_success 'add note by specifying single "-m", "--stripspace" is the default behavior' ' |
59587049 TL |
37 | test_when_finished "git notes remove" && |
38 | cat >expect <<-EOF && | |
39 | first-line | |
40 | ||
41 | second-line | |
42 | EOF | |
43 | ||
44 | git notes add -m "${LF}first-line${MULTI_LF}second-line${LF}" && | |
45 | git notes show >actual && | |
c4e2aa7d TL |
46 | test_cmp expect actual && |
47 | git notes remove && | |
48 | git notes add --stripspace -m "${LF}first-line${MULTI_LF}second-line${LF}" && | |
49 | git notes show >actual && | |
59587049 TL |
50 | test_cmp expect actual |
51 | ' | |
52 | ||
c4e2aa7d TL |
53 | test_expect_success 'add note by specifying single "-m" and "--no-stripspace" ' ' |
54 | test_when_finished "git notes remove" && | |
55 | cat >expect <<-EOF && | |
56 | ${LF}first-line${MULTI_LF}second-line | |
57 | EOF | |
58 | ||
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 | |
63 | ' | |
64 | ||
65 | test_expect_success 'add note by specifying multiple "-m", "--stripspace" is the default behavior' ' | |
59587049 TL |
66 | test_when_finished "git notes remove" && |
67 | cat >expect <<-EOF && | |
68 | first-line | |
69 | ||
70 | second-line | |
71 | EOF | |
72 | ||
73 | git notes add -m "${LF}" \ | |
74 | -m "first-line" \ | |
75 | -m "${MULTI_LF}" \ | |
76 | -m "second-line" \ | |
77 | -m "${LF}" && | |
78 | git notes show >actual && | |
c4e2aa7d TL |
79 | test_cmp expect actual && |
80 | git notes remove && | |
81 | git notes add --stripspace -m "${LF}" \ | |
82 | -m "first-line" \ | |
83 | -m "${MULTI_LF}" \ | |
84 | -m "second-line" \ | |
85 | -m "${LF}" && | |
86 | git notes show >actual && | |
59587049 TL |
87 | test_cmp expect actual |
88 | ' | |
89 | ||
c4e2aa7d TL |
90 | test_expect_success 'add notes by specifying multiple "-m" and "--no-stripspace"' ' |
91 | test_when_finished "git notes remove" && | |
92 | cat >expect <<-EOF && | |
93 | ${LF} | |
94 | first-line | |
95 | ${MULTI_LF} | |
96 | second-line${LF} | |
97 | EOF | |
98 | ||
99 | git notes add --no-stripspace \ | |
100 | -m "${LF}" \ | |
101 | -m "first-line" \ | |
102 | -m "${MULTI_LF}" \ | |
103 | -m "second-line" \ | |
104 | -m "${LF}" && | |
105 | git notes show >actual && | |
106 | test_cmp expect actual | |
107 | ' | |
108 | ||
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 && | |
112 | first-line | |
113 | ||
114 | second-line | |
115 | EOF | |
116 | ||
117 | cat >note-file <<-EOF && | |
118 | ${LF} | |
119 | first-line | |
120 | ${MULTI_LF} | |
121 | second-line | |
122 | ${LF} | |
123 | EOF | |
124 | ||
125 | git notes add -F note-file && | |
126 | git notes show >actual && | |
127 | test_cmp expect actual && | |
128 | git notes remove && | |
129 | git notes add --stripspace -F note-file && | |
130 | git notes show >actual | |
131 | ' | |
132 | ||
133 | test_expect_success 'add note by specifying single "-F" and "--no-stripspace"' ' | |
134 | test_when_finished "git notes remove" && | |
135 | cat >expect <<-EOF && | |
136 | ${LF} | |
137 | first-line | |
138 | ${MULTI_LF} | |
139 | second-line | |
140 | ${LF} | |
141 | EOF | |
142 | ||
143 | cat >note-file <<-EOF && | |
144 | ${LF} | |
145 | first-line | |
146 | ${MULTI_LF} | |
147 | second-line | |
148 | ${LF} | |
149 | EOF | |
150 | ||
151 | git notes add --no-stripspace -F note-file && | |
152 | git notes show >actual && | |
153 | test_cmp expect actual | |
154 | ' | |
155 | ||
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 && | |
159 | file-1-first-line | |
160 | ||
161 | file-1-second-line | |
162 | ||
163 | file-2-first-line | |
164 | ||
165 | file-2-second-line | |
166 | EOF | |
167 | ||
168 | cat >note-file-1 <<-EOF && | |
169 | ${LF} | |
170 | file-1-first-line | |
171 | ${MULTI_LF} | |
172 | file-1-second-line | |
173 | ${LF} | |
174 | EOF | |
175 | ||
176 | cat >note-file-2 <<-EOF && | |
177 | ${LF} | |
178 | file-2-first-line | |
179 | ${MULTI_LF} | |
180 | file-2-second-line | |
181 | ${LF} | |
182 | EOF | |
183 | ||
184 | git notes add -F note-file-1 -F note-file-2 && | |
185 | git notes show >actual && | |
186 | test_cmp expect actual && | |
187 | git notes remove && | |
188 | git notes add --stripspace -F note-file-1 -F note-file-2 && | |
189 | git notes show >actual && | |
190 | test_cmp expect actual | |
191 | ' | |
192 | ||
193 | test_expect_success 'add note by specifying multiple "-F" with "--no-stripspace"' ' | |
194 | test_when_finished "git notes remove" && | |
195 | cat >expect <<-EOF && | |
196 | ${LF} | |
197 | file-1-first-line | |
198 | ${MULTI_LF} | |
199 | file-1-second-line | |
200 | ${LF} | |
201 | ||
202 | ${LF} | |
203 | file-2-first-line | |
204 | ${MULTI_LF} | |
205 | file-2-second-line | |
206 | ${LF} | |
207 | EOF | |
208 | ||
209 | cat >note-file-1 <<-EOF && | |
210 | ${LF} | |
211 | file-1-first-line | |
212 | ${MULTI_LF} | |
213 | file-1-second-line | |
214 | ${LF} | |
215 | EOF | |
216 | ||
217 | cat >note-file-2 <<-EOF && | |
218 | ${LF} | |
219 | file-2-first-line | |
220 | ${MULTI_LF} | |
221 | file-2-second-line | |
222 | ${LF} | |
223 | EOF | |
224 | ||
225 | git notes add --no-stripspace -F note-file-1 -F note-file-2 && | |
226 | git notes show >actual && | |
227 | test_cmp expect actual | |
228 | ' | |
59587049 TL |
229 | |
230 | test_expect_success 'append note by editor' ' | |
231 | test_when_finished "git notes remove" && | |
232 | cat >expect <<-EOF && | |
233 | first-line | |
234 | ||
235 | second-line | |
236 | EOF | |
237 | ||
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 | |
242 | ' | |
243 | ||
244 | test_expect_success 'append note by specifying single "-m"' ' | |
245 | test_when_finished "git notes remove" && | |
246 | cat >expect <<-EOF && | |
247 | first-line | |
248 | ||
249 | second-line | |
250 | EOF | |
251 | ||
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 | |
256 | ' | |
257 | ||
258 | test_expect_success 'append note by specifying multiple "-m"' ' | |
259 | test_when_finished "git notes remove" && | |
260 | cat >expect <<-EOF && | |
261 | first-line | |
262 | ||
263 | second-line | |
264 | EOF | |
265 | ||
266 | git notes add -m "${LF}first-line" && | |
267 | git notes append -m "${MULTI_LF}" \ | |
268 | -m "second-line" \ | |
269 | -m "${LF}" && | |
270 | git notes show >actual && | |
271 | test_cmp expect actual | |
272 | ' | |
273 | ||
274 | test_expect_success 'add note by specifying single "-F"' ' | |
275 | test_when_finished "git notes remove" && | |
276 | cat >expect <<-EOF && | |
277 | first-line | |
278 | ||
279 | second-line | |
280 | EOF | |
281 | ||
282 | cat >note-file <<-EOF && | |
283 | ${LF} | |
284 | first-line | |
285 | ${MULTI_LF} | |
286 | second-line | |
287 | ${LF} | |
288 | EOF | |
289 | ||
290 | git notes add -F note-file && | |
291 | git notes show >actual && | |
292 | test_cmp expect actual | |
293 | ' | |
294 | ||
295 | test_expect_success 'add notes by specifying multiple "-F"' ' | |
296 | test_when_finished "git notes remove" && | |
297 | cat >expect <<-EOF && | |
298 | file-1-first-line | |
299 | ||
300 | file-1-second-line | |
301 | ||
302 | file-2-first-line | |
303 | ||
304 | file-2-second-line | |
305 | EOF | |
306 | ||
307 | cat >note-file-1 <<-EOF && | |
308 | ${LF} | |
309 | file-1-first-line | |
310 | ${MULTI_LF} | |
311 | file-1-second-line | |
312 | ${LF} | |
313 | EOF | |
314 | ||
315 | cat >note-file-2 <<-EOF && | |
316 | ${LF} | |
317 | file-2-first-line | |
318 | ${MULTI_LF} | |
319 | file-2-second-line | |
320 | ${LF} | |
321 | EOF | |
322 | ||
323 | git notes add -F note-file-1 -F note-file-2 && | |
324 | git notes show >actual && | |
325 | test_cmp expect actual | |
326 | ' | |
327 | ||
328 | test_expect_success 'append note by specifying single "-F"' ' | |
329 | test_when_finished "git notes remove" && | |
330 | cat >expect <<-EOF && | |
331 | initial-line | |
332 | ||
333 | first-line | |
334 | ||
335 | second-line | |
336 | EOF | |
337 | ||
338 | cat >note-file <<-EOF && | |
339 | ${LF} | |
340 | first-line | |
341 | ${MULTI_LF} | |
342 | second-line | |
343 | ${LF} | |
344 | EOF | |
345 | ||
346 | git notes add -m "initial-line" && | |
347 | git notes append -F note-file && | |
348 | git notes show >actual && | |
349 | test_cmp expect actual | |
350 | ' | |
351 | ||
352 | test_expect_success 'append notes by specifying multiple "-F"' ' | |
353 | test_when_finished "git notes remove" && | |
354 | cat >expect <<-EOF && | |
355 | initial-line | |
356 | ||
357 | file-1-first-line | |
358 | ||
359 | file-1-second-line | |
360 | ||
361 | file-2-first-line | |
362 | ||
363 | file-2-second-line | |
364 | EOF | |
365 | ||
366 | cat >note-file-1 <<-EOF && | |
367 | ${LF} | |
368 | file-1-first-line | |
369 | ${MULTI_LF} | |
370 | file-1-second-line | |
371 | ${LF} | |
372 | EOF | |
373 | ||
374 | cat >note-file-2 <<-EOF && | |
375 | ${LF} | |
376 | file-2-first-line | |
377 | ${MULTI_LF} | |
378 | file-2-second-line | |
379 | ${LF} | |
380 | EOF | |
381 | ||
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 | |
386 | ' | |
387 | ||
c4e2aa7d TL |
388 | test_expect_success 'append note by specifying multiple "-F" with "--no-stripspace"' ' |
389 | test_when_finished "git notes remove" && | |
390 | cat >expect <<-EOF && | |
391 | initial-line | |
392 | ${LF}${LF} | |
393 | file-1-first-line | |
394 | ${MULTI_LF} | |
395 | file-1-second-line | |
396 | ${LF} | |
397 | ||
398 | ${LF} | |
399 | file-2-first-line | |
400 | ${MULTI_LF} | |
401 | file-2-second-line | |
402 | ${LF} | |
403 | EOF | |
404 | ||
405 | cat >note-file-1 <<-EOF && | |
406 | ${LF} | |
407 | file-1-first-line | |
408 | ${MULTI_LF} | |
409 | file-1-second-line | |
410 | ${LF} | |
411 | EOF | |
412 | ||
413 | cat >note-file-2 <<-EOF && | |
414 | ${LF} | |
415 | file-2-first-line | |
416 | ${MULTI_LF} | |
417 | file-2-second-line | |
418 | ${LF} | |
419 | EOF | |
420 | ||
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 | |
425 | ' | |
426 | ||
59587049 TL |
427 | test_expect_success 'add notes with empty messages' ' |
428 | rev=$(git rev-parse HEAD) && | |
429 | git notes add -m "${LF}" \ | |
430 | -m "${MULTI_LF}" \ | |
431 | -m "${LF}" >actual 2>&1 && | |
6789275d | 432 | test_grep "Removing note for object" actual |
59587049 TL |
433 | ' |
434 | ||
c4e2aa7d | 435 | test_expect_success 'add note by specifying "-C", "--no-stripspace" is the default behavior' ' |
59587049 TL |
436 | test_when_finished "git notes remove" && |
437 | cat >expect <<-EOF && | |
438 | ${LF} | |
439 | first-line | |
440 | ${MULTI_LF} | |
441 | second-line | |
442 | ${LF} | |
443 | EOF | |
444 | ||
2b5a303a | 445 | git hash-object -w --stdin <expect >blob && |
59587049 TL |
446 | git notes add -C $(cat blob) && |
447 | git notes show >actual && | |
c4e2aa7d TL |
448 | test_cmp expect actual && |
449 | git notes remove && | |
450 | git notes add --no-stripspace -C $(cat blob) && | |
451 | git notes show >actual && | |
452 | test_cmp expect actual | |
453 | ' | |
454 | ||
455 | test_expect_success 'reuse note by specifying "-C" and "--stripspace"' ' | |
456 | test_when_finished "git notes remove" && | |
457 | cat >data <<-EOF && | |
458 | ${LF} | |
459 | first-line | |
460 | ${MULTI_LF} | |
461 | second-line | |
462 | ${LF} | |
463 | EOF | |
464 | ||
465 | cat >expect <<-EOF && | |
466 | first-line | |
467 | ||
468 | second-line | |
469 | EOF | |
470 | ||
2b5a303a | 471 | git hash-object -w --stdin <data >blob && |
c4e2aa7d TL |
472 | git notes add --stripspace -C $(cat blob) && |
473 | git notes show >actual && | |
59587049 TL |
474 | test_cmp expect actual |
475 | ' | |
476 | ||
c4e2aa7d | 477 | test_expect_success 'reuse with "-C" and add note with "-m", "-m" will stripspace all together' ' |
59587049 TL |
478 | test_when_finished "git notes remove" && |
479 | cat >data <<-EOF && | |
480 | ${LF} | |
481 | first-line | |
482 | ${MULTI_LF} | |
483 | second-line | |
484 | ${LF} | |
485 | EOF | |
486 | ||
487 | cat >expect <<-EOF && | |
488 | first-line | |
489 | ||
490 | second-line | |
491 | ||
492 | third-line | |
493 | EOF | |
494 | ||
2b5a303a | 495 | git hash-object -w --stdin <data >blob && |
59587049 TL |
496 | git notes add -C $(cat blob) -m "third-line" && |
497 | git notes show >actual && | |
498 | test_cmp expect actual | |
499 | ' | |
500 | ||
c4e2aa7d | 501 | test_expect_success 'add note with "-m" and reuse note with "-C", "-C" will not stripspace all together' ' |
59587049 TL |
502 | test_when_finished "git notes remove" && |
503 | cat >data <<-EOF && | |
504 | ||
505 | second-line | |
506 | EOF | |
507 | ||
508 | cat >expect <<-EOF && | |
509 | first-line | |
510 | ${LF} | |
511 | second-line | |
512 | EOF | |
513 | ||
2b5a303a | 514 | git hash-object -w --stdin <data >blob && |
59587049 TL |
515 | git notes add -m "first-line" -C $(cat blob) && |
516 | git notes show >actual && | |
517 | test_cmp expect actual | |
518 | ' | |
519 | ||
c4e2aa7d TL |
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 && | |
523 | first-line | |
524 | ||
525 | second-line | |
526 | EOF | |
527 | ||
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 && | |
532 | git notes remove && | |
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 | |
536 | ' | |
537 | ||
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} | |
542 | EOF | |
543 | ||
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 | |
548 | ' | |
549 | ||
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 && | |
553 | first-line | |
554 | ||
555 | second-line | |
556 | EOF | |
557 | ||
558 | MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit && | |
559 | git notes show >actual && | |
560 | test_cmp expect actual && | |
561 | git notes remove && | |
562 | MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit --stripspace && | |
563 | git notes show >actual && | |
564 | test_cmp expect actual | |
565 | ' | |
566 | ||
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} | |
571 | EOF | |
572 | ||
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 | |
576 | ' | |
577 | ||
59587049 | 578 | test_done |