3 # Copyright (c) 2013, 2014 Christian Couder
6 test_description='git interpret-trailers'
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' '
15 cat >basic_message <<-\EOF &&
20 cat >complex_message_body <<-\EOF &&
24 and contains some special
28 sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF &&
34 cat >basic_patch <<-\EOF
37 1 file changed, 1 insertion(+), 1 deletion(-)
39 diff --git a/foo.txt b/foo.txt
40 index 0353767..1d91aa1 100644
54 test_expect_success 'without config' '
55 sed -e "s/ Z\$/ /" >expected <<-\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 &&
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 &&
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 &&
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 &&
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 &&
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
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
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
175 this is not a trailer
177 cat >expected <<-\EOF &&
179 this is not a trailer
180 this is not a trailer
182 this is not a trailer
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
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
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
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 &&
249 q_to_tab >expected <<-\EOF &&
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>
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>
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
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 &&
297 q_to_tab >expected <<-\EOF &&
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 &&
318 q_to_tab >expected <<-\EOF &&
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 &&
337 test_config trailer.name.ifexists addIfDifferent &&
339 q_to_tab >trailer <<-\EOF &&
343 q_to_tab >expected <<-\EOF &&
350 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
351 test_cmp expected actual &&
353 q_to_tab >trailer <<-\EOF &&
357 q_to_tab >expected <<-\EOF &&
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*
373 q_to_tab >expected <<-\EOF &&
379 name: first line *DIFFERENT*
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 &&
394 test_config trailer.name.where after &&
395 test_config trailer.name.ifexists addIfDifferentNeighbor &&
397 q_to_tab >trailer <<-\EOF &&
401 q_to_tab >expected <<-\EOF &&
408 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
409 test_cmp expected actual &&
411 q_to_tab >trailer <<-\EOF &&
415 q_to_tab >expected <<-\EOF &&
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 &&
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 &&
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 &&
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 &&
479 cat >expected <<-\EOF &&
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 &&
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 &&
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 &&
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 &&
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 &&
536 cat basic_patch >>expected &&
537 git interpret-trailers complex_message input >actual &&
538 test_cmp expected actual
541 # Cover multiple comment characters with the same test input.
546 # This is the default, so let's explicitly _not_
547 # set any config to make sure it behaves as we expect.
550 config="-c core.commentChar=$char"
554 test_expect_success "with message that has comments ($char)" '
555 cat basic_message >message_with_comments &&
557 -e "s/#/$char/g" >>message_with_comments <<-EOF &&
562 # yet another comment
568 cat basic_patch >>message_with_comments &&
569 cat basic_message >expected &&
570 sed -e "s/#/$char/g" >>expected <<-\EOF &&
578 cat basic_patch >>expected &&
579 git $config interpret-trailers \
580 --trim-empty --trailer "Cc: Peff" \
581 message_with_comments >actual &&
582 test_cmp expected actual
586 test_expect_success 'with message that has an old style conflict block' '
587 cat basic_message >message_with_comments &&
588 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
593 # yet another comment
601 cat basic_message >expected &&
602 cat >>expected <<-\EOF &&
612 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
613 test_cmp expected actual
616 test_expect_success 'with commit complex message and trailer args' '
617 cat complex_message_body >expected &&
618 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
626 git interpret-trailers --trailer "ack: Peff" \
627 --trailer "bug: 42" <complex_message >actual &&
628 test_cmp expected actual
631 test_expect_success 'with complex patch, args and --trim-empty' '
632 cat complex_message >complex_patch &&
633 cat basic_patch >>complex_patch &&
634 cat complex_message_body >expected &&
635 cat >>expected <<-\EOF &&
639 cat basic_patch >>expected &&
640 git interpret-trailers --trim-empty --trailer "ack: Peff" \
641 --trailer "bug: 42" <complex_patch >actual &&
642 test_cmp expected actual
645 test_expect_success 'in-place editing with basic patch' '
646 cat basic_message >message &&
647 cat basic_patch >>message &&
648 cat basic_message >expected &&
650 cat basic_patch >>expected &&
651 git interpret-trailers --in-place message &&
652 test_cmp expected message
655 test_expect_success 'in-place editing with additional trailer' '
656 cat basic_message >message &&
657 cat basic_patch >>message &&
658 cat basic_message >expected &&
660 cat >>expected <<-\EOF &&
663 cat basic_patch >>expected &&
664 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
665 test_cmp expected message
668 test_expect_success 'in-place editing on stdin disallowed' '
669 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
672 test_expect_success 'in-place editing on non-existing file' '
673 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
674 test_path_is_missing nonexisting
677 test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" '
678 cat basic_message >message &&
680 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
682 test_cmp message basic_message
685 test_expect_success 'using "where = before"' '
686 git config trailer.bug.where "before" &&
687 cat complex_message_body >expected &&
688 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
696 git interpret-trailers --trailer "ack: Peff" \
697 --trailer "bug: 42" complex_message >actual &&
698 test_cmp expected actual
701 test_expect_success 'overriding configuration with "--where after"' '
702 git config trailer.ack.where "before" &&
703 cat complex_message_body >expected &&
704 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
711 git interpret-trailers --where after --trailer "ack: Peff" \
712 complex_message >actual &&
713 test_cmp expected actual
716 test_expect_success 'using "where = before" with "--no-where"' '
717 cat complex_message_body >expected &&
718 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
726 git interpret-trailers --where after --no-where --trailer "ack: Peff" \
727 --trailer "bug: 42" complex_message >actual &&
728 test_cmp expected actual
731 test_expect_success 'using "where = after"' '
732 git config trailer.ack.where "after" &&
733 cat complex_message_body >expected &&
734 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
742 git interpret-trailers --trailer "ack: Peff" \
743 --trailer "bug: 42" complex_message >actual &&
744 test_cmp expected actual
747 test_expect_success 'using "where = end"' '
748 git config trailer.review.key "Reviewed-by" &&
749 git config trailer.review.where "end" &&
750 cat complex_message_body >expected &&
751 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
758 Reviewed-by: Johannes
760 git interpret-trailers --trailer "ack: Peff" \
761 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
762 complex_message >actual &&
763 test_cmp expected actual
766 test_expect_success 'using "where = start"' '
767 git config trailer.review.key "Reviewed-by" &&
768 git config trailer.review.where "start" &&
769 cat complex_message_body >expected &&
770 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
771 Reviewed-by: Johannes
779 git interpret-trailers --trailer "ack: Peff" \
780 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
781 complex_message >actual &&
782 test_cmp expected actual
785 test_expect_success 'using "where = before" for a token in the middle of the message' '
786 git config trailer.review.key "Reviewed-by:" &&
787 git config trailer.review.where "before" &&
788 cat complex_message_body >expected &&
789 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
798 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
799 --trailer "review: Johan" <complex_message >actual &&
800 test_cmp expected actual
803 test_expect_success 'using "where = before" and --trim-empty' '
804 cat complex_message_body >expected &&
805 cat >>expected <<-\EOF &&
811 git interpret-trailers --trim-empty --trailer "ack: Peff" \
812 --trailer "bug: 42" --trailer "review: Johan" \
813 --trailer "Bug: 46" <complex_message >actual &&
814 test_cmp expected actual
817 test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
818 cat complex_message_body >expected &&
819 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
829 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
830 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
831 --trailer "ack: Peff" <complex_message >actual &&
832 test_cmp expected actual
835 test_expect_success 'default "ifExists" is now "addIfDifferent"' '
836 git config trailer.ifexists "addIfDifferent" &&
837 cat complex_message_body >expected &&
838 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
847 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
848 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
849 --trailer "ack: Peff" <complex_message >actual &&
850 test_cmp expected actual
853 test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
854 git config trailer.ack.ifExists "addIfDifferent" &&
855 git config trailer.ack.where "end" &&
856 cat complex_message_body >expected &&
857 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
865 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
866 --trailer "bug: 42" --trailer "ack: Peff" \
867 <complex_message >actual &&
868 test_cmp expected actual
871 test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
872 git config trailer.ack.ifExists "addIfDifferent" &&
873 git config trailer.ack.where "before" &&
874 cat complex_message_body >expected &&
875 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
883 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
884 --trailer "bug: 42" --trailer "ack: Peff" \
885 <complex_message >actual &&
886 test_cmp expected actual
889 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
890 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
891 git config trailer.ack.where "end" &&
892 cat complex_message_body >expected &&
893 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
905 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
906 --trailer "ack: Junio" --trailer "bug: 42" \
907 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
908 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
909 test_cmp expected actual
912 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
913 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
914 git config trailer.ack.where "after" &&
915 cat complex_message_body >expected &&
916 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
927 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
928 --trailer "ack: Junio" --trailer "bug: 42" \
929 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
930 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
931 test_cmp expected actual
934 test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
935 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
936 cat complex_message_body >expected &&
937 cat >>expected <<-\EOF &&
943 git interpret-trailers --trim-empty --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 = add" with "where = end"' '
951 git config trailer.ack.ifExists "add" &&
952 git config trailer.ack.where "end" &&
953 cat complex_message_body >expected &&
954 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
967 git interpret-trailers --trailer "ack: Peff" \
968 --trailer "Acked-by= Peff" --trailer "review:" \
969 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
970 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
971 --trailer "ack: Peff" <complex_message >actual &&
972 test_cmp expected actual
975 test_expect_success 'using "ifExists = add" with "where = after"' '
976 git config trailer.ack.ifExists "add" &&
977 git config trailer.ack.where "after" &&
978 cat complex_message_body >expected &&
979 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
990 git interpret-trailers --trailer "ack: Peff" \
991 --trailer "Acked-by= Peff" --trailer "review:" \
992 --trailer "ack: Junio" --trailer "bug: 42" \
993 --trailer "ack: Peff" <complex_message >actual &&
994 test_cmp expected actual
997 test_expect_success 'overriding configuration with "--if-exists replace"' '
998 git config trailer.fix.key "Fixes: " &&
999 git config trailer.fix.ifExists "add" &&
1000 cat complex_message_body >expected &&
1001 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1008 git interpret-trailers --if-exists replace --trailer "review:" \
1009 --trailer "fix=53" --trailer "fix=22" --trailer "bug: 42" \
1010 <complex_message >actual &&
1011 test_cmp expected actual
1014 test_expect_success 'using "ifExists = replace"' '
1015 git config trailer.fix.key "Fixes: " &&
1016 git config trailer.fix.ifExists "replace" &&
1017 cat complex_message_body >expected &&
1018 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1027 git interpret-trailers --trailer "review:" \
1028 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1029 --trailer "bug: 42" --trailer "ack: Peff" \
1030 <complex_message >actual &&
1031 test_cmp expected actual
1034 test_expect_success 'using "ifExists = replace" with "where = after"' '
1035 git config trailer.fix.where "after" &&
1036 cat complex_message_body >expected &&
1037 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1046 git interpret-trailers --trailer "review:" \
1047 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1048 --trailer "bug: 42" --trailer "ack: Peff" \
1049 <complex_message >actual &&
1050 test_cmp expected actual
1053 test_expect_success 'using "ifExists = doNothing"' '
1054 git config trailer.fix.ifExists "doNothing" &&
1055 cat complex_message_body >expected &&
1056 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1065 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1066 --trailer "ack: Junio" --trailer "fix=22" \
1067 --trailer "bug: 42" --trailer "ack: Peff" \
1068 <complex_message >actual &&
1069 test_cmp expected actual
1072 test_expect_success 'the default is "ifMissing = add"' '
1073 git config trailer.cc.key "Cc: " &&
1074 git config trailer.cc.where "before" &&
1075 cat complex_message_body >expected &&
1076 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1086 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1087 --trailer "cc=Linus" --trailer "ack: Junio" \
1088 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1089 <complex_message >actual &&
1090 test_cmp expected actual
1093 test_expect_success 'overriding configuration with "--if-missing doNothing"' '
1094 git config trailer.ifmissing "add" &&
1095 cat complex_message_body >expected &&
1096 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1104 git interpret-trailers --if-missing doNothing \
1105 --trailer "review:" --trailer "fix=53" \
1106 --trailer "cc=Linus" --trailer "ack: Junio" \
1107 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1108 <complex_message >actual &&
1109 test_cmp expected actual
1112 test_expect_success 'when default "ifMissing" is "doNothing"' '
1113 git config trailer.ifmissing "doNothing" &&
1114 cat complex_message_body >expected &&
1115 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1123 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1124 --trailer "cc=Linus" --trailer "ack: Junio" \
1125 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1126 <complex_message >actual &&
1127 test_cmp expected actual &&
1128 git config trailer.ifmissing "add"
1131 test_expect_success 'using "ifMissing = add" with "where = end"' '
1132 git config trailer.cc.key "Cc: " &&
1133 git config trailer.cc.where "end" &&
1134 git config trailer.cc.ifMissing "add" &&
1135 cat complex_message_body >expected &&
1136 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1146 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1147 --trailer "ack: Junio" --trailer "fix=22" \
1148 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1149 <complex_message >actual &&
1150 test_cmp expected actual
1153 test_expect_success 'using "ifMissing = add" with "where = before"' '
1154 git config trailer.cc.key "Cc: " &&
1155 git config trailer.cc.where "before" &&
1156 git config trailer.cc.ifMissing "add" &&
1157 cat complex_message_body >expected &&
1158 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1168 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1169 --trailer "ack: Junio" --trailer "fix=22" \
1170 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1171 <complex_message >actual &&
1172 test_cmp expected actual
1175 test_expect_success 'using "ifMissing = doNothing"' '
1176 git config trailer.cc.ifMissing "doNothing" &&
1177 cat complex_message_body >expected &&
1178 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1187 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1188 --trailer "cc=Linus" --trailer "ack: Junio" \
1189 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1190 <complex_message >actual &&
1191 test_cmp expected actual
1194 test_expect_success 'default "where" is now "after"' '
1195 git config trailer.where "after" &&
1196 git config --unset trailer.ack.where &&
1197 cat complex_message_body >expected &&
1198 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1211 git interpret-trailers --trailer "ack: Peff" \
1212 --trailer "Acked-by= Peff" --trailer "review:" \
1213 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1214 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1215 --trailer "ack: Peff" <complex_message >actual &&
1216 test_cmp expected actual
1219 test_expect_success 'with simple command' '
1220 git config trailer.sign.key "Signed-off-by: " &&
1221 git config trailer.sign.where "after" &&
1222 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1223 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
1224 cat complex_message_body >expected &&
1225 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1230 Signed-off-by: A U Thor <author@example.com>
1232 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1233 <complex_message >actual &&
1234 test_cmp expected actual
1237 test_expect_success 'with command using committer information' '
1238 git config trailer.sign.ifExists "addIfDifferent" &&
1239 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
1240 cat complex_message_body >expected &&
1241 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1246 Signed-off-by: C O Mitter <committer@example.com>
1248 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1249 <complex_message >actual &&
1250 test_cmp expected actual
1253 test_expect_success 'with command using author information' '
1254 git config trailer.sign.key "Signed-off-by: " &&
1255 git config trailer.sign.where "after" &&
1256 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1257 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1258 cat complex_message_body >expected &&
1259 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1264 Signed-off-by: A U Thor <author@example.com>
1266 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1267 <complex_message >actual &&
1268 test_cmp expected actual
1271 test_expect_success 'setup a commit' '
1272 echo "Content of the first commit." > a.txt &&
1274 git commit -m "Add file a.txt"
1277 test_expect_success 'with command using $ARG' '
1278 git config trailer.fix.ifExists "replace" &&
1279 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1280 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1281 cat complex_message_body >expected &&
1282 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1287 Signed-off-by: A U Thor <author@example.com>
1289 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1290 <complex_message >actual &&
1291 test_cmp expected actual
1294 test_expect_success 'with failing command using $ARG' '
1295 git config trailer.fix.ifExists "replace" &&
1296 git config trailer.fix.command "false \$ARG" &&
1297 cat complex_message_body >expected &&
1298 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1303 Signed-off-by: A U Thor <author@example.com>
1305 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1306 <complex_message >actual &&
1307 test_cmp expected actual
1310 test_expect_success 'with empty tokens' '
1311 git config --unset trailer.fix.command &&
1312 cat >expected <<-EOF &&
1314 Signed-off-by: A U Thor <author@example.com>
1316 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1318 test_cmp expected actual
1321 test_expect_success 'with command but no key' '
1322 git config --unset trailer.sign.key &&
1323 cat >expected <<-EOF &&
1325 sign: A U Thor <author@example.com>
1327 git interpret-trailers >actual <<-EOF &&
1329 test_cmp expected actual
1332 test_expect_success 'with no command and no key' '
1333 git config --unset trailer.review.key &&
1334 cat >expected <<-EOF &&
1337 sign: A U Thor <author@example.com>
1339 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1341 test_cmp expected actual
1344 test_expect_success 'with cut line' '
1345 cat >expected <<-\EOF &&
1349 sign: A U Thor <author@example.com>
1350 # ------------------------ >8 ------------------------
1353 git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
1355 # ------------------------ >8 ------------------------
1358 test_cmp expected actual
1361 test_expect_success 'only trailers' '
1362 git config trailer.sign.command "echo config-value" &&
1363 cat >expected <<-\EOF &&
1364 existing: existing-value
1368 git interpret-trailers \
1369 --trailer added:added-value \
1370 --only-trailers >actual <<-\EOF &&
1375 existing: existing-value
1377 test_cmp expected actual
1380 test_expect_success 'only-trailers omits non-trailer in middle of block' '
1381 git config trailer.sign.command "echo config-value" &&
1382 cat >expected <<-\EOF &&
1383 Signed-off-by: nobody <nobody@nowhere>
1384 Signed-off-by: somebody <somebody@somewhere>
1387 git interpret-trailers --only-trailers >actual <<-\EOF &&
1390 it is important that the trailers below are signed-off-by
1391 so that they meet the "25% trailers Git knows about" heuristic
1393 Signed-off-by: nobody <nobody@nowhere>
1394 this is not a trailer
1395 Signed-off-by: somebody <somebody@somewhere>
1397 test_cmp expected actual
1400 test_expect_success 'only input' '
1401 git config trailer.sign.command "echo config-value" &&
1402 cat >expected <<-\EOF &&
1403 existing: existing-value
1405 git interpret-trailers \
1406 --only-trailers --only-input >actual <<-\EOF &&
1411 existing: existing-value
1413 test_cmp expected actual
1416 test_expect_success 'unfold' '
1417 cat >expected <<-\EOF &&
1418 foo: continued across several lines
1420 # pass through tr to make leading and trailing whitespace more obvious
1433 git interpret-trailers --only-trailers --only-input --unfold >actual &&
1434 test_cmp expected actual
1437 test_expect_success 'handling of --- lines in input' '
1438 echo "real-trailer: just right" >expected &&
1440 git interpret-trailers --parse >actual <<-\EOF &&
1445 not-a-trailer: too soon
1446 ------ this is just a line in the commit message with a bunch of
1447 ------ dashes; it does not have any syntactic meaning.
1449 real-trailer: just right
1451 below the dashed line may be a patch, etc.
1453 not-a-trailer: too late
1456 test_cmp expected actual
1459 test_expect_success 'suppress --- handling' '
1460 echo "real-trailer: just right" >expected &&
1462 git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1465 This commit message has a "---" in it, but because we tell
1466 interpret-trailers not to respect that, it has no effect.
1468 not-a-trailer: too soon
1471 This is still the commit message body.
1473 real-trailer: just right
1476 test_cmp expected actual