fast-import: convert internal structs to struct object_id
[alt-git.git] / t / t7513-interpret-trailers.sh
blob4dd1d7c52085d25546f64692acd0b351a7dddd72
1 #!/bin/sh
3 # Copyright (c) 2013, 2014 Christian Couder
6 test_description='git interpret-trailers'
8 . ./test-lib.sh
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.
13 test_expect_success 'setup' '
14 : >empty &&
15 cat >basic_message <<-\EOF &&
16 subject
18 body
19 EOF
20 cat >complex_message_body <<-\EOF &&
21 my subject
23 my body which is long
24 and contains some special
25 chars like : = ? !
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(-)
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 @@
45 -bar
46 +baz
49 1.9.rc0.11.ga562ddc
51 EOF
54 test_expect_success 'without config' '
55 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
57 ack: Peff
58 Reviewed-by: Z
59 Acked-by: Johan
60 EOF
61 git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \
62 --trailer "Acked-by: Johan" empty >actual &&
63 test_cmp expected actual
66 test_expect_success 'without config in another order' '
67 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
69 Acked-by: Johan
70 Reviewed-by: Z
71 ack: Peff
72 EOF
73 git interpret-trailers --trailer "Acked-by: Johan" --trailer "Reviewed-by" \
74 --trailer "ack = Peff" empty >actual &&
75 test_cmp expected actual
78 test_expect_success '--trim-empty without config' '
79 cat >expected <<-\EOF &&
81 ack: Peff
82 Acked-by: Johan
83 EOF
84 git interpret-trailers --trim-empty --trailer ack=Peff \
85 --trailer "Reviewed-by" --trailer "Acked-by: Johan" \
86 --trailer "sob:" empty >actual &&
87 test_cmp expected actual
90 test_expect_success 'with config option on the command line' '
91 cat >expected <<-\EOF &&
93 Acked-by: Johan
94 Reviewed-by: Peff
95 EOF
96 { echo; echo "Acked-by: Johan"; } |
97 git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
98 --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
99 test_cmp expected actual
102 test_expect_success 'with only a title in the message' '
103 cat >expected <<-\EOF &&
104 area: change
106 Reviewed-by: Peff
107 Acked-by: Johan
109 echo "area: change" |
110 git interpret-trailers --trailer "Reviewed-by: Peff" \
111 --trailer "Acked-by: Johan" >actual &&
112 test_cmp expected actual
115 test_expect_success 'with multiline title in the message' '
116 cat >expected <<-\EOF &&
117 place of
118 code: change
120 Reviewed-by: Peff
121 Acked-by: Johan
123 printf "%s\n" "place of" "code: change" |
124 git interpret-trailers --trailer "Reviewed-by: Peff" \
125 --trailer "Acked-by: Johan" >actual &&
126 test_cmp expected actual
129 test_expect_success 'with non-trailer lines mixed with Signed-off-by' '
130 cat >patch <<-\EOF &&
132 this is not a trailer
133 this is not a trailer
134 Signed-off-by: a <a@example.com>
135 this is not a trailer
137 cat >expected <<-\EOF &&
139 this is not a trailer
140 this is not a trailer
141 Signed-off-by: a <a@example.com>
142 this is not a trailer
143 token: value
145 git interpret-trailers --trailer "token: value" patch >actual &&
146 test_cmp expected actual
149 test_expect_success 'with non-trailer lines mixed with cherry picked from' '
150 cat >patch <<-\EOF &&
152 this is not a trailer
153 this is not a trailer
154 (cherry picked from commit x)
155 this is not a trailer
157 cat >expected <<-\EOF &&
159 this is not a trailer
160 this is not a trailer
161 (cherry picked from commit x)
162 this is not a trailer
163 token: value
165 git interpret-trailers --trailer "token: value" patch >actual &&
166 test_cmp expected actual
169 test_expect_success 'with non-trailer lines mixed with a configured trailer' '
170 cat >patch <<-\EOF &&
172 this is not a trailer
173 this is not a trailer
174 My-trailer: x
175 this is not a trailer
177 cat >expected <<-\EOF &&
179 this is not a trailer
180 this is not a trailer
181 My-trailer: x
182 this is not a trailer
183 token: value
185 test_config trailer.my.key "My-trailer: " &&
186 git interpret-trailers --trailer "token: value" patch >actual &&
187 test_cmp expected actual
190 test_expect_success 'with non-trailer lines mixed with a non-configured trailer' '
191 cat >patch <<-\EOF &&
193 this is not a trailer
194 this is not a trailer
195 I-am-not-configured: x
196 this is not a trailer
198 cat >expected <<-\EOF &&
200 this is not a trailer
201 this is not a trailer
202 I-am-not-configured: x
203 this is not a trailer
205 token: value
207 test_config trailer.my.key "My-trailer: " &&
208 git interpret-trailers --trailer "token: value" patch >actual &&
209 test_cmp expected actual
212 test_expect_success 'with all non-configured trailers' '
213 cat >patch <<-\EOF &&
215 I-am-not-configured: x
216 I-am-also-not-configured: x
218 cat >expected <<-\EOF &&
220 I-am-not-configured: x
221 I-am-also-not-configured: x
222 token: value
224 test_config trailer.my.key "My-trailer: " &&
225 git interpret-trailers --trailer "token: value" patch >actual &&
226 test_cmp expected actual
229 test_expect_success 'with non-trailer lines only' '
230 cat >patch <<-\EOF &&
232 this is not a trailer
234 cat >expected <<-\EOF &&
236 this is not a trailer
238 token: value
240 git interpret-trailers --trailer "token: value" patch >actual &&
241 test_cmp expected actual
244 test_expect_success 'line with leading whitespace is not trailer' '
245 q_to_tab >patch <<-\EOF &&
247 Qtoken: value
249 q_to_tab >expected <<-\EOF &&
251 Qtoken: value
253 token: value
255 git interpret-trailers --trailer "token: value" patch >actual &&
256 test_cmp expected actual
259 test_expect_success 'multiline field treated as one trailer for 25% check' '
260 q_to_tab >patch <<-\EOF &&
262 Signed-off-by: a <a@example.com>
263 name: value on
264 Qmultiple lines
265 this is not a trailer
266 this is not a trailer
267 this is not a trailer
268 this is not a trailer
269 this is not a trailer
270 this is not a trailer
272 q_to_tab >expected <<-\EOF &&
274 Signed-off-by: a <a@example.com>
275 name: value on
276 Qmultiple lines
277 this is not a trailer
278 this is not a trailer
279 this is not a trailer
280 this is not a trailer
281 this is not a trailer
282 this is not a trailer
283 name: value
285 git interpret-trailers --trailer "name: value" patch >actual &&
286 test_cmp expected actual
289 test_expect_success 'multiline field treated as atomic for placement' '
290 q_to_tab >patch <<-\EOF &&
292 another: trailer
293 name: value on
294 Qmultiple lines
295 another: trailer
297 q_to_tab >expected <<-\EOF &&
299 another: trailer
300 name: value on
301 Qmultiple lines
302 name: value
303 another: trailer
305 test_config trailer.name.where after &&
306 git interpret-trailers --trailer "name: value" patch >actual &&
307 test_cmp expected actual
310 test_expect_success 'multiline field treated as atomic for replacement' '
311 q_to_tab >patch <<-\EOF &&
313 another: trailer
314 name: value on
315 Qmultiple lines
316 another: trailer
318 q_to_tab >expected <<-\EOF &&
320 another: trailer
321 another: trailer
322 name: value
324 test_config trailer.name.ifexists replace &&
325 git interpret-trailers --trailer "name: value" patch >actual &&
326 test_cmp expected actual
329 test_expect_success 'multiline field treated as atomic for difference check' '
330 q_to_tab >patch <<-\EOF &&
332 another: trailer
333 name: first line
334 Qsecond line
335 another: trailer
337 test_config trailer.name.ifexists addIfDifferent &&
339 q_to_tab >trailer <<-\EOF &&
340 name: first line
341 Qsecond line
343 q_to_tab >expected <<-\EOF &&
345 another: trailer
346 name: first line
347 Qsecond line
348 another: trailer
350 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
351 test_cmp expected actual &&
353 q_to_tab >trailer <<-\EOF &&
354 name: first line
355 QQQQQsecond line
357 q_to_tab >expected <<-\EOF &&
359 another: trailer
360 name: first line
361 Qsecond line
362 another: trailer
363 name: first line
364 QQQQQsecond line
366 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
367 test_cmp expected actual &&
369 q_to_tab >trailer <<-\EOF &&
370 name: first line *DIFFERENT*
371 Qsecond line
373 q_to_tab >expected <<-\EOF &&
375 another: trailer
376 name: first line
377 Qsecond line
378 another: trailer
379 name: first line *DIFFERENT*
380 Qsecond line
382 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
383 test_cmp expected actual
386 test_expect_success 'multiline field treated as atomic for neighbor check' '
387 q_to_tab >patch <<-\EOF &&
389 another: trailer
390 name: first line
391 Qsecond line
392 another: trailer
394 test_config trailer.name.where after &&
395 test_config trailer.name.ifexists addIfDifferentNeighbor &&
397 q_to_tab >trailer <<-\EOF &&
398 name: first line
399 Qsecond line
401 q_to_tab >expected <<-\EOF &&
403 another: trailer
404 name: first line
405 Qsecond line
406 another: trailer
408 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
409 test_cmp expected actual &&
411 q_to_tab >trailer <<-\EOF &&
412 name: first line
413 QQQQQsecond line
415 q_to_tab >expected <<-\EOF &&
417 another: trailer
418 name: first line
419 Qsecond line
420 name: first line
421 QQQQQsecond line
422 another: trailer
424 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
425 test_cmp expected actual
428 test_expect_success 'with config setup' '
429 git config trailer.ack.key "Acked-by: " &&
430 cat >expected <<-\EOF &&
432 Acked-by: Peff
434 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
435 test_cmp expected actual &&
436 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
437 test_cmp expected actual &&
438 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
439 test_cmp expected actual
442 test_expect_success 'with config setup and ":=" as separators' '
443 git config trailer.separators ":=" &&
444 git config trailer.ack.key "Acked-by= " &&
445 cat >expected <<-\EOF &&
447 Acked-by= Peff
449 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
450 test_cmp expected actual &&
451 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
452 test_cmp expected actual &&
453 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
454 test_cmp expected actual
457 test_expect_success 'with config setup and "%" as separators' '
458 git config trailer.separators "%" &&
459 cat >expected <<-\EOF &&
461 bug% 42
462 count% 10
463 bug% 422
465 git interpret-trailers --trim-empty --trailer "bug = 42" \
466 --trailer count%10 --trailer "test: stuff" \
467 --trailer "bug % 422" empty >actual &&
468 test_cmp expected actual
471 test_expect_success 'with "%" as separators and a message with trailers' '
472 cat >special_message <<-\EOF &&
473 Special Message
475 bug% 42
476 count% 10
477 bug% 422
479 cat >expected <<-\EOF &&
480 Special Message
482 bug% 42
483 count% 10
484 bug% 422
485 count% 100
487 git interpret-trailers --trailer count%100 \
488 special_message >actual &&
489 test_cmp expected actual
492 test_expect_success 'with config setup and ":=#" as separators' '
493 git config trailer.separators ":=#" &&
494 git config trailer.bug.key "Bug #" &&
495 cat >expected <<-\EOF &&
497 Bug #42
499 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
500 test_cmp expected actual
503 test_expect_success 'with commit basic message' '
504 cat basic_message >expected &&
505 echo >>expected &&
506 git interpret-trailers <basic_message >actual &&
507 test_cmp expected actual
510 test_expect_success 'with basic patch' '
511 cat basic_message >input &&
512 cat basic_patch >>input &&
513 cat basic_message >expected &&
514 echo >>expected &&
515 cat basic_patch >>expected &&
516 git interpret-trailers <input >actual &&
517 test_cmp expected actual
520 test_expect_success 'with commit complex message as argument' '
521 cat complex_message_body complex_message_trailers >complex_message &&
522 cat complex_message_body >expected &&
523 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
524 Fixes: Z
525 Acked-by= Z
526 Reviewed-by: Z
527 Signed-off-by: Z
529 git interpret-trailers complex_message >actual &&
530 test_cmp expected actual
533 test_expect_success 'with 2 files arguments' '
534 cat basic_message >>expected &&
535 echo >>expected &&
536 cat basic_patch >>expected &&
537 git interpret-trailers complex_message input >actual &&
538 test_cmp expected actual
541 test_expect_success 'with message that has comments' '
542 cat basic_message >message_with_comments &&
543 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
544 # comment
546 # other comment
547 Cc: Z
548 # yet another comment
549 Reviewed-by: Johan
550 Reviewed-by: Z
551 # last comment
554 cat basic_patch >>message_with_comments &&
555 cat basic_message >expected &&
556 cat >>expected <<-\EOF &&
557 # comment
559 Reviewed-by: Johan
560 Cc: Peff
561 # last comment
564 cat basic_patch >>expected &&
565 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
566 test_cmp expected actual
569 test_expect_success 'with message that has an old style conflict block' '
570 cat basic_message >message_with_comments &&
571 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
572 # comment
574 # other comment
575 Cc: Z
576 # yet another comment
577 Reviewed-by: Johan
578 Reviewed-by: Z
579 # last comment
581 Conflicts:
584 cat basic_message >expected &&
585 cat >>expected <<-\EOF &&
586 # comment
588 Reviewed-by: Johan
589 Cc: Peff
590 # last comment
592 Conflicts:
595 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
596 test_cmp expected actual
599 test_expect_success 'with commit complex message and trailer args' '
600 cat complex_message_body >expected &&
601 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
602 Fixes: Z
603 Acked-by= Z
604 Reviewed-by: Z
605 Signed-off-by: Z
606 Acked-by= Peff
607 Bug #42
609 git interpret-trailers --trailer "ack: Peff" \
610 --trailer "bug: 42" <complex_message >actual &&
611 test_cmp expected actual
614 test_expect_success 'with complex patch, args and --trim-empty' '
615 cat complex_message >complex_patch &&
616 cat basic_patch >>complex_patch &&
617 cat complex_message_body >expected &&
618 cat >>expected <<-\EOF &&
619 Acked-by= Peff
620 Bug #42
622 cat basic_patch >>expected &&
623 git interpret-trailers --trim-empty --trailer "ack: Peff" \
624 --trailer "bug: 42" <complex_patch >actual &&
625 test_cmp expected actual
628 test_expect_success 'in-place editing with basic patch' '
629 cat basic_message >message &&
630 cat basic_patch >>message &&
631 cat basic_message >expected &&
632 echo >>expected &&
633 cat basic_patch >>expected &&
634 git interpret-trailers --in-place message &&
635 test_cmp expected message
638 test_expect_success 'in-place editing with additional trailer' '
639 cat basic_message >message &&
640 cat basic_patch >>message &&
641 cat basic_message >expected &&
642 echo >>expected &&
643 cat >>expected <<-\EOF &&
644 Reviewed-by: Alice
646 cat basic_patch >>expected &&
647 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
648 test_cmp expected message
651 test_expect_success 'in-place editing on stdin disallowed' '
652 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
655 test_expect_success 'in-place editing on non-existing file' '
656 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
657 test_path_is_missing nonexisting
660 test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" '
661 cat basic_message >message &&
662 chmod -r message &&
663 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
664 chmod +r message &&
665 test_cmp message basic_message
668 test_expect_success 'using "where = before"' '
669 git config trailer.bug.where "before" &&
670 cat complex_message_body >expected &&
671 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
672 Bug #42
673 Fixes: Z
674 Acked-by= Z
675 Reviewed-by: Z
676 Signed-off-by: Z
677 Acked-by= Peff
679 git interpret-trailers --trailer "ack: Peff" \
680 --trailer "bug: 42" complex_message >actual &&
681 test_cmp expected actual
684 test_expect_success 'using "where = after"' '
685 git config trailer.ack.where "after" &&
686 cat complex_message_body >expected &&
687 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
688 Bug #42
689 Fixes: Z
690 Acked-by= Z
691 Acked-by= Peff
692 Reviewed-by: Z
693 Signed-off-by: Z
695 git interpret-trailers --trailer "ack: Peff" \
696 --trailer "bug: 42" complex_message >actual &&
697 test_cmp expected actual
700 test_expect_success 'using "where = end"' '
701 git config trailer.review.key "Reviewed-by" &&
702 git config trailer.review.where "end" &&
703 cat complex_message_body >expected &&
704 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
705 Fixes: Z
706 Acked-by= Z
707 Acked-by= Peff
708 Reviewed-by: Z
709 Signed-off-by: Z
710 Reviewed-by: Junio
711 Reviewed-by: Johannes
713 git interpret-trailers --trailer "ack: Peff" \
714 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
715 complex_message >actual &&
716 test_cmp expected actual
719 test_expect_success 'using "where = start"' '
720 git config trailer.review.key "Reviewed-by" &&
721 git config trailer.review.where "start" &&
722 cat complex_message_body >expected &&
723 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
724 Reviewed-by: Johannes
725 Reviewed-by: Junio
726 Fixes: Z
727 Acked-by= Z
728 Acked-by= Peff
729 Reviewed-by: Z
730 Signed-off-by: Z
732 git interpret-trailers --trailer "ack: Peff" \
733 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
734 complex_message >actual &&
735 test_cmp expected actual
738 test_expect_success 'using "where = before" for a token in the middle of the message' '
739 git config trailer.review.key "Reviewed-by:" &&
740 git config trailer.review.where "before" &&
741 cat complex_message_body >expected &&
742 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
743 Bug #42
744 Fixes: Z
745 Acked-by= Z
746 Acked-by= Peff
747 Reviewed-by:Johan
748 Reviewed-by:
749 Signed-off-by: Z
751 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
752 --trailer "review: Johan" <complex_message >actual &&
753 test_cmp expected actual
756 test_expect_success 'using "where = before" and --trim-empty' '
757 cat complex_message_body >expected &&
758 cat >>expected <<-\EOF &&
759 Bug #46
760 Bug #42
761 Acked-by= Peff
762 Reviewed-by:Johan
764 git interpret-trailers --trim-empty --trailer "ack: Peff" \
765 --trailer "bug: 42" --trailer "review: Johan" \
766 --trailer "Bug: 46" <complex_message >actual &&
767 test_cmp expected actual
770 test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
771 cat complex_message_body >expected &&
772 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
773 Bug #42
774 Fixes: Z
775 Acked-by= Z
776 Acked-by= Peff
777 Acked-by= Junio
778 Acked-by= Peff
779 Reviewed-by:
780 Signed-off-by: Z
782 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
783 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
784 --trailer "ack: Peff" <complex_message >actual &&
785 test_cmp expected actual
788 test_expect_success 'default "ifExists" is now "addIfDifferent"' '
789 git config trailer.ifexists "addIfDifferent" &&
790 cat complex_message_body >expected &&
791 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
792 Bug #42
793 Fixes: Z
794 Acked-by= Z
795 Acked-by= Peff
796 Acked-by= Junio
797 Reviewed-by:
798 Signed-off-by: Z
800 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
801 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
802 --trailer "ack: Peff" <complex_message >actual &&
803 test_cmp expected actual
806 test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
807 git config trailer.ack.ifExists "addIfDifferent" &&
808 git config trailer.ack.where "end" &&
809 cat complex_message_body >expected &&
810 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
811 Bug #42
812 Fixes: Z
813 Acked-by= Z
814 Reviewed-by:
815 Signed-off-by: Z
816 Acked-by= Peff
818 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
819 --trailer "bug: 42" --trailer "ack: Peff" \
820 <complex_message >actual &&
821 test_cmp expected actual
824 test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
825 git config trailer.ack.ifExists "addIfDifferent" &&
826 git config trailer.ack.where "before" &&
827 cat complex_message_body >expected &&
828 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
829 Bug #42
830 Fixes: Z
831 Acked-by= Peff
832 Acked-by= Z
833 Reviewed-by:
834 Signed-off-by: Z
836 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
837 --trailer "bug: 42" --trailer "ack: Peff" \
838 <complex_message >actual &&
839 test_cmp expected actual
842 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
843 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
844 git config trailer.ack.where "end" &&
845 cat complex_message_body >expected &&
846 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
847 Bug #42
848 Fixes: Z
849 Acked-by= Z
850 Reviewed-by:
851 Signed-off-by: Z
852 Acked-by= Peff
853 Acked-by= Junio
854 Tested-by: Jakub
855 Acked-by= Junio
856 Acked-by= Peff
858 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
859 --trailer "ack: Junio" --trailer "bug: 42" \
860 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
861 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
862 test_cmp expected actual
865 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
866 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
867 git config trailer.ack.where "after" &&
868 cat complex_message_body >expected &&
869 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
870 Bug #42
871 Fixes: Z
872 Acked-by= Z
873 Acked-by= Peff
874 Acked-by= Junio
875 Acked-by= Peff
876 Reviewed-by:
877 Signed-off-by: Z
878 Tested-by: Jakub
880 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
881 --trailer "ack: Junio" --trailer "bug: 42" \
882 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
883 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
884 test_cmp expected actual
887 test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
888 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
889 cat complex_message_body >expected &&
890 cat >>expected <<-\EOF &&
891 Bug #42
892 Acked-by= Peff
893 Acked-by= Junio
894 Acked-by= Peff
896 git interpret-trailers --trim-empty --trailer "ack: Peff" \
897 --trailer "Acked-by= Peff" --trailer "review:" \
898 --trailer "ack: Junio" --trailer "bug: 42" \
899 --trailer "ack: Peff" <complex_message >actual &&
900 test_cmp expected actual
903 test_expect_success 'using "ifExists = add" with "where = end"' '
904 git config trailer.ack.ifExists "add" &&
905 git config trailer.ack.where "end" &&
906 cat complex_message_body >expected &&
907 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
908 Bug #42
909 Fixes: Z
910 Acked-by= Z
911 Reviewed-by:
912 Signed-off-by: Z
913 Acked-by= Peff
914 Acked-by= Peff
915 Tested-by: Jakub
916 Acked-by= Junio
917 Tested-by: Johannes
918 Acked-by= Peff
920 git interpret-trailers --trailer "ack: Peff" \
921 --trailer "Acked-by= Peff" --trailer "review:" \
922 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
923 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
924 --trailer "ack: Peff" <complex_message >actual &&
925 test_cmp expected actual
928 test_expect_success 'using "ifExists = add" with "where = after"' '
929 git config trailer.ack.ifExists "add" &&
930 git config trailer.ack.where "after" &&
931 cat complex_message_body >expected &&
932 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
933 Bug #42
934 Fixes: Z
935 Acked-by= Z
936 Acked-by= Peff
937 Acked-by= Peff
938 Acked-by= Junio
939 Acked-by= Peff
940 Reviewed-by:
941 Signed-off-by: Z
943 git interpret-trailers --trailer "ack: Peff" \
944 --trailer "Acked-by= Peff" --trailer "review:" \
945 --trailer "ack: Junio" --trailer "bug: 42" \
946 --trailer "ack: Peff" <complex_message >actual &&
947 test_cmp expected actual
950 test_expect_success 'using "ifExists = replace"' '
951 git config trailer.fix.key "Fixes: " &&
952 git config trailer.fix.ifExists "replace" &&
953 cat complex_message_body >expected &&
954 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
955 Bug #42
956 Acked-by= Z
957 Acked-by= Junio
958 Acked-by= Peff
959 Reviewed-by:
960 Signed-off-by: Z
961 Fixes: 22
963 git interpret-trailers --trailer "review:" \
964 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
965 --trailer "bug: 42" --trailer "ack: Peff" \
966 <complex_message >actual &&
967 test_cmp expected actual
970 test_expect_success 'using "ifExists = replace" with "where = after"' '
971 git config trailer.fix.where "after" &&
972 cat complex_message_body >expected &&
973 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
974 Bug #42
975 Fixes: 22
976 Acked-by= Z
977 Acked-by= Junio
978 Acked-by= Peff
979 Reviewed-by:
980 Signed-off-by: Z
982 git interpret-trailers --trailer "review:" \
983 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
984 --trailer "bug: 42" --trailer "ack: Peff" \
985 <complex_message >actual &&
986 test_cmp expected actual
989 test_expect_success 'using "ifExists = doNothing"' '
990 git config trailer.fix.ifExists "doNothing" &&
991 cat complex_message_body >expected &&
992 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
993 Bug #42
994 Fixes: Z
995 Acked-by= Z
996 Acked-by= Junio
997 Acked-by= Peff
998 Reviewed-by:
999 Signed-off-by: Z
1001 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1002 --trailer "ack: Junio" --trailer "fix=22" \
1003 --trailer "bug: 42" --trailer "ack: Peff" \
1004 <complex_message >actual &&
1005 test_cmp expected actual
1008 test_expect_success 'the default is "ifMissing = add"' '
1009 git config trailer.cc.key "Cc: " &&
1010 git config trailer.cc.where "before" &&
1011 cat complex_message_body >expected &&
1012 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1013 Bug #42
1014 Cc: Linus
1015 Fixes: Z
1016 Acked-by= Z
1017 Acked-by= Junio
1018 Acked-by= Peff
1019 Reviewed-by:
1020 Signed-off-by: Z
1022 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1023 --trailer "cc=Linus" --trailer "ack: Junio" \
1024 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1025 <complex_message >actual &&
1026 test_cmp expected actual
1029 test_expect_success 'when default "ifMissing" is "doNothing"' '
1030 git config trailer.ifmissing "doNothing" &&
1031 cat complex_message_body >expected &&
1032 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1033 Fixes: Z
1034 Acked-by= Z
1035 Acked-by= Junio
1036 Acked-by= Peff
1037 Reviewed-by:
1038 Signed-off-by: Z
1040 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1041 --trailer "cc=Linus" --trailer "ack: Junio" \
1042 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1043 <complex_message >actual &&
1044 test_cmp expected actual &&
1045 git config trailer.ifmissing "add"
1048 test_expect_success 'using "ifMissing = add" with "where = end"' '
1049 git config trailer.cc.key "Cc: " &&
1050 git config trailer.cc.where "end" &&
1051 git config trailer.cc.ifMissing "add" &&
1052 cat complex_message_body >expected &&
1053 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1054 Bug #42
1055 Fixes: Z
1056 Acked-by= Z
1057 Acked-by= Junio
1058 Acked-by= Peff
1059 Reviewed-by:
1060 Signed-off-by: Z
1061 Cc: Linus
1063 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1064 --trailer "ack: Junio" --trailer "fix=22" \
1065 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1066 <complex_message >actual &&
1067 test_cmp expected actual
1070 test_expect_success 'using "ifMissing = add" with "where = before"' '
1071 git config trailer.cc.key "Cc: " &&
1072 git config trailer.cc.where "before" &&
1073 git config trailer.cc.ifMissing "add" &&
1074 cat complex_message_body >expected &&
1075 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1076 Cc: Linus
1077 Bug #42
1078 Fixes: Z
1079 Acked-by= Z
1080 Acked-by= Junio
1081 Acked-by= Peff
1082 Reviewed-by:
1083 Signed-off-by: Z
1085 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1086 --trailer "ack: Junio" --trailer "fix=22" \
1087 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1088 <complex_message >actual &&
1089 test_cmp expected actual
1092 test_expect_success 'using "ifMissing = doNothing"' '
1093 git config trailer.cc.ifMissing "doNothing" &&
1094 cat complex_message_body >expected &&
1095 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1096 Bug #42
1097 Fixes: Z
1098 Acked-by= Z
1099 Acked-by= Junio
1100 Acked-by= Peff
1101 Reviewed-by:
1102 Signed-off-by: Z
1104 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1105 --trailer "cc=Linus" --trailer "ack: Junio" \
1106 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1107 <complex_message >actual &&
1108 test_cmp expected actual
1111 test_expect_success 'default "where" is now "after"' '
1112 git config trailer.where "after" &&
1113 git config --unset trailer.ack.where &&
1114 cat complex_message_body >expected &&
1115 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1116 Bug #42
1117 Fixes: Z
1118 Acked-by= Z
1119 Acked-by= Peff
1120 Acked-by= Peff
1121 Acked-by= Junio
1122 Acked-by= Peff
1123 Reviewed-by:
1124 Signed-off-by: Z
1125 Tested-by: Jakub
1126 Tested-by: Johannes
1128 git interpret-trailers --trailer "ack: Peff" \
1129 --trailer "Acked-by= Peff" --trailer "review:" \
1130 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1131 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1132 --trailer "ack: Peff" <complex_message >actual &&
1133 test_cmp expected actual
1136 test_expect_success 'with simple command' '
1137 git config trailer.sign.key "Signed-off-by: " &&
1138 git config trailer.sign.where "after" &&
1139 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1140 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
1141 cat complex_message_body >expected &&
1142 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1143 Fixes: Z
1144 Acked-by= Z
1145 Reviewed-by:
1146 Signed-off-by: Z
1147 Signed-off-by: A U Thor <author@example.com>
1149 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1150 <complex_message >actual &&
1151 test_cmp expected actual
1154 test_expect_success 'with command using commiter information' '
1155 git config trailer.sign.ifExists "addIfDifferent" &&
1156 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
1157 cat complex_message_body >expected &&
1158 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1159 Fixes: Z
1160 Acked-by= Z
1161 Reviewed-by:
1162 Signed-off-by: Z
1163 Signed-off-by: C O Mitter <committer@example.com>
1165 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1166 <complex_message >actual &&
1167 test_cmp expected actual
1170 test_expect_success 'with command using author information' '
1171 git config trailer.sign.key "Signed-off-by: " &&
1172 git config trailer.sign.where "after" &&
1173 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1174 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1175 cat complex_message_body >expected &&
1176 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1177 Fixes: Z
1178 Acked-by= Z
1179 Reviewed-by:
1180 Signed-off-by: Z
1181 Signed-off-by: A U Thor <author@example.com>
1183 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1184 <complex_message >actual &&
1185 test_cmp expected actual
1188 test_expect_success 'setup a commit' '
1189 echo "Content of the first commit." > a.txt &&
1190 git add a.txt &&
1191 git commit -m "Add file a.txt"
1194 test_expect_success 'with command using $ARG' '
1195 git config trailer.fix.ifExists "replace" &&
1196 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1197 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1198 cat complex_message_body >expected &&
1199 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1200 Fixes: $FIXED
1201 Acked-by= Z
1202 Reviewed-by:
1203 Signed-off-by: Z
1204 Signed-off-by: A U Thor <author@example.com>
1206 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1207 <complex_message >actual &&
1208 test_cmp expected actual
1211 test_expect_success 'with failing command using $ARG' '
1212 git config trailer.fix.ifExists "replace" &&
1213 git config trailer.fix.command "false \$ARG" &&
1214 cat complex_message_body >expected &&
1215 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1216 Fixes: Z
1217 Acked-by= Z
1218 Reviewed-by:
1219 Signed-off-by: Z
1220 Signed-off-by: A U Thor <author@example.com>
1222 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1223 <complex_message >actual &&
1224 test_cmp expected actual
1227 test_expect_success 'with empty tokens' '
1228 git config --unset trailer.fix.command &&
1229 cat >expected <<-EOF &&
1231 Signed-off-by: A U Thor <author@example.com>
1233 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1235 test_cmp expected actual
1238 test_expect_success 'with command but no key' '
1239 git config --unset trailer.sign.key &&
1240 cat >expected <<-EOF &&
1242 sign: A U Thor <author@example.com>
1244 git interpret-trailers >actual <<-EOF &&
1246 test_cmp expected actual
1249 test_expect_success 'with no command and no key' '
1250 git config --unset trailer.review.key &&
1251 cat >expected <<-EOF &&
1253 review: Junio
1254 sign: A U Thor <author@example.com>
1256 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1258 test_cmp expected actual
1261 test_done