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 test_expect_success 'with message that has comments' '
542 cat basic_message >message_with_comments &&
543 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
548 # yet another comment
554 cat basic_patch >>message_with_comments &&
555 cat basic_message >expected &&
556 cat >>expected <<-\EOF &&
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 &&
576 # yet another comment
584 cat basic_message >expected &&
585 cat >>expected <<-\EOF &&
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 &&
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 &&
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 &&
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 &&
643 cat >>expected <<-\EOF &&
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 &&
663 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place 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 &&
679 git interpret-trailers --trailer "ack: Peff" \
680 --trailer "bug: 42" complex_message >actual &&
681 test_cmp expected actual
684 test_expect_success 'overriding configuration with "--where after"' '
685 git config trailer.ack.where "before" &&
686 cat complex_message_body >expected &&
687 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
694 git interpret-trailers --where after --trailer "ack: Peff" \
695 complex_message >actual &&
696 test_cmp expected actual
699 test_expect_success 'using "where = before" with "--no-where"' '
700 cat complex_message_body >expected &&
701 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
709 git interpret-trailers --where after --no-where --trailer "ack: Peff" \
710 --trailer "bug: 42" complex_message >actual &&
711 test_cmp expected actual
714 test_expect_success 'using "where = after"' '
715 git config trailer.ack.where "after" &&
716 cat complex_message_body >expected &&
717 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
725 git interpret-trailers --trailer "ack: Peff" \
726 --trailer "bug: 42" complex_message >actual &&
727 test_cmp expected actual
730 test_expect_success 'using "where = end"' '
731 git config trailer.review.key "Reviewed-by" &&
732 git config trailer.review.where "end" &&
733 cat complex_message_body >expected &&
734 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
741 Reviewed-by: Johannes
743 git interpret-trailers --trailer "ack: Peff" \
744 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
745 complex_message >actual &&
746 test_cmp expected actual
749 test_expect_success 'using "where = start"' '
750 git config trailer.review.key "Reviewed-by" &&
751 git config trailer.review.where "start" &&
752 cat complex_message_body >expected &&
753 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
754 Reviewed-by: Johannes
762 git interpret-trailers --trailer "ack: Peff" \
763 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
764 complex_message >actual &&
765 test_cmp expected actual
768 test_expect_success 'using "where = before" for a token in the middle of the message' '
769 git config trailer.review.key "Reviewed-by:" &&
770 git config trailer.review.where "before" &&
771 cat complex_message_body >expected &&
772 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
781 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
782 --trailer "review: Johan" <complex_message >actual &&
783 test_cmp expected actual
786 test_expect_success 'using "where = before" and --trim-empty' '
787 cat complex_message_body >expected &&
788 cat >>expected <<-\EOF &&
794 git interpret-trailers --trim-empty --trailer "ack: Peff" \
795 --trailer "bug: 42" --trailer "review: Johan" \
796 --trailer "Bug: 46" <complex_message >actual &&
797 test_cmp expected actual
800 test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
801 cat complex_message_body >expected &&
802 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
812 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
813 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
814 --trailer "ack: Peff" <complex_message >actual &&
815 test_cmp expected actual
818 test_expect_success 'default "ifExists" is now "addIfDifferent"' '
819 git config trailer.ifexists "addIfDifferent" &&
820 cat complex_message_body >expected &&
821 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
830 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
831 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
832 --trailer "ack: Peff" <complex_message >actual &&
833 test_cmp expected actual
836 test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
837 git config trailer.ack.ifExists "addIfDifferent" &&
838 git config trailer.ack.where "end" &&
839 cat complex_message_body >expected &&
840 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
848 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
849 --trailer "bug: 42" --trailer "ack: Peff" \
850 <complex_message >actual &&
851 test_cmp expected actual
854 test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
855 git config trailer.ack.ifExists "addIfDifferent" &&
856 git config trailer.ack.where "before" &&
857 cat complex_message_body >expected &&
858 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
866 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
867 --trailer "bug: 42" --trailer "ack: Peff" \
868 <complex_message >actual &&
869 test_cmp expected actual
872 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
873 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
874 git config trailer.ack.where "end" &&
875 cat complex_message_body >expected &&
876 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
888 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
889 --trailer "ack: Junio" --trailer "bug: 42" \
890 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
891 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
892 test_cmp expected actual
895 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
896 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
897 git config trailer.ack.where "after" &&
898 cat complex_message_body >expected &&
899 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
910 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
911 --trailer "ack: Junio" --trailer "bug: 42" \
912 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
913 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
914 test_cmp expected actual
917 test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
918 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
919 cat complex_message_body >expected &&
920 cat >>expected <<-\EOF &&
926 git interpret-trailers --trim-empty --trailer "ack: Peff" \
927 --trailer "Acked-by= Peff" --trailer "review:" \
928 --trailer "ack: Junio" --trailer "bug: 42" \
929 --trailer "ack: Peff" <complex_message >actual &&
930 test_cmp expected actual
933 test_expect_success 'using "ifExists = add" with "where = end"' '
934 git config trailer.ack.ifExists "add" &&
935 git config trailer.ack.where "end" &&
936 cat complex_message_body >expected &&
937 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
950 git interpret-trailers --trailer "ack: Peff" \
951 --trailer "Acked-by= Peff" --trailer "review:" \
952 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
953 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
954 --trailer "ack: Peff" <complex_message >actual &&
955 test_cmp expected actual
958 test_expect_success 'using "ifExists = add" with "where = after"' '
959 git config trailer.ack.ifExists "add" &&
960 git config trailer.ack.where "after" &&
961 cat complex_message_body >expected &&
962 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
973 git interpret-trailers --trailer "ack: Peff" \
974 --trailer "Acked-by= Peff" --trailer "review:" \
975 --trailer "ack: Junio" --trailer "bug: 42" \
976 --trailer "ack: Peff" <complex_message >actual &&
977 test_cmp expected actual
980 test_expect_success 'overriding configuration with "--if-exists replace"' '
981 git config trailer.fix.key "Fixes: " &&
982 git config trailer.fix.ifExists "add" &&
983 cat complex_message_body >expected &&
984 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
991 git interpret-trailers --if-exists replace --trailer "review:" \
992 --trailer "fix=53" --trailer "fix=22" --trailer "bug: 42" \
993 <complex_message >actual &&
994 test_cmp expected actual
997 test_expect_success 'using "ifExists = replace"' '
998 git config trailer.fix.key "Fixes: " &&
999 git config trailer.fix.ifExists "replace" &&
1000 cat complex_message_body >expected &&
1001 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1010 git interpret-trailers --trailer "review:" \
1011 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1012 --trailer "bug: 42" --trailer "ack: Peff" \
1013 <complex_message >actual &&
1014 test_cmp expected actual
1017 test_expect_success 'using "ifExists = replace" with "where = after"' '
1018 git config trailer.fix.where "after" &&
1019 cat complex_message_body >expected &&
1020 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1029 git interpret-trailers --trailer "review:" \
1030 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1031 --trailer "bug: 42" --trailer "ack: Peff" \
1032 <complex_message >actual &&
1033 test_cmp expected actual
1036 test_expect_success 'using "ifExists = doNothing"' '
1037 git config trailer.fix.ifExists "doNothing" &&
1038 cat complex_message_body >expected &&
1039 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1048 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1049 --trailer "ack: Junio" --trailer "fix=22" \
1050 --trailer "bug: 42" --trailer "ack: Peff" \
1051 <complex_message >actual &&
1052 test_cmp expected actual
1055 test_expect_success 'the default is "ifMissing = add"' '
1056 git config trailer.cc.key "Cc: " &&
1057 git config trailer.cc.where "before" &&
1058 cat complex_message_body >expected &&
1059 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1069 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1070 --trailer "cc=Linus" --trailer "ack: Junio" \
1071 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1072 <complex_message >actual &&
1073 test_cmp expected actual
1076 test_expect_success 'overriding configuration with "--if-missing doNothing"' '
1077 git config trailer.ifmissing "add" &&
1078 cat complex_message_body >expected &&
1079 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1087 git interpret-trailers --if-missing doNothing \
1088 --trailer "review:" --trailer "fix=53" \
1089 --trailer "cc=Linus" --trailer "ack: Junio" \
1090 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1091 <complex_message >actual &&
1092 test_cmp expected actual
1095 test_expect_success 'when default "ifMissing" is "doNothing"' '
1096 git config trailer.ifmissing "doNothing" &&
1097 cat complex_message_body >expected &&
1098 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1106 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1107 --trailer "cc=Linus" --trailer "ack: Junio" \
1108 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1109 <complex_message >actual &&
1110 test_cmp expected actual &&
1111 git config trailer.ifmissing "add"
1114 test_expect_success 'using "ifMissing = add" with "where = end"' '
1115 git config trailer.cc.key "Cc: " &&
1116 git config trailer.cc.where "end" &&
1117 git config trailer.cc.ifMissing "add" &&
1118 cat complex_message_body >expected &&
1119 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1129 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1130 --trailer "ack: Junio" --trailer "fix=22" \
1131 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1132 <complex_message >actual &&
1133 test_cmp expected actual
1136 test_expect_success 'using "ifMissing = add" with "where = before"' '
1137 git config trailer.cc.key "Cc: " &&
1138 git config trailer.cc.where "before" &&
1139 git config trailer.cc.ifMissing "add" &&
1140 cat complex_message_body >expected &&
1141 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1151 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1152 --trailer "ack: Junio" --trailer "fix=22" \
1153 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1154 <complex_message >actual &&
1155 test_cmp expected actual
1158 test_expect_success 'using "ifMissing = doNothing"' '
1159 git config trailer.cc.ifMissing "doNothing" &&
1160 cat complex_message_body >expected &&
1161 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1170 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1171 --trailer "cc=Linus" --trailer "ack: Junio" \
1172 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1173 <complex_message >actual &&
1174 test_cmp expected actual
1177 test_expect_success 'default "where" is now "after"' '
1178 git config trailer.where "after" &&
1179 git config --unset trailer.ack.where &&
1180 cat complex_message_body >expected &&
1181 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1194 git interpret-trailers --trailer "ack: Peff" \
1195 --trailer "Acked-by= Peff" --trailer "review:" \
1196 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1197 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1198 --trailer "ack: Peff" <complex_message >actual &&
1199 test_cmp expected actual
1202 test_expect_success 'with simple command' '
1203 git config trailer.sign.key "Signed-off-by: " &&
1204 git config trailer.sign.where "after" &&
1205 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1206 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
1207 cat complex_message_body >expected &&
1208 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1213 Signed-off-by: A U Thor <author@example.com>
1215 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1216 <complex_message >actual &&
1217 test_cmp expected actual
1220 test_expect_success 'with command using commiter information' '
1221 git config trailer.sign.ifExists "addIfDifferent" &&
1222 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
1223 cat complex_message_body >expected &&
1224 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1229 Signed-off-by: C O Mitter <committer@example.com>
1231 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1232 <complex_message >actual &&
1233 test_cmp expected actual
1236 test_expect_success 'with command using author information' '
1237 git config trailer.sign.key "Signed-off-by: " &&
1238 git config trailer.sign.where "after" &&
1239 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1240 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1241 cat complex_message_body >expected &&
1242 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1247 Signed-off-by: A U Thor <author@example.com>
1249 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1250 <complex_message >actual &&
1251 test_cmp expected actual
1254 test_expect_success 'setup a commit' '
1255 echo "Content of the first commit." > a.txt &&
1257 git commit -m "Add file a.txt"
1260 test_expect_success 'with command using $ARG' '
1261 git config trailer.fix.ifExists "replace" &&
1262 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1263 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1264 cat complex_message_body >expected &&
1265 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1270 Signed-off-by: A U Thor <author@example.com>
1272 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1273 <complex_message >actual &&
1274 test_cmp expected actual
1277 test_expect_success 'with failing command using $ARG' '
1278 git config trailer.fix.ifExists "replace" &&
1279 git config trailer.fix.command "false \$ARG" &&
1280 cat complex_message_body >expected &&
1281 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1286 Signed-off-by: A U Thor <author@example.com>
1288 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1289 <complex_message >actual &&
1290 test_cmp expected actual
1293 test_expect_success 'with empty tokens' '
1294 git config --unset trailer.fix.command &&
1295 cat >expected <<-EOF &&
1297 Signed-off-by: A U Thor <author@example.com>
1299 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1301 test_cmp expected actual
1304 test_expect_success 'with command but no key' '
1305 git config --unset trailer.sign.key &&
1306 cat >expected <<-EOF &&
1308 sign: A U Thor <author@example.com>
1310 git interpret-trailers >actual <<-EOF &&
1312 test_cmp expected actual
1315 test_expect_success 'with no command and no key' '
1316 git config --unset trailer.review.key &&
1317 cat >expected <<-EOF &&
1320 sign: A U Thor <author@example.com>
1322 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1324 test_cmp expected actual
1327 test_expect_success 'with cut line' '
1328 cat >expected <<-\EOF &&
1332 sign: A U Thor <author@example.com>
1333 # ------------------------ >8 ------------------------
1336 git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
1338 # ------------------------ >8 ------------------------
1341 test_cmp expected actual
1344 test_expect_success 'only trailers' '
1345 git config trailer.sign.command "echo config-value" &&
1346 cat >expected <<-\EOF &&
1347 existing: existing-value
1351 git interpret-trailers \
1352 --trailer added:added-value \
1353 --only-trailers >actual <<-\EOF &&
1358 existing: existing-value
1360 test_cmp expected actual
1363 test_expect_success 'only-trailers omits non-trailer in middle of block' '
1364 git config trailer.sign.command "echo config-value" &&
1365 cat >expected <<-\EOF &&
1366 Signed-off-by: nobody <nobody@nowhere>
1367 Signed-off-by: somebody <somebody@somewhere>
1370 git interpret-trailers --only-trailers >actual <<-\EOF &&
1373 it is important that the trailers below are signed-off-by
1374 so that they meet the "25% trailers Git knows about" heuristic
1376 Signed-off-by: nobody <nobody@nowhere>
1377 this is not a trailer
1378 Signed-off-by: somebody <somebody@somewhere>
1380 test_cmp expected actual
1383 test_expect_success 'only input' '
1384 git config trailer.sign.command "echo config-value" &&
1385 cat >expected <<-\EOF &&
1386 existing: existing-value
1388 git interpret-trailers \
1389 --only-trailers --only-input >actual <<-\EOF &&
1394 existing: existing-value
1396 test_cmp expected actual
1399 test_expect_success 'unfold' '
1400 cat >expected <<-\EOF &&
1401 foo: continued across several lines
1403 # pass through tr to make leading and trailing whitespace more obvious
1416 git interpret-trailers --only-trailers --only-input --unfold >actual &&
1417 test_cmp expected actual
1420 test_expect_success 'handling of --- lines in input' '
1421 echo "real-trailer: just right" >expected &&
1423 git interpret-trailers --parse >actual <<-\EOF &&
1428 not-a-trailer: too soon
1429 ------ this is just a line in the commit message with a bunch of
1430 ------ dashes; it does not have any syntactic meaning.
1432 real-trailer: just right
1434 below the dashed line may be a patch, etc.
1436 not-a-trailer: too late
1439 test_cmp expected actual
1442 test_expect_success 'suppress --- handling' '
1443 echo "real-trailer: just right" >expected &&
1445 git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1448 This commit message has a "---" in it, but because we tell
1449 interpret-trailers not to respect that, it has no effect.
1451 not-a-trailer: too soon
1454 This is still the commit message body.
1456 real-trailer: just right
1459 test_cmp expected actual