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
'using "where = after"' '
685 git config trailer.ack.where "after" &&
686 cat complex_message_body >expected &&
687 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
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 &&
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
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
1254 sign: A U Thor <author@example.com>
1256 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1258 test_cmp expected actual
1261 test_expect_success
'with cut line' '
1262 cat >expected <<-\EOF &&
1266 sign: A U Thor <author@example.com>
1267 # ------------------------ >8 ------------------------
1270 git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
1272 # ------------------------ >8 ------------------------
1275 test_cmp expected actual