]>
Commit | Line | Data |
---|---|---|
76bed78a CC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2013, 2014 Christian Couder | |
4 | # | |
5 | ||
6 | test_description='git interpret-trailers' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | # When we want one trailing space at the end of each line, let's use sed | |
11 | # to make sure that these spaces are not removed by any automatic tool. | |
12 | ||
13 | test_expect_success 'setup' ' | |
14 | : >empty && | |
15 | cat >basic_message <<-\EOF && | |
16 | subject | |
17 | ||
18 | body | |
19 | EOF | |
20 | cat >complex_message_body <<-\EOF && | |
21 | my subject | |
22 | ||
23 | my body which is long | |
24 | and contains some special | |
25 | chars like : = ? ! | |
26 | ||
27 | EOF | |
28 | sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF && | |
29 | Fixes: Z | |
30 | Acked-by: Z | |
31 | Reviewed-by: Z | |
32 | Signed-off-by: Z | |
33 | EOF | |
34 | cat >basic_patch <<-\EOF | |
35 | --- | |
36 | foo.txt | 2 +- | |
37 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
38 | ||
39 | diff --git a/foo.txt b/foo.txt | |
40 | index 0353767..1d91aa1 100644 | |
41 | --- a/foo.txt | |
42 | +++ b/foo.txt | |
43 | @@ -1,3 +1,3 @@ | |
44 | ||
45 | -bar | |
46 | +baz | |
47 | ||
48 | -- | |
49 | 1.9.rc0.11.ga562ddc | |
50 | ||
51 | EOF | |
52 | ' | |
53 | ||
c364b7ef ZH |
54 | test_expect_success 'with cmd' ' |
55 | test_when_finished "git config --remove-section trailer.bug" && | |
56 | git config trailer.bug.key "Bug-maker: " && | |
57 | git config trailer.bug.ifExists "add" && | |
58 | git config trailer.bug.cmd "echo \"maybe is\"" && | |
59 | cat >expected2 <<-EOF && | |
60 | ||
61 | Bug-maker: maybe is him | |
62 | Bug-maker: maybe is me | |
63 | EOF | |
64 | git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ | |
65 | >actual2 && | |
66 | test_cmp expected2 actual2 | |
67 | ' | |
68 | ||
69 | test_expect_success 'with cmd and $1' ' | |
70 | test_when_finished "git config --remove-section trailer.bug" && | |
71 | git config trailer.bug.key "Bug-maker: " && | |
72 | git config trailer.bug.ifExists "add" && | |
73 | git config trailer.bug.cmd "echo \"\$1\" is" && | |
74 | cat >expected2 <<-EOF && | |
75 | ||
76 | Bug-maker: him is him | |
77 | Bug-maker: me is me | |
78 | EOF | |
79 | git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ | |
80 | >actual2 && | |
81 | test_cmp expected2 actual2 | |
82 | ' | |
83 | ||
84 | test_expect_success 'with cmd and $1 with sh -c' ' | |
85 | test_when_finished "git config --remove-section trailer.bug" && | |
86 | git config trailer.bug.key "Bug-maker: " && | |
87 | git config trailer.bug.ifExists "replace" && | |
88 | git config trailer.bug.cmd "sh -c \"echo who is \"\$1\"\"" && | |
89 | cat >expected2 <<-EOF && | |
90 | ||
91 | Bug-maker: who is me | |
92 | EOF | |
93 | git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ | |
94 | >actual2 && | |
95 | test_cmp expected2 actual2 | |
96 | ' | |
97 | ||
98 | test_expect_success 'with cmd and $1 with shell script' ' | |
99 | test_when_finished "git config --remove-section trailer.bug" && | |
100 | git config trailer.bug.key "Bug-maker: " && | |
101 | git config trailer.bug.ifExists "replace" && | |
102 | git config trailer.bug.cmd "./echoscript" && | |
103 | cat >expected2 <<-EOF && | |
104 | ||
105 | Bug-maker: who is me | |
106 | EOF | |
107 | cat >echoscript <<-EOF && | |
108 | #!/bin/sh | |
109 | echo who is "\$1" | |
110 | EOF | |
111 | chmod +x echoscript && | |
112 | git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ | |
113 | >actual2 && | |
114 | test_cmp expected2 actual2 | |
115 | ' | |
116 | ||
76bed78a CC |
117 | test_expect_success 'without config' ' |
118 | sed -e "s/ Z\$/ /" >expected <<-\EOF && | |
119 | ||
120 | ack: Peff | |
121 | Reviewed-by: Z | |
122 | Acked-by: Johan | |
123 | EOF | |
124 | git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \ | |
125 | --trailer "Acked-by: Johan" empty >actual && | |
126 | test_cmp expected actual | |
127 | ' | |
128 | ||
129 | test_expect_success 'without config in another order' ' | |
130 | sed -e "s/ Z\$/ /" >expected <<-\EOF && | |
131 | ||
132 | Acked-by: Johan | |
133 | Reviewed-by: Z | |
134 | ack: Peff | |
135 | EOF | |
136 | git interpret-trailers --trailer "Acked-by: Johan" --trailer "Reviewed-by" \ | |
137 | --trailer "ack = Peff" empty >actual && | |
138 | test_cmp expected actual | |
139 | ' | |
140 | ||
141 | test_expect_success '--trim-empty without config' ' | |
142 | cat >expected <<-\EOF && | |
143 | ||
144 | ack: Peff | |
145 | Acked-by: Johan | |
146 | EOF | |
147 | git interpret-trailers --trim-empty --trailer ack=Peff \ | |
148 | --trailer "Reviewed-by" --trailer "Acked-by: Johan" \ | |
149 | --trailer "sob:" empty >actual && | |
150 | test_cmp expected actual | |
151 | ' | |
152 | ||
153 | test_expect_success 'with config option on the command line' ' | |
154 | cat >expected <<-\EOF && | |
155 | ||
156 | Acked-by: Johan | |
157 | Reviewed-by: Peff | |
158 | EOF | |
dc5d553b | 159 | { echo; echo "Acked-by: Johan"; } | |
76bed78a CC |
160 | git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \ |
161 | --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual && | |
162 | test_cmp expected actual | |
163 | ' | |
164 | ||
6262fe9c | 165 | test_expect_success 'with only a title in the message' ' |
dc5d553b CC |
166 | cat >expected <<-\EOF && |
167 | area: change | |
168 | ||
169 | Reviewed-by: Peff | |
170 | Acked-by: Johan | |
171 | EOF | |
172 | echo "area: change" | | |
173 | git interpret-trailers --trailer "Reviewed-by: Peff" \ | |
174 | --trailer "Acked-by: Johan" >actual && | |
175 | test_cmp expected actual | |
176 | ' | |
177 | ||
5c99995d CC |
178 | test_expect_success 'with multiline title in the message' ' |
179 | cat >expected <<-\EOF && | |
180 | place of | |
181 | code: change | |
182 | ||
183 | Reviewed-by: Peff | |
184 | Acked-by: Johan | |
185 | EOF | |
186 | printf "%s\n" "place of" "code: change" | | |
187 | git interpret-trailers --trailer "Reviewed-by: Peff" \ | |
188 | --trailer "Acked-by: Johan" >actual && | |
189 | test_cmp expected actual | |
190 | ' | |
191 | ||
14624506 JT |
192 | test_expect_success 'with non-trailer lines mixed with Signed-off-by' ' |
193 | cat >patch <<-\EOF && | |
194 | ||
195 | this is not a trailer | |
196 | this is not a trailer | |
197 | Signed-off-by: a <a@example.com> | |
198 | this is not a trailer | |
199 | EOF | |
200 | cat >expected <<-\EOF && | |
201 | ||
202 | this is not a trailer | |
203 | this is not a trailer | |
204 | Signed-off-by: a <a@example.com> | |
205 | this is not a trailer | |
206 | token: value | |
207 | EOF | |
208 | git interpret-trailers --trailer "token: value" patch >actual && | |
209 | test_cmp expected actual | |
210 | ' | |
211 | ||
212 | test_expect_success 'with non-trailer lines mixed with cherry picked from' ' | |
213 | cat >patch <<-\EOF && | |
214 | ||
215 | this is not a trailer | |
216 | this is not a trailer | |
217 | (cherry picked from commit x) | |
218 | this is not a trailer | |
219 | EOF | |
220 | cat >expected <<-\EOF && | |
221 | ||
222 | this is not a trailer | |
223 | this is not a trailer | |
224 | (cherry picked from commit x) | |
225 | this is not a trailer | |
226 | token: value | |
227 | EOF | |
228 | git interpret-trailers --trailer "token: value" patch >actual && | |
229 | test_cmp expected actual | |
230 | ' | |
231 | ||
232 | test_expect_success 'with non-trailer lines mixed with a configured trailer' ' | |
233 | cat >patch <<-\EOF && | |
234 | ||
235 | this is not a trailer | |
236 | this is not a trailer | |
237 | My-trailer: x | |
238 | this is not a trailer | |
239 | EOF | |
240 | cat >expected <<-\EOF && | |
241 | ||
242 | this is not a trailer | |
243 | this is not a trailer | |
244 | My-trailer: x | |
245 | this is not a trailer | |
246 | token: value | |
247 | EOF | |
248 | test_config trailer.my.key "My-trailer: " && | |
249 | git interpret-trailers --trailer "token: value" patch >actual && | |
250 | test_cmp expected actual | |
251 | ' | |
252 | ||
253 | test_expect_success 'with non-trailer lines mixed with a non-configured trailer' ' | |
254 | cat >patch <<-\EOF && | |
255 | ||
256 | this is not a trailer | |
257 | this is not a trailer | |
258 | I-am-not-configured: x | |
259 | this is not a trailer | |
260 | EOF | |
261 | cat >expected <<-\EOF && | |
262 | ||
263 | this is not a trailer | |
264 | this is not a trailer | |
265 | I-am-not-configured: x | |
266 | this is not a trailer | |
267 | ||
268 | token: value | |
269 | EOF | |
270 | test_config trailer.my.key "My-trailer: " && | |
271 | git interpret-trailers --trailer "token: value" patch >actual && | |
272 | test_cmp expected actual | |
273 | ' | |
274 | ||
275 | test_expect_success 'with all non-configured trailers' ' | |
276 | cat >patch <<-\EOF && | |
277 | ||
278 | I-am-not-configured: x | |
279 | I-am-also-not-configured: x | |
280 | EOF | |
281 | cat >expected <<-\EOF && | |
282 | ||
283 | I-am-not-configured: x | |
284 | I-am-also-not-configured: x | |
285 | token: value | |
286 | EOF | |
287 | test_config trailer.my.key "My-trailer: " && | |
288 | git interpret-trailers --trailer "token: value" patch >actual && | |
289 | test_cmp expected actual | |
290 | ' | |
291 | ||
292 | test_expect_success 'with non-trailer lines only' ' | |
293 | cat >patch <<-\EOF && | |
294 | ||
295 | this is not a trailer | |
296 | EOF | |
297 | cat >expected <<-\EOF && | |
298 | ||
299 | this is not a trailer | |
300 | ||
301 | token: value | |
302 | EOF | |
303 | git interpret-trailers --trailer "token: value" patch >actual && | |
304 | test_cmp expected actual | |
305 | ' | |
306 | ||
c463a6b2 JT |
307 | test_expect_success 'line with leading whitespace is not trailer' ' |
308 | q_to_tab >patch <<-\EOF && | |
309 | ||
310 | Qtoken: value | |
311 | EOF | |
312 | q_to_tab >expected <<-\EOF && | |
313 | ||
314 | Qtoken: value | |
315 | ||
316 | token: value | |
317 | EOF | |
318 | git interpret-trailers --trailer "token: value" patch >actual && | |
319 | test_cmp expected actual | |
320 | ' | |
321 | ||
60ef86a1 JT |
322 | test_expect_success 'multiline field treated as one trailer for 25% check' ' |
323 | q_to_tab >patch <<-\EOF && | |
324 | ||
325 | Signed-off-by: a <a@example.com> | |
326 | name: value on | |
327 | Qmultiple lines | |
328 | this is not a trailer | |
329 | this is not a trailer | |
330 | this is not a trailer | |
331 | this is not a trailer | |
332 | this is not a trailer | |
333 | this is not a trailer | |
334 | EOF | |
335 | q_to_tab >expected <<-\EOF && | |
336 | ||
337 | Signed-off-by: a <a@example.com> | |
338 | name: value on | |
339 | Qmultiple lines | |
340 | this is not a trailer | |
341 | this is not a trailer | |
342 | this is not a trailer | |
343 | this is not a trailer | |
344 | this is not a trailer | |
345 | this is not a trailer | |
346 | name: value | |
347 | EOF | |
348 | git interpret-trailers --trailer "name: value" patch >actual && | |
349 | test_cmp expected actual | |
350 | ' | |
351 | ||
352 | test_expect_success 'multiline field treated as atomic for placement' ' | |
353 | q_to_tab >patch <<-\EOF && | |
354 | ||
355 | another: trailer | |
356 | name: value on | |
357 | Qmultiple lines | |
358 | another: trailer | |
359 | EOF | |
360 | q_to_tab >expected <<-\EOF && | |
361 | ||
362 | another: trailer | |
363 | name: value on | |
364 | Qmultiple lines | |
365 | name: value | |
366 | another: trailer | |
367 | EOF | |
368 | test_config trailer.name.where after && | |
369 | git interpret-trailers --trailer "name: value" patch >actual && | |
370 | test_cmp expected actual | |
371 | ' | |
372 | ||
373 | test_expect_success 'multiline field treated as atomic for replacement' ' | |
374 | q_to_tab >patch <<-\EOF && | |
375 | ||
376 | another: trailer | |
377 | name: value on | |
378 | Qmultiple lines | |
379 | another: trailer | |
380 | EOF | |
381 | q_to_tab >expected <<-\EOF && | |
382 | ||
383 | another: trailer | |
384 | another: trailer | |
385 | name: value | |
386 | EOF | |
387 | test_config trailer.name.ifexists replace && | |
388 | git interpret-trailers --trailer "name: value" patch >actual && | |
389 | test_cmp expected actual | |
390 | ' | |
391 | ||
392 | test_expect_success 'multiline field treated as atomic for difference check' ' | |
393 | q_to_tab >patch <<-\EOF && | |
394 | ||
395 | another: trailer | |
396 | name: first line | |
397 | Qsecond line | |
398 | another: trailer | |
399 | EOF | |
400 | test_config trailer.name.ifexists addIfDifferent && | |
401 | ||
402 | q_to_tab >trailer <<-\EOF && | |
403 | name: first line | |
404 | Qsecond line | |
405 | EOF | |
406 | q_to_tab >expected <<-\EOF && | |
407 | ||
408 | another: trailer | |
409 | name: first line | |
410 | Qsecond line | |
411 | another: trailer | |
412 | EOF | |
413 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
414 | test_cmp expected actual && | |
415 | ||
416 | q_to_tab >trailer <<-\EOF && | |
417 | name: first line | |
418 | QQQQQsecond line | |
419 | EOF | |
420 | q_to_tab >expected <<-\EOF && | |
421 | ||
422 | another: trailer | |
423 | name: first line | |
424 | Qsecond line | |
425 | another: trailer | |
426 | name: first line | |
427 | QQQQQsecond line | |
428 | EOF | |
429 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
430 | test_cmp expected actual && | |
431 | ||
432 | q_to_tab >trailer <<-\EOF && | |
433 | name: first line *DIFFERENT* | |
434 | Qsecond line | |
435 | EOF | |
436 | q_to_tab >expected <<-\EOF && | |
437 | ||
438 | another: trailer | |
439 | name: first line | |
440 | Qsecond line | |
441 | another: trailer | |
442 | name: first line *DIFFERENT* | |
443 | Qsecond line | |
444 | EOF | |
445 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
446 | test_cmp expected actual | |
447 | ' | |
448 | ||
449 | test_expect_success 'multiline field treated as atomic for neighbor check' ' | |
450 | q_to_tab >patch <<-\EOF && | |
451 | ||
452 | another: trailer | |
453 | name: first line | |
454 | Qsecond line | |
455 | another: trailer | |
456 | EOF | |
457 | test_config trailer.name.where after && | |
458 | test_config trailer.name.ifexists addIfDifferentNeighbor && | |
459 | ||
460 | q_to_tab >trailer <<-\EOF && | |
461 | name: first line | |
462 | Qsecond line | |
463 | EOF | |
464 | q_to_tab >expected <<-\EOF && | |
465 | ||
466 | another: trailer | |
467 | name: first line | |
468 | Qsecond line | |
469 | another: trailer | |
470 | EOF | |
471 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
472 | test_cmp expected actual && | |
473 | ||
474 | q_to_tab >trailer <<-\EOF && | |
475 | name: first line | |
476 | QQQQQsecond line | |
477 | EOF | |
478 | q_to_tab >expected <<-\EOF && | |
479 | ||
480 | another: trailer | |
481 | name: first line | |
482 | Qsecond line | |
483 | name: first line | |
484 | QQQQQsecond line | |
485 | another: trailer | |
486 | EOF | |
487 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
488 | test_cmp expected actual | |
489 | ' | |
490 | ||
76bed78a CC |
491 | test_expect_success 'with config setup' ' |
492 | git config trailer.ack.key "Acked-by: " && | |
493 | cat >expected <<-\EOF && | |
494 | ||
495 | Acked-by: Peff | |
496 | EOF | |
497 | git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual && | |
498 | test_cmp expected actual && | |
499 | git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual && | |
500 | test_cmp expected actual && | |
501 | git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual && | |
502 | test_cmp expected actual | |
503 | ' | |
504 | ||
505 | test_expect_success 'with config setup and ":=" as separators' ' | |
506 | git config trailer.separators ":=" && | |
507 | git config trailer.ack.key "Acked-by= " && | |
508 | cat >expected <<-\EOF && | |
509 | ||
510 | Acked-by= Peff | |
511 | EOF | |
512 | git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual && | |
513 | test_cmp expected actual && | |
514 | git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual && | |
515 | test_cmp expected actual && | |
516 | git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual && | |
517 | test_cmp expected actual | |
518 | ' | |
519 | ||
520 | test_expect_success 'with config setup and "%" as separators' ' | |
521 | git config trailer.separators "%" && | |
522 | cat >expected <<-\EOF && | |
523 | ||
524 | bug% 42 | |
525 | count% 10 | |
526 | bug% 422 | |
527 | EOF | |
528 | git interpret-trailers --trim-empty --trailer "bug = 42" \ | |
529 | --trailer count%10 --trailer "test: stuff" \ | |
530 | --trailer "bug % 422" empty >actual && | |
531 | test_cmp expected actual | |
532 | ' | |
533 | ||
534 | test_expect_success 'with "%" as separators and a message with trailers' ' | |
535 | cat >special_message <<-\EOF && | |
536 | Special Message | |
537 | ||
538 | bug% 42 | |
539 | count% 10 | |
540 | bug% 422 | |
541 | EOF | |
542 | cat >expected <<-\EOF && | |
543 | Special Message | |
544 | ||
545 | bug% 42 | |
546 | count% 10 | |
547 | bug% 422 | |
548 | count% 100 | |
549 | EOF | |
550 | git interpret-trailers --trailer count%100 \ | |
551 | special_message >actual && | |
552 | test_cmp expected actual | |
553 | ' | |
554 | ||
555 | test_expect_success 'with config setup and ":=#" as separators' ' | |
556 | git config trailer.separators ":=#" && | |
557 | git config trailer.bug.key "Bug #" && | |
558 | cat >expected <<-\EOF && | |
559 | ||
560 | Bug #42 | |
561 | EOF | |
562 | git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual && | |
563 | test_cmp expected actual | |
564 | ' | |
565 | ||
566 | test_expect_success 'with commit basic message' ' | |
567 | cat basic_message >expected && | |
568 | echo >>expected && | |
569 | git interpret-trailers <basic_message >actual && | |
570 | test_cmp expected actual | |
571 | ' | |
572 | ||
573 | test_expect_success 'with basic patch' ' | |
574 | cat basic_message >input && | |
575 | cat basic_patch >>input && | |
576 | cat basic_message >expected && | |
577 | echo >>expected && | |
578 | cat basic_patch >>expected && | |
579 | git interpret-trailers <input >actual && | |
580 | test_cmp expected actual | |
581 | ' | |
582 | ||
583 | test_expect_success 'with commit complex message as argument' ' | |
584 | cat complex_message_body complex_message_trailers >complex_message && | |
585 | cat complex_message_body >expected && | |
586 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
587 | Fixes: Z | |
588 | Acked-by= Z | |
589 | Reviewed-by: Z | |
590 | Signed-off-by: Z | |
591 | EOF | |
592 | git interpret-trailers complex_message >actual && | |
593 | test_cmp expected actual | |
594 | ' | |
595 | ||
596 | test_expect_success 'with 2 files arguments' ' | |
597 | cat basic_message >>expected && | |
598 | echo >>expected && | |
599 | cat basic_patch >>expected && | |
600 | git interpret-trailers complex_message input >actual && | |
601 | test_cmp expected actual | |
602 | ' | |
603 | ||
29c83fc2 JK |
604 | # Cover multiple comment characters with the same test input. |
605 | for char in "#" ";" | |
606 | do | |
607 | case "$char" in | |
608 | "#") | |
609 | # This is the default, so let's explicitly _not_ | |
610 | # set any config to make sure it behaves as we expect. | |
611 | ;; | |
612 | *) | |
613 | config="-c core.commentChar=$char" | |
614 | ;; | |
615 | esac | |
616 | ||
617 | test_expect_success "with message that has comments ($char)" ' | |
618 | cat basic_message >message_with_comments && | |
619 | sed -e "s/ Z\$/ /" \ | |
620 | -e "s/#/$char/g" >>message_with_comments <<-EOF && | |
621 | # comment | |
622 | ||
623 | # other comment | |
624 | Cc: Z | |
625 | # yet another comment | |
626 | Reviewed-by: Johan | |
627 | Reviewed-by: Z | |
628 | # last comment | |
629 | ||
630 | EOF | |
631 | cat basic_patch >>message_with_comments && | |
632 | cat basic_message >expected && | |
633 | sed -e "s/#/$char/g" >>expected <<-\EOF && | |
634 | # comment | |
635 | ||
636 | Reviewed-by: Johan | |
637 | Cc: Peff | |
638 | # last comment | |
639 | ||
640 | EOF | |
641 | cat basic_patch >>expected && | |
642 | git $config interpret-trailers \ | |
643 | --trim-empty --trailer "Cc: Peff" \ | |
644 | message_with_comments >actual && | |
645 | test_cmp expected actual | |
646 | ' | |
647 | done | |
76bed78a | 648 | |
3d24a726 CC |
649 | test_expect_success 'with message that has an old style conflict block' ' |
650 | cat basic_message >message_with_comments && | |
651 | sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF && | |
652 | # comment | |
653 | ||
654 | # other comment | |
655 | Cc: Z | |
656 | # yet another comment | |
657 | Reviewed-by: Johan | |
658 | Reviewed-by: Z | |
659 | # last comment | |
660 | ||
661 | Conflicts: | |
662 | ||
663 | EOF | |
664 | cat basic_message >expected && | |
665 | cat >>expected <<-\EOF && | |
666 | # comment | |
667 | ||
668 | Reviewed-by: Johan | |
669 | Cc: Peff | |
670 | # last comment | |
671 | ||
672 | Conflicts: | |
673 | ||
674 | EOF | |
675 | git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual && | |
676 | test_cmp expected actual | |
677 | ' | |
678 | ||
76bed78a CC |
679 | test_expect_success 'with commit complex message and trailer args' ' |
680 | cat complex_message_body >expected && | |
681 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
682 | Fixes: Z | |
683 | Acked-by= Z | |
684 | Reviewed-by: Z | |
685 | Signed-off-by: Z | |
686 | Acked-by= Peff | |
687 | Bug #42 | |
688 | EOF | |
689 | git interpret-trailers --trailer "ack: Peff" \ | |
690 | --trailer "bug: 42" <complex_message >actual && | |
691 | test_cmp expected actual | |
692 | ' | |
693 | ||
694 | test_expect_success 'with complex patch, args and --trim-empty' ' | |
695 | cat complex_message >complex_patch && | |
696 | cat basic_patch >>complex_patch && | |
697 | cat complex_message_body >expected && | |
698 | cat >>expected <<-\EOF && | |
699 | Acked-by= Peff | |
700 | Bug #42 | |
701 | EOF | |
702 | cat basic_patch >>expected && | |
703 | git interpret-trailers --trim-empty --trailer "ack: Peff" \ | |
704 | --trailer "bug: 42" <complex_patch >actual && | |
705 | test_cmp expected actual | |
706 | ' | |
707 | ||
e1f89863 TK |
708 | test_expect_success 'in-place editing with basic patch' ' |
709 | cat basic_message >message && | |
710 | cat basic_patch >>message && | |
711 | cat basic_message >expected && | |
712 | echo >>expected && | |
713 | cat basic_patch >>expected && | |
714 | git interpret-trailers --in-place message && | |
715 | test_cmp expected message | |
716 | ' | |
717 | ||
718 | test_expect_success 'in-place editing with additional trailer' ' | |
719 | cat basic_message >message && | |
720 | cat basic_patch >>message && | |
721 | cat basic_message >expected && | |
722 | echo >>expected && | |
723 | cat >>expected <<-\EOF && | |
724 | Reviewed-by: Alice | |
725 | EOF | |
726 | cat basic_patch >>expected && | |
727 | git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message && | |
728 | test_cmp expected message | |
729 | ' | |
730 | ||
731 | test_expect_success 'in-place editing on stdin disallowed' ' | |
732 | test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message | |
733 | ' | |
734 | ||
735 | test_expect_success 'in-place editing on non-existing file' ' | |
736 | test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting && | |
737 | test_path_is_missing nonexisting | |
738 | ' | |
739 | ||
740 | test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" ' | |
741 | cat basic_message >message && | |
742 | chmod -r message && | |
743 | test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message && | |
744 | chmod +r message && | |
745 | test_cmp message basic_message | |
746 | ' | |
747 | ||
76bed78a CC |
748 | test_expect_success 'using "where = before"' ' |
749 | git config trailer.bug.where "before" && | |
750 | cat complex_message_body >expected && | |
751 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
752 | Bug #42 | |
753 | Fixes: Z | |
754 | Acked-by= Z | |
755 | Reviewed-by: Z | |
756 | Signed-off-by: Z | |
757 | Acked-by= Peff | |
758 | EOF | |
759 | git interpret-trailers --trailer "ack: Peff" \ | |
760 | --trailer "bug: 42" complex_message >actual && | |
761 | test_cmp expected actual | |
762 | ' | |
763 | ||
0ea5292e PB |
764 | test_expect_success 'overriding configuration with "--where after"' ' |
765 | git config trailer.ack.where "before" && | |
766 | cat complex_message_body >expected && | |
767 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
768 | Fixes: Z | |
769 | Acked-by= Z | |
770 | Acked-by= Peff | |
771 | Reviewed-by: Z | |
772 | Signed-off-by: Z | |
773 | EOF | |
774 | git interpret-trailers --where after --trailer "ack: Peff" \ | |
775 | complex_message >actual && | |
776 | test_cmp expected actual | |
777 | ' | |
778 | ||
779 | test_expect_success 'using "where = before" with "--no-where"' ' | |
780 | cat complex_message_body >expected && | |
781 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
782 | Bug #42 | |
783 | Fixes: Z | |
784 | Acked-by= Peff | |
785 | Acked-by= Z | |
786 | Reviewed-by: Z | |
787 | Signed-off-by: Z | |
788 | EOF | |
789 | git interpret-trailers --where after --no-where --trailer "ack: Peff" \ | |
790 | --trailer "bug: 42" complex_message >actual && | |
791 | test_cmp expected actual | |
792 | ' | |
793 | ||
76bed78a CC |
794 | test_expect_success 'using "where = after"' ' |
795 | git config trailer.ack.where "after" && | |
796 | cat complex_message_body >expected && | |
797 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
798 | Bug #42 | |
799 | Fixes: Z | |
800 | Acked-by= Z | |
801 | Acked-by= Peff | |
802 | Reviewed-by: Z | |
803 | Signed-off-by: Z | |
804 | EOF | |
805 | git interpret-trailers --trailer "ack: Peff" \ | |
806 | --trailer "bug: 42" complex_message >actual && | |
807 | test_cmp expected actual | |
808 | ' | |
809 | ||
810 | test_expect_success 'using "where = end"' ' | |
811 | git config trailer.review.key "Reviewed-by" && | |
812 | git config trailer.review.where "end" && | |
813 | cat complex_message_body >expected && | |
814 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
815 | Fixes: Z | |
816 | Acked-by= Z | |
817 | Acked-by= Peff | |
818 | Reviewed-by: Z | |
819 | Signed-off-by: Z | |
820 | Reviewed-by: Junio | |
821 | Reviewed-by: Johannes | |
822 | EOF | |
823 | git interpret-trailers --trailer "ack: Peff" \ | |
824 | --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \ | |
825 | complex_message >actual && | |
826 | test_cmp expected actual | |
827 | ' | |
828 | ||
829 | test_expect_success 'using "where = start"' ' | |
830 | git config trailer.review.key "Reviewed-by" && | |
831 | git config trailer.review.where "start" && | |
832 | cat complex_message_body >expected && | |
833 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
834 | Reviewed-by: Johannes | |
835 | Reviewed-by: Junio | |
836 | Fixes: Z | |
837 | Acked-by= Z | |
838 | Acked-by= Peff | |
839 | Reviewed-by: Z | |
840 | Signed-off-by: Z | |
841 | EOF | |
842 | git interpret-trailers --trailer "ack: Peff" \ | |
843 | --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \ | |
844 | complex_message >actual && | |
845 | test_cmp expected actual | |
846 | ' | |
847 | ||
848 | test_expect_success 'using "where = before" for a token in the middle of the message' ' | |
849 | git config trailer.review.key "Reviewed-by:" && | |
850 | git config trailer.review.where "before" && | |
851 | cat complex_message_body >expected && | |
852 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
853 | Bug #42 | |
854 | Fixes: Z | |
855 | Acked-by= Z | |
856 | Acked-by= Peff | |
857 | Reviewed-by:Johan | |
858 | Reviewed-by: | |
859 | Signed-off-by: Z | |
860 | EOF | |
861 | git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \ | |
862 | --trailer "review: Johan" <complex_message >actual && | |
863 | test_cmp expected actual | |
864 | ' | |
865 | ||
866 | test_expect_success 'using "where = before" and --trim-empty' ' | |
867 | cat complex_message_body >expected && | |
868 | cat >>expected <<-\EOF && | |
869 | Bug #46 | |
870 | Bug #42 | |
871 | Acked-by= Peff | |
872 | Reviewed-by:Johan | |
873 | EOF | |
874 | git interpret-trailers --trim-empty --trailer "ack: Peff" \ | |
875 | --trailer "bug: 42" --trailer "review: Johan" \ | |
876 | --trailer "Bug: 46" <complex_message >actual && | |
877 | test_cmp expected actual | |
878 | ' | |
879 | ||
880 | test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' ' | |
881 | cat complex_message_body >expected && | |
882 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
883 | Bug #42 | |
884 | Fixes: Z | |
885 | Acked-by= Z | |
886 | Acked-by= Peff | |
887 | Acked-by= Junio | |
888 | Acked-by= Peff | |
889 | Reviewed-by: | |
890 | Signed-off-by: Z | |
891 | EOF | |
892 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
893 | --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \ | |
894 | --trailer "ack: Peff" <complex_message >actual && | |
895 | test_cmp expected actual | |
896 | ' | |
897 | ||
898 | test_expect_success 'default "ifExists" is now "addIfDifferent"' ' | |
899 | git config trailer.ifexists "addIfDifferent" && | |
900 | cat complex_message_body >expected && | |
901 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
902 | Bug #42 | |
903 | Fixes: Z | |
904 | Acked-by= Z | |
905 | Acked-by= Peff | |
906 | Acked-by= Junio | |
907 | Reviewed-by: | |
908 | Signed-off-by: Z | |
909 | EOF | |
910 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
911 | --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \ | |
912 | --trailer "ack: Peff" <complex_message >actual && | |
913 | test_cmp expected actual | |
914 | ' | |
915 | ||
916 | test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' ' | |
917 | git config trailer.ack.ifExists "addIfDifferent" && | |
918 | git config trailer.ack.where "end" && | |
919 | cat complex_message_body >expected && | |
920 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
921 | Bug #42 | |
922 | Fixes: Z | |
923 | Acked-by= Z | |
924 | Reviewed-by: | |
925 | Signed-off-by: Z | |
926 | Acked-by= Peff | |
927 | EOF | |
928 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
929 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
930 | <complex_message >actual && | |
931 | test_cmp expected actual | |
932 | ' | |
933 | ||
934 | test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' ' | |
935 | git config trailer.ack.ifExists "addIfDifferent" && | |
936 | git config trailer.ack.where "before" && | |
937 | cat complex_message_body >expected && | |
938 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
939 | Bug #42 | |
940 | Fixes: Z | |
941 | Acked-by= Peff | |
942 | Acked-by= Z | |
943 | Reviewed-by: | |
944 | Signed-off-by: Z | |
945 | EOF | |
946 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
947 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
948 | <complex_message >actual && | |
949 | test_cmp expected actual | |
950 | ' | |
951 | ||
952 | test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' ' | |
953 | git config trailer.ack.ifExists "addIfDifferentNeighbor" && | |
954 | git config trailer.ack.where "end" && | |
955 | cat complex_message_body >expected && | |
956 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
957 | Bug #42 | |
958 | Fixes: Z | |
959 | Acked-by= Z | |
960 | Reviewed-by: | |
961 | Signed-off-by: Z | |
962 | Acked-by= Peff | |
963 | Acked-by= Junio | |
964 | Tested-by: Jakub | |
965 | Acked-by= Junio | |
966 | Acked-by= Peff | |
967 | EOF | |
968 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
969 | --trailer "ack: Junio" --trailer "bug: 42" \ | |
970 | --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ | |
971 | --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual && | |
972 | test_cmp expected actual | |
973 | ' | |
974 | ||
975 | test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' ' | |
976 | git config trailer.ack.ifExists "addIfDifferentNeighbor" && | |
977 | git config trailer.ack.where "after" && | |
978 | cat complex_message_body >expected && | |
979 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
980 | Bug #42 | |
981 | Fixes: Z | |
982 | Acked-by= Z | |
983 | Acked-by= Peff | |
984 | Acked-by= Junio | |
985 | Acked-by= Peff | |
986 | Reviewed-by: | |
987 | Signed-off-by: Z | |
988 | Tested-by: Jakub | |
989 | EOF | |
990 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
991 | --trailer "ack: Junio" --trailer "bug: 42" \ | |
992 | --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ | |
993 | --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual && | |
994 | test_cmp expected actual | |
995 | ' | |
996 | ||
997 | test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' ' | |
998 | git config trailer.ack.ifExists "addIfDifferentNeighbor" && | |
999 | cat complex_message_body >expected && | |
1000 | cat >>expected <<-\EOF && | |
1001 | Bug #42 | |
1002 | Acked-by= Peff | |
1003 | Acked-by= Junio | |
1004 | Acked-by= Peff | |
1005 | EOF | |
1006 | git interpret-trailers --trim-empty --trailer "ack: Peff" \ | |
1007 | --trailer "Acked-by= Peff" --trailer "review:" \ | |
1008 | --trailer "ack: Junio" --trailer "bug: 42" \ | |
1009 | --trailer "ack: Peff" <complex_message >actual && | |
1010 | test_cmp expected actual | |
1011 | ' | |
1012 | ||
1013 | test_expect_success 'using "ifExists = add" with "where = end"' ' | |
1014 | git config trailer.ack.ifExists "add" && | |
1015 | git config trailer.ack.where "end" && | |
1016 | cat complex_message_body >expected && | |
1017 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1018 | Bug #42 | |
1019 | Fixes: Z | |
1020 | Acked-by= Z | |
1021 | Reviewed-by: | |
1022 | Signed-off-by: Z | |
1023 | Acked-by= Peff | |
1024 | Acked-by= Peff | |
1025 | Tested-by: Jakub | |
1026 | Acked-by= Junio | |
1027 | Tested-by: Johannes | |
1028 | Acked-by= Peff | |
1029 | EOF | |
1030 | git interpret-trailers --trailer "ack: Peff" \ | |
1031 | --trailer "Acked-by= Peff" --trailer "review:" \ | |
1032 | --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ | |
1033 | --trailer "bug: 42" --trailer "Tested-by: Johannes" \ | |
1034 | --trailer "ack: Peff" <complex_message >actual && | |
1035 | test_cmp expected actual | |
1036 | ' | |
1037 | ||
1038 | test_expect_success 'using "ifExists = add" with "where = after"' ' | |
1039 | git config trailer.ack.ifExists "add" && | |
1040 | git config trailer.ack.where "after" && | |
1041 | cat complex_message_body >expected && | |
1042 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1043 | Bug #42 | |
1044 | Fixes: Z | |
1045 | Acked-by= Z | |
1046 | Acked-by= Peff | |
1047 | Acked-by= Peff | |
1048 | Acked-by= Junio | |
1049 | Acked-by= Peff | |
1050 | Reviewed-by: | |
1051 | Signed-off-by: Z | |
1052 | EOF | |
1053 | git interpret-trailers --trailer "ack: Peff" \ | |
1054 | --trailer "Acked-by= Peff" --trailer "review:" \ | |
1055 | --trailer "ack: Junio" --trailer "bug: 42" \ | |
1056 | --trailer "ack: Peff" <complex_message >actual && | |
1057 | test_cmp expected actual | |
1058 | ' | |
1059 | ||
0ea5292e PB |
1060 | test_expect_success 'overriding configuration with "--if-exists replace"' ' |
1061 | git config trailer.fix.key "Fixes: " && | |
1062 | git config trailer.fix.ifExists "add" && | |
1063 | cat complex_message_body >expected && | |
1064 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1065 | Bug #42 | |
1066 | Acked-by= Z | |
1067 | Reviewed-by: | |
1068 | Signed-off-by: Z | |
1069 | Fixes: 22 | |
1070 | EOF | |
1071 | git interpret-trailers --if-exists replace --trailer "review:" \ | |
1072 | --trailer "fix=53" --trailer "fix=22" --trailer "bug: 42" \ | |
1073 | <complex_message >actual && | |
1074 | test_cmp expected actual | |
1075 | ' | |
1076 | ||
76bed78a CC |
1077 | test_expect_success 'using "ifExists = replace"' ' |
1078 | git config trailer.fix.key "Fixes: " && | |
1079 | git config trailer.fix.ifExists "replace" && | |
1080 | cat complex_message_body >expected && | |
1081 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1082 | Bug #42 | |
1083 | Acked-by= Z | |
1084 | Acked-by= Junio | |
1085 | Acked-by= Peff | |
1086 | Reviewed-by: | |
1087 | Signed-off-by: Z | |
1088 | Fixes: 22 | |
1089 | EOF | |
1090 | git interpret-trailers --trailer "review:" \ | |
1091 | --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \ | |
1092 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
1093 | <complex_message >actual && | |
1094 | test_cmp expected actual | |
1095 | ' | |
1096 | ||
1097 | test_expect_success 'using "ifExists = replace" with "where = after"' ' | |
1098 | git config trailer.fix.where "after" && | |
1099 | cat complex_message_body >expected && | |
1100 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1101 | Bug #42 | |
1102 | Fixes: 22 | |
1103 | Acked-by= Z | |
1104 | Acked-by= Junio | |
1105 | Acked-by= Peff | |
1106 | Reviewed-by: | |
1107 | Signed-off-by: Z | |
1108 | EOF | |
1109 | git interpret-trailers --trailer "review:" \ | |
1110 | --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \ | |
1111 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
1112 | <complex_message >actual && | |
1113 | test_cmp expected actual | |
1114 | ' | |
1115 | ||
1116 | test_expect_success 'using "ifExists = doNothing"' ' | |
1117 | git config trailer.fix.ifExists "doNothing" && | |
1118 | cat complex_message_body >expected && | |
1119 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1120 | Bug #42 | |
1121 | Fixes: Z | |
1122 | Acked-by= Z | |
1123 | Acked-by= Junio | |
1124 | Acked-by= Peff | |
1125 | Reviewed-by: | |
1126 | Signed-off-by: Z | |
1127 | EOF | |
1128 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1129 | --trailer "ack: Junio" --trailer "fix=22" \ | |
1130 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
1131 | <complex_message >actual && | |
1132 | test_cmp expected actual | |
1133 | ' | |
1134 | ||
1135 | test_expect_success 'the default is "ifMissing = add"' ' | |
1136 | git config trailer.cc.key "Cc: " && | |
1137 | git config trailer.cc.where "before" && | |
1138 | cat complex_message_body >expected && | |
1139 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1140 | Bug #42 | |
1141 | Cc: Linus | |
1142 | Fixes: Z | |
1143 | Acked-by= Z | |
1144 | Acked-by= Junio | |
1145 | Acked-by= Peff | |
1146 | Reviewed-by: | |
1147 | Signed-off-by: Z | |
1148 | EOF | |
1149 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1150 | --trailer "cc=Linus" --trailer "ack: Junio" \ | |
1151 | --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1152 | <complex_message >actual && | |
1153 | test_cmp expected actual | |
1154 | ' | |
1155 | ||
0ea5292e PB |
1156 | test_expect_success 'overriding configuration with "--if-missing doNothing"' ' |
1157 | git config trailer.ifmissing "add" && | |
1158 | cat complex_message_body >expected && | |
1159 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1160 | Fixes: Z | |
1161 | Acked-by= Z | |
1162 | Acked-by= Junio | |
1163 | Acked-by= Peff | |
1164 | Reviewed-by: | |
1165 | Signed-off-by: Z | |
1166 | EOF | |
1167 | git interpret-trailers --if-missing doNothing \ | |
1168 | --trailer "review:" --trailer "fix=53" \ | |
1169 | --trailer "cc=Linus" --trailer "ack: Junio" \ | |
1170 | --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1171 | <complex_message >actual && | |
1172 | test_cmp expected actual | |
1173 | ' | |
1174 | ||
76bed78a CC |
1175 | test_expect_success 'when default "ifMissing" is "doNothing"' ' |
1176 | git config trailer.ifmissing "doNothing" && | |
1177 | cat complex_message_body >expected && | |
1178 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1179 | Fixes: Z | |
1180 | Acked-by= Z | |
1181 | Acked-by= Junio | |
1182 | Acked-by= Peff | |
1183 | Reviewed-by: | |
1184 | Signed-off-by: Z | |
1185 | EOF | |
1186 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1187 | --trailer "cc=Linus" --trailer "ack: Junio" \ | |
1188 | --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1189 | <complex_message >actual && | |
1190 | test_cmp expected actual && | |
1191 | git config trailer.ifmissing "add" | |
1192 | ' | |
1193 | ||
1194 | test_expect_success 'using "ifMissing = add" with "where = end"' ' | |
1195 | git config trailer.cc.key "Cc: " && | |
1196 | git config trailer.cc.where "end" && | |
1197 | git config trailer.cc.ifMissing "add" && | |
1198 | cat complex_message_body >expected && | |
1199 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1200 | Bug #42 | |
1201 | Fixes: Z | |
1202 | Acked-by= Z | |
1203 | Acked-by= Junio | |
1204 | Acked-by= Peff | |
1205 | Reviewed-by: | |
1206 | Signed-off-by: Z | |
1207 | Cc: Linus | |
1208 | EOF | |
1209 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1210 | --trailer "ack: Junio" --trailer "fix=22" \ | |
1211 | --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \ | |
1212 | <complex_message >actual && | |
1213 | test_cmp expected actual | |
1214 | ' | |
1215 | ||
1216 | test_expect_success 'using "ifMissing = add" with "where = before"' ' | |
1217 | git config trailer.cc.key "Cc: " && | |
1218 | git config trailer.cc.where "before" && | |
1219 | git config trailer.cc.ifMissing "add" && | |
1220 | cat complex_message_body >expected && | |
1221 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1222 | Cc: Linus | |
1223 | Bug #42 | |
1224 | Fixes: Z | |
1225 | Acked-by= Z | |
1226 | Acked-by= Junio | |
1227 | Acked-by= Peff | |
1228 | Reviewed-by: | |
1229 | Signed-off-by: Z | |
1230 | EOF | |
1231 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1232 | --trailer "ack: Junio" --trailer "fix=22" \ | |
1233 | --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \ | |
1234 | <complex_message >actual && | |
1235 | test_cmp expected actual | |
1236 | ' | |
1237 | ||
1238 | test_expect_success 'using "ifMissing = doNothing"' ' | |
1239 | git config trailer.cc.ifMissing "doNothing" && | |
1240 | cat complex_message_body >expected && | |
1241 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1242 | Bug #42 | |
1243 | Fixes: Z | |
1244 | Acked-by= Z | |
1245 | Acked-by= Junio | |
1246 | Acked-by= Peff | |
1247 | Reviewed-by: | |
1248 | Signed-off-by: Z | |
1249 | EOF | |
1250 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1251 | --trailer "cc=Linus" --trailer "ack: Junio" \ | |
1252 | --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1253 | <complex_message >actual && | |
1254 | test_cmp expected actual | |
1255 | ' | |
1256 | ||
1257 | test_expect_success 'default "where" is now "after"' ' | |
1258 | git config trailer.where "after" && | |
1259 | git config --unset trailer.ack.where && | |
1260 | cat complex_message_body >expected && | |
1261 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1262 | Bug #42 | |
1263 | Fixes: Z | |
1264 | Acked-by= Z | |
1265 | Acked-by= Peff | |
1266 | Acked-by= Peff | |
1267 | Acked-by= Junio | |
1268 | Acked-by= Peff | |
1269 | Reviewed-by: | |
1270 | Signed-off-by: Z | |
1271 | Tested-by: Jakub | |
1272 | Tested-by: Johannes | |
1273 | EOF | |
1274 | git interpret-trailers --trailer "ack: Peff" \ | |
1275 | --trailer "Acked-by= Peff" --trailer "review:" \ | |
1276 | --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ | |
1277 | --trailer "bug: 42" --trailer "Tested-by: Johannes" \ | |
1278 | --trailer "ack: Peff" <complex_message >actual && | |
1279 | test_cmp expected actual | |
1280 | ' | |
1281 | ||
b9384ff3 CC |
1282 | test_expect_success 'with simple command' ' |
1283 | git config trailer.sign.key "Signed-off-by: " && | |
1284 | git config trailer.sign.where "after" && | |
1285 | git config trailer.sign.ifExists "addIfDifferentNeighbor" && | |
1286 | git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" && | |
1287 | cat complex_message_body >expected && | |
1288 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1289 | Fixes: Z | |
1290 | Acked-by= Z | |
1291 | Reviewed-by: | |
1292 | Signed-off-by: Z | |
1293 | Signed-off-by: A U Thor <author@example.com> | |
1294 | EOF | |
1295 | git interpret-trailers --trailer "review:" --trailer "fix=22" \ | |
1296 | <complex_message >actual && | |
1297 | test_cmp expected actual | |
1298 | ' | |
1299 | ||
4dc8b1c1 | 1300 | test_expect_success 'with command using committer information' ' |
b9384ff3 CC |
1301 | git config trailer.sign.ifExists "addIfDifferent" && |
1302 | git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" && | |
1303 | cat complex_message_body >expected && | |
1304 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1305 | Fixes: Z | |
1306 | Acked-by= Z | |
1307 | Reviewed-by: | |
1308 | Signed-off-by: Z | |
1309 | Signed-off-by: C O Mitter <committer@example.com> | |
1310 | EOF | |
1311 | git interpret-trailers --trailer "review:" --trailer "fix=22" \ | |
1312 | <complex_message >actual && | |
1313 | test_cmp expected actual | |
1314 | ' | |
1315 | ||
1316 | test_expect_success 'with command using author information' ' | |
1317 | git config trailer.sign.key "Signed-off-by: " && | |
1318 | git config trailer.sign.where "after" && | |
1319 | git config trailer.sign.ifExists "addIfDifferentNeighbor" && | |
1320 | git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && | |
1321 | cat complex_message_body >expected && | |
1322 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1323 | Fixes: Z | |
1324 | Acked-by= Z | |
1325 | Reviewed-by: | |
1326 | Signed-off-by: Z | |
1327 | Signed-off-by: A U Thor <author@example.com> | |
1328 | EOF | |
1329 | git interpret-trailers --trailer "review:" --trailer "fix=22" \ | |
1330 | <complex_message >actual && | |
1331 | test_cmp expected actual | |
1332 | ' | |
1333 | ||
1334 | test_expect_success 'setup a commit' ' | |
1335 | echo "Content of the first commit." > a.txt && | |
1336 | git add a.txt && | |
1337 | git commit -m "Add file a.txt" | |
1338 | ' | |
1339 | ||
c364b7ef ZH |
1340 | test_expect_success 'cmd takes precedence over command' ' |
1341 | test_when_finished "git config --unset trailer.fix.cmd" && | |
1342 | git config trailer.fix.ifExists "replace" && | |
1343 | git config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \ | |
1344 | --abbrev-commit --abbrev=14 \"\$1\" || true" && | |
1345 | git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \ | |
1346 | --abbrev-commit --abbrev=14 \$ARG" && | |
1347 | FIXED=$(git log -1 --oneline --format="%h (%aN)" --abbrev-commit --abbrev=14 HEAD) && | |
1348 | cat complex_message_body >expected2 && | |
1349 | sed -e "s/ Z\$/ /" >>expected2 <<-EOF && | |
1350 | Fixes: $FIXED | |
1351 | Acked-by= Z | |
1352 | Reviewed-by: | |
1353 | Signed-off-by: Z | |
1354 | Signed-off-by: A U Thor <author@example.com> | |
1355 | EOF | |
1356 | git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ | |
1357 | <complex_message >actual2 && | |
1358 | test_cmp expected2 actual2 | |
1359 | ' | |
1360 | ||
b9384ff3 CC |
1361 | test_expect_success 'with command using $ARG' ' |
1362 | git config trailer.fix.ifExists "replace" && | |
1363 | git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" && | |
1364 | FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) && | |
1365 | cat complex_message_body >expected && | |
1366 | sed -e "s/ Z\$/ /" >>expected <<-EOF && | |
1367 | Fixes: $FIXED | |
1368 | Acked-by= Z | |
1369 | Reviewed-by: | |
1370 | Signed-off-by: Z | |
1371 | Signed-off-by: A U Thor <author@example.com> | |
1372 | EOF | |
1373 | git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ | |
1374 | <complex_message >actual && | |
1375 | test_cmp expected actual | |
1376 | ' | |
1377 | ||
1378 | test_expect_success 'with failing command using $ARG' ' | |
1379 | git config trailer.fix.ifExists "replace" && | |
1380 | git config trailer.fix.command "false \$ARG" && | |
1381 | cat complex_message_body >expected && | |
1382 | sed -e "s/ Z\$/ /" >>expected <<-EOF && | |
1383 | Fixes: Z | |
1384 | Acked-by= Z | |
1385 | Reviewed-by: | |
1386 | Signed-off-by: Z | |
1387 | Signed-off-by: A U Thor <author@example.com> | |
1388 | EOF | |
1389 | git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ | |
1390 | <complex_message >actual && | |
1391 | test_cmp expected actual | |
1392 | ' | |
1393 | ||
1394 | test_expect_success 'with empty tokens' ' | |
1395 | git config --unset trailer.fix.command && | |
1396 | cat >expected <<-EOF && | |
1397 | ||
1398 | Signed-off-by: A U Thor <author@example.com> | |
1399 | EOF | |
1400 | git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF && | |
1401 | EOF | |
1402 | test_cmp expected actual | |
1403 | ' | |
1404 | ||
1405 | test_expect_success 'with command but no key' ' | |
1406 | git config --unset trailer.sign.key && | |
1407 | cat >expected <<-EOF && | |
1408 | ||
1409 | sign: A U Thor <author@example.com> | |
1410 | EOF | |
1411 | git interpret-trailers >actual <<-EOF && | |
1412 | EOF | |
1413 | test_cmp expected actual | |
1414 | ' | |
1415 | ||
1416 | test_expect_success 'with no command and no key' ' | |
1417 | git config --unset trailer.review.key && | |
1418 | cat >expected <<-EOF && | |
1419 | ||
1420 | review: Junio | |
1421 | sign: A U Thor <author@example.com> | |
1422 | EOF | |
1423 | git interpret-trailers --trailer "review:Junio" >actual <<-EOF && | |
1424 | EOF | |
1425 | test_cmp expected actual | |
1426 | ' | |
1427 | ||
d76650b8 BM |
1428 | test_expect_success 'with cut line' ' |
1429 | cat >expected <<-\EOF && | |
1430 | my subject | |
1431 | ||
1432 | review: Brian | |
1433 | sign: A U Thor <author@example.com> | |
1434 | # ------------------------ >8 ------------------------ | |
1435 | ignore this | |
1436 | EOF | |
1437 | git interpret-trailers --trailer review:Brian >actual <<-\EOF && | |
1438 | my subject | |
1439 | # ------------------------ >8 ------------------------ | |
1440 | ignore this | |
1441 | EOF | |
1442 | test_cmp expected actual | |
1443 | ' | |
1444 | ||
56c493ed JK |
1445 | test_expect_success 'only trailers' ' |
1446 | git config trailer.sign.command "echo config-value" && | |
1447 | cat >expected <<-\EOF && | |
1448 | existing: existing-value | |
1449 | sign: config-value | |
1450 | added: added-value | |
1451 | EOF | |
1452 | git interpret-trailers \ | |
1453 | --trailer added:added-value \ | |
1454 | --only-trailers >actual <<-\EOF && | |
1455 | my subject | |
1456 | ||
1457 | my body | |
1458 | ||
1459 | existing: existing-value | |
1460 | EOF | |
1461 | test_cmp expected actual | |
1462 | ' | |
1463 | ||
1464 | test_expect_success 'only-trailers omits non-trailer in middle of block' ' | |
1465 | git config trailer.sign.command "echo config-value" && | |
1466 | cat >expected <<-\EOF && | |
1467 | Signed-off-by: nobody <nobody@nowhere> | |
1468 | Signed-off-by: somebody <somebody@somewhere> | |
1469 | sign: config-value | |
1470 | EOF | |
1471 | git interpret-trailers --only-trailers >actual <<-\EOF && | |
1472 | subject | |
1473 | ||
1474 | it is important that the trailers below are signed-off-by | |
1475 | so that they meet the "25% trailers Git knows about" heuristic | |
1476 | ||
1477 | Signed-off-by: nobody <nobody@nowhere> | |
1478 | this is not a trailer | |
1479 | Signed-off-by: somebody <somebody@somewhere> | |
1480 | EOF | |
1481 | test_cmp expected actual | |
1482 | ' | |
1483 | ||
fdbdb64f JK |
1484 | test_expect_success 'only input' ' |
1485 | git config trailer.sign.command "echo config-value" && | |
1486 | cat >expected <<-\EOF && | |
1487 | existing: existing-value | |
1488 | EOF | |
1489 | git interpret-trailers \ | |
1490 | --only-trailers --only-input >actual <<-\EOF && | |
1491 | my subject | |
1492 | ||
1493 | my body | |
1494 | ||
1495 | existing: existing-value | |
1496 | EOF | |
1497 | test_cmp expected actual | |
1498 | ' | |
1499 | ||
00002396 JK |
1500 | test_expect_success 'unfold' ' |
1501 | cat >expected <<-\EOF && | |
1502 | foo: continued across several lines | |
1503 | EOF | |
1504 | # pass through tr to make leading and trailing whitespace more obvious | |
1505 | tr _ " " <<-\EOF | | |
1506 | my subject | |
1507 | ||
1508 | my body | |
1509 | ||
1510 | foo:_ | |
1511 | __continued | |
1512 | ___across | |
1513 | ____several | |
1514 | _____lines | |
1515 | ___ | |
1516 | EOF | |
1517 | git interpret-trailers --only-trailers --only-input --unfold >actual && | |
1518 | test_cmp expected actual | |
1519 | ' | |
1520 | ||
c188668e JK |
1521 | test_expect_success 'handling of --- lines in input' ' |
1522 | echo "real-trailer: just right" >expected && | |
1523 | ||
1524 | git interpret-trailers --parse >actual <<-\EOF && | |
1525 | subject | |
1526 | ||
1527 | body | |
1528 | ||
1529 | not-a-trailer: too soon | |
1530 | ------ this is just a line in the commit message with a bunch of | |
1531 | ------ dashes; it does not have any syntactic meaning. | |
1532 | ||
1533 | real-trailer: just right | |
1534 | --- | |
1535 | below the dashed line may be a patch, etc. | |
1536 | ||
1537 | not-a-trailer: too late | |
1538 | EOF | |
1539 | ||
1540 | test_cmp expected actual | |
1541 | ' | |
1542 | ||
1688c9a4 JK |
1543 | test_expect_success 'suppress --- handling' ' |
1544 | echo "real-trailer: just right" >expected && | |
1545 | ||
1546 | git interpret-trailers --parse --no-divider >actual <<-\EOF && | |
1547 | subject | |
1548 | ||
1549 | This commit message has a "---" in it, but because we tell | |
1550 | interpret-trailers not to respect that, it has no effect. | |
1551 | ||
1552 | not-a-trailer: too soon | |
1553 | --- | |
1554 | ||
1555 | This is still the commit message body. | |
1556 | ||
1557 | real-trailer: just right | |
1558 | EOF | |
1559 | ||
1560 | test_cmp expected actual | |
1561 | ' | |
1562 | ||
76bed78a | 1563 | test_done |