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
'with cmd' '
55 test_when_finished "git config --remove-section trailer.bug" &&
56 git config trailer.bug.key "Bug-maker: " &&
57 git config trailer.bug.ifExists "add" &&
58 git config trailer.bug.cmd "echo \"maybe is\"" &&
59 cat >expected2 <<-EOF &&
61 Bug-maker: maybe is him
62 Bug-maker: maybe is me
64 git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
66 test_cmp expected2 actual2
69 test_expect_success
'with cmd and $1' '
70 test_when_finished "git config --remove-section trailer.bug" &&
71 git config trailer.bug.key "Bug-maker: " &&
72 git config trailer.bug.ifExists "add" &&
73 git config trailer.bug.cmd "echo \"\$1\" is" &&
74 cat >expected2 <<-EOF &&
79 git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
81 test_cmp expected2 actual2
84 test_expect_success
'with cmd and $1 with sh -c' '
85 test_when_finished "git config --remove-section trailer.bug" &&
86 git config trailer.bug.key "Bug-maker: " &&
87 git config trailer.bug.ifExists "replace" &&
88 git config trailer.bug.cmd "sh -c \"echo who is \"\$1\"\"" &&
89 cat >expected2 <<-EOF &&
93 git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
95 test_cmp expected2 actual2
98 test_expect_success
'with cmd and $1 with shell script' '
99 test_when_finished "git config --remove-section trailer.bug" &&
100 git config trailer.bug.key "Bug-maker: " &&
101 git config trailer.bug.ifExists "replace" &&
102 git config trailer.bug.cmd "./echoscript" &&
103 cat >expected2 <<-EOF &&
107 cat >echoscript <<-EOF &&
111 chmod +x echoscript &&
112 git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
114 test_cmp expected2 actual2
117 test_expect_success
'without config' '
118 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
124 git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \
125 --trailer "Acked-by: Johan" empty >actual &&
126 test_cmp expected actual
129 test_expect_success
'without config in another order' '
130 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
136 git interpret-trailers --trailer "Acked-by: Johan" --trailer "Reviewed-by" \
137 --trailer "ack = Peff" empty >actual &&
138 test_cmp expected actual
141 test_expect_success
'--trim-empty without config' '
142 cat >expected <<-\EOF &&
147 git interpret-trailers --trim-empty --trailer ack=Peff \
148 --trailer "Reviewed-by" --trailer "Acked-by: Johan" \
149 --trailer "sob:" empty >actual &&
150 test_cmp expected actual
153 test_expect_success
'with config option on the command line' '
154 cat >expected <<-\EOF &&
159 { echo && echo "Acked-by: Johan"; } |
160 git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
161 --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
162 test_cmp expected actual
165 test_expect_success
'with only a title in the message' '
166 cat >expected <<-\EOF &&
172 echo "area: change" |
173 git interpret-trailers --trailer "Reviewed-by: Peff" \
174 --trailer "Acked-by: Johan" >actual &&
175 test_cmp expected actual
178 test_expect_success
'with multiline title in the message' '
179 cat >expected <<-\EOF &&
186 printf "%s\n" "place of" "code: change" |
187 git interpret-trailers --trailer "Reviewed-by: Peff" \
188 --trailer "Acked-by: Johan" >actual &&
189 test_cmp expected actual
192 test_expect_success
'with non-trailer lines mixed with Signed-off-by' '
193 cat >patch <<-\EOF &&
195 this is not a trailer
196 this is not a trailer
197 Signed-off-by: a <a@example.com>
198 this is not a trailer
200 cat >expected <<-\EOF &&
202 this is not a trailer
203 this is not a trailer
204 Signed-off-by: a <a@example.com>
205 this is not a trailer
208 git interpret-trailers --trailer "token: value" patch >actual &&
209 test_cmp expected actual
212 test_expect_success
'with non-trailer lines mixed with cherry picked from' '
213 cat >patch <<-\EOF &&
215 this is not a trailer
216 this is not a trailer
217 (cherry picked from commit x)
218 this is not a trailer
220 cat >expected <<-\EOF &&
222 this is not a trailer
223 this is not a trailer
224 (cherry picked from commit x)
225 this is not a trailer
228 git interpret-trailers --trailer "token: value" patch >actual &&
229 test_cmp expected actual
232 test_expect_success
'with non-trailer lines mixed with a configured trailer' '
233 cat >patch <<-\EOF &&
235 this is not a trailer
236 this is not a trailer
238 this is not a trailer
240 cat >expected <<-\EOF &&
242 this is not a trailer
243 this is not a trailer
245 this is not a trailer
248 test_config trailer.my.key "My-trailer: " &&
249 git interpret-trailers --trailer "token: value" patch >actual &&
250 test_cmp expected actual
253 test_expect_success
'with non-trailer lines mixed with a non-configured trailer' '
254 cat >patch <<-\EOF &&
256 this is not a trailer
257 this is not a trailer
258 I-am-not-configured: x
259 this is not a trailer
261 cat >expected <<-\EOF &&
263 this is not a trailer
264 this is not a trailer
265 I-am-not-configured: x
266 this is not a trailer
270 test_config trailer.my.key "My-trailer: " &&
271 git interpret-trailers --trailer "token: value" patch >actual &&
272 test_cmp expected actual
275 test_expect_success
'with all non-configured trailers' '
276 cat >patch <<-\EOF &&
278 I-am-not-configured: x
279 I-am-also-not-configured: x
281 cat >expected <<-\EOF &&
283 I-am-not-configured: x
284 I-am-also-not-configured: x
287 test_config trailer.my.key "My-trailer: " &&
288 git interpret-trailers --trailer "token: value" patch >actual &&
289 test_cmp expected actual
292 test_expect_success
'with non-trailer lines only' '
293 cat >patch <<-\EOF &&
295 this is not a trailer
297 cat >expected <<-\EOF &&
299 this is not a trailer
303 git interpret-trailers --trailer "token: value" patch >actual &&
304 test_cmp expected actual
307 test_expect_success
'line with leading whitespace is not trailer' '
308 q_to_tab >patch <<-\EOF &&
312 q_to_tab >expected <<-\EOF &&
318 git interpret-trailers --trailer "token: value" patch >actual &&
319 test_cmp expected actual
322 test_expect_success
'multiline field treated as one trailer for 25% check' '
323 q_to_tab >patch <<-\EOF &&
325 Signed-off-by: a <a@example.com>
328 this is not a trailer
329 this is not a trailer
330 this is not a trailer
331 this is not a trailer
332 this is not a trailer
333 this is not a trailer
335 q_to_tab >expected <<-\EOF &&
337 Signed-off-by: a <a@example.com>
340 this is not a trailer
341 this is not a trailer
342 this is not a trailer
343 this is not a trailer
344 this is not a trailer
345 this is not a trailer
348 git interpret-trailers --trailer "name: value" patch >actual &&
349 test_cmp expected actual
352 test_expect_success
'multiline field treated as atomic for placement' '
353 q_to_tab >patch <<-\EOF &&
360 q_to_tab >expected <<-\EOF &&
368 test_config trailer.name.where after &&
369 git interpret-trailers --trailer "name: value" patch >actual &&
370 test_cmp expected actual
373 test_expect_success
'multiline field treated as atomic for replacement' '
374 q_to_tab >patch <<-\EOF &&
381 q_to_tab >expected <<-\EOF &&
387 test_config trailer.name.ifexists replace &&
388 git interpret-trailers --trailer "name: value" patch >actual &&
389 test_cmp expected actual
392 test_expect_success
'multiline field treated as atomic for difference check' '
393 q_to_tab >patch <<-\EOF &&
400 test_config trailer.name.ifexists addIfDifferent &&
402 q_to_tab >trailer <<-\EOF &&
406 q_to_tab >expected <<-\EOF &&
413 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
414 test_cmp expected actual &&
416 q_to_tab >trailer <<-\EOF &&
420 q_to_tab >expected <<-\EOF &&
429 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
430 test_cmp expected actual &&
432 q_to_tab >trailer <<-\EOF &&
433 name: first line *DIFFERENT*
436 q_to_tab >expected <<-\EOF &&
442 name: first line *DIFFERENT*
445 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
446 test_cmp expected actual
449 test_expect_success
'multiline field treated as atomic for neighbor check' '
450 q_to_tab >patch <<-\EOF &&
457 test_config trailer.name.where after &&
458 test_config trailer.name.ifexists addIfDifferentNeighbor &&
460 q_to_tab >trailer <<-\EOF &&
464 q_to_tab >expected <<-\EOF &&
471 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
472 test_cmp expected actual &&
474 q_to_tab >trailer <<-\EOF &&
478 q_to_tab >expected <<-\EOF &&
487 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
488 test_cmp expected actual
491 test_expect_success
'with config setup' '
492 git config trailer.ack.key "Acked-by: " &&
493 cat >expected <<-\EOF &&
497 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
498 test_cmp expected actual &&
499 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
500 test_cmp expected actual &&
501 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
502 test_cmp expected actual
505 test_expect_success
'with config setup and ":=" as separators' '
506 git config trailer.separators ":=" &&
507 git config trailer.ack.key "Acked-by= " &&
508 cat >expected <<-\EOF &&
512 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
513 test_cmp expected actual &&
514 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
515 test_cmp expected actual &&
516 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
517 test_cmp expected actual
520 test_expect_success
'with config setup and "%" as separators' '
521 git config trailer.separators "%" &&
522 cat >expected <<-\EOF &&
528 git interpret-trailers --trim-empty --trailer "bug = 42" \
529 --trailer count%10 --trailer "test: stuff" \
530 --trailer "bug % 422" empty >actual &&
531 test_cmp expected actual
534 test_expect_success
'with "%" as separators and a message with trailers' '
535 cat >special_message <<-\EOF &&
542 cat >expected <<-\EOF &&
550 git interpret-trailers --trailer count%100 \
551 special_message >actual &&
552 test_cmp expected actual
555 test_expect_success
'with config setup and ":=#" as separators' '
556 git config trailer.separators ":=#" &&
557 git config trailer.bug.key "Bug #" &&
558 cat >expected <<-\EOF &&
562 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
563 test_cmp expected actual
566 test_expect_success
'with commit basic message' '
567 cat basic_message >expected &&
569 git interpret-trailers <basic_message >actual &&
570 test_cmp expected actual
573 test_expect_success
'with basic patch' '
574 cat basic_message >input &&
575 cat basic_patch >>input &&
576 cat basic_message >expected &&
578 cat basic_patch >>expected &&
579 git interpret-trailers <input >actual &&
580 test_cmp expected actual
583 test_expect_success
'with commit complex message as argument' '
584 cat complex_message_body complex_message_trailers >complex_message &&
585 cat complex_message_body >expected &&
586 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
592 git interpret-trailers complex_message >actual &&
593 test_cmp expected actual
596 test_expect_success
'with 2 files arguments' '
597 cat basic_message >>expected &&
599 cat basic_patch >>expected &&
600 git interpret-trailers complex_message input >actual &&
601 test_cmp expected actual
604 # Cover multiple comment characters with the same test input.
609 # This is the default, so let's explicitly _not_
610 # set any config to make sure it behaves as we expect.
613 config
="-c core.commentChar=$char"
617 test_expect_success
"with message that has comments ($char)" '
618 cat basic_message >message_with_comments &&
620 -e "s/#/$char/g" >>message_with_comments <<-EOF &&
625 # yet another comment
631 cat basic_patch >>message_with_comments &&
632 cat basic_message >expected &&
633 sed -e "s/#/$char/g" >>expected <<-\EOF &&
641 cat basic_patch >>expected &&
642 git $config interpret-trailers \
643 --trim-empty --trailer "Cc: Peff" \
644 message_with_comments >actual &&
645 test_cmp expected actual
649 test_expect_success
'with message that has an old style conflict block' '
650 cat basic_message >message_with_comments &&
651 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
656 # yet another comment
664 cat basic_message >expected &&
665 cat >>expected <<-\EOF &&
675 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
676 test_cmp expected actual
679 test_expect_success
'with commit complex message and trailer args' '
680 cat complex_message_body >expected &&
681 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
689 git interpret-trailers --trailer "ack: Peff" \
690 --trailer "bug: 42" <complex_message >actual &&
691 test_cmp expected actual
694 test_expect_success
'with complex patch, args and --trim-empty' '
695 cat complex_message >complex_patch &&
696 cat basic_patch >>complex_patch &&
697 cat complex_message_body >expected &&
698 cat >>expected <<-\EOF &&
702 cat basic_patch >>expected &&
703 git interpret-trailers --trim-empty --trailer "ack: Peff" \
704 --trailer "bug: 42" <complex_patch >actual &&
705 test_cmp expected actual
708 test_expect_success
'in-place editing with basic patch' '
709 cat basic_message >message &&
710 cat basic_patch >>message &&
711 cat basic_message >expected &&
713 cat basic_patch >>expected &&
714 git interpret-trailers --in-place message &&
715 test_cmp expected message
718 test_expect_success
'in-place editing with additional trailer' '
719 cat basic_message >message &&
720 cat basic_patch >>message &&
721 cat basic_message >expected &&
723 cat >>expected <<-\EOF &&
726 cat basic_patch >>expected &&
727 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
728 test_cmp expected message
731 test_expect_success
'in-place editing on stdin disallowed' '
732 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
735 test_expect_success
'in-place editing on non-existing file' '
736 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
737 test_path_is_missing nonexisting
740 test_expect_success POSIXPERM
,SANITY
"in-place editing doesn't clobber original file on error" '
741 cat basic_message >message &&
743 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
745 test_cmp message basic_message
748 test_expect_success
'using "where = before"' '
749 git config trailer.bug.where "before" &&
750 cat complex_message_body >expected &&
751 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
759 git interpret-trailers --trailer "ack: Peff" \
760 --trailer "bug: 42" complex_message >actual &&
761 test_cmp expected actual
764 test_expect_success
'overriding configuration with "--where after"' '
765 git config trailer.ack.where "before" &&
766 cat complex_message_body >expected &&
767 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
774 git interpret-trailers --where after --trailer "ack: Peff" \
775 complex_message >actual &&
776 test_cmp expected actual
779 test_expect_success
'using "where = before" with "--no-where"' '
780 cat complex_message_body >expected &&
781 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
789 git interpret-trailers --where after --no-where --trailer "ack: Peff" \
790 --trailer "bug: 42" complex_message >actual &&
791 test_cmp expected actual
794 test_expect_success
'using "where = after"' '
795 git config trailer.ack.where "after" &&
796 cat complex_message_body >expected &&
797 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
805 git interpret-trailers --trailer "ack: Peff" \
806 --trailer "bug: 42" complex_message >actual &&
807 test_cmp expected actual
810 test_expect_success
'using "where = end"' '
811 git config trailer.review.key "Reviewed-by" &&
812 git config trailer.review.where "end" &&
813 cat complex_message_body >expected &&
814 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
821 Reviewed-by: Johannes
823 git interpret-trailers --trailer "ack: Peff" \
824 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
825 complex_message >actual &&
826 test_cmp expected actual
829 test_expect_success
'using "where = start"' '
830 git config trailer.review.key "Reviewed-by" &&
831 git config trailer.review.where "start" &&
832 cat complex_message_body >expected &&
833 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
834 Reviewed-by: Johannes
842 git interpret-trailers --trailer "ack: Peff" \
843 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
844 complex_message >actual &&
845 test_cmp expected actual
848 test_expect_success
'using "where = before" for a token in the middle of the message' '
849 git config trailer.review.key "Reviewed-by:" &&
850 git config trailer.review.where "before" &&
851 cat complex_message_body >expected &&
852 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
861 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
862 --trailer "review: Johan" <complex_message >actual &&
863 test_cmp expected actual
866 test_expect_success
'using "where = before" and --trim-empty' '
867 cat complex_message_body >expected &&
868 cat >>expected <<-\EOF &&
874 git interpret-trailers --trim-empty --trailer "ack: Peff" \
875 --trailer "bug: 42" --trailer "review: Johan" \
876 --trailer "Bug: 46" <complex_message >actual &&
877 test_cmp expected actual
880 test_expect_success
'the default is "ifExists = addIfDifferentNeighbor"' '
881 cat complex_message_body >expected &&
882 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
892 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
893 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
894 --trailer "ack: Peff" <complex_message >actual &&
895 test_cmp expected actual
898 test_expect_success
'default "ifExists" is now "addIfDifferent"' '
899 git config trailer.ifexists "addIfDifferent" &&
900 cat complex_message_body >expected &&
901 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
910 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
911 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
912 --trailer "ack: Peff" <complex_message >actual &&
913 test_cmp expected actual
916 test_expect_success
'using "ifExists = addIfDifferent" with "where = end"' '
917 git config trailer.ack.ifExists "addIfDifferent" &&
918 git config trailer.ack.where "end" &&
919 cat complex_message_body >expected &&
920 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
928 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
929 --trailer "bug: 42" --trailer "ack: Peff" \
930 <complex_message >actual &&
931 test_cmp expected actual
934 test_expect_success
'using "ifExists = addIfDifferent" with "where = before"' '
935 git config trailer.ack.ifExists "addIfDifferent" &&
936 git config trailer.ack.where "before" &&
937 cat complex_message_body >expected &&
938 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
946 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
947 --trailer "bug: 42" --trailer "ack: Peff" \
948 <complex_message >actual &&
949 test_cmp expected actual
952 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
953 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
954 git config trailer.ack.where "end" &&
955 cat complex_message_body >expected &&
956 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
968 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
969 --trailer "ack: Junio" --trailer "bug: 42" \
970 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
971 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
972 test_cmp expected actual
975 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
976 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
977 git config trailer.ack.where "after" &&
978 cat complex_message_body >expected &&
979 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
990 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
991 --trailer "ack: Junio" --trailer "bug: 42" \
992 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
993 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
994 test_cmp expected actual
997 test_expect_success
'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
998 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
999 cat complex_message_body >expected &&
1000 cat >>expected <<-\EOF &&
1006 git interpret-trailers --trim-empty --trailer "ack: Peff" \
1007 --trailer "Acked-by= Peff" --trailer "review:" \
1008 --trailer "ack: Junio" --trailer "bug: 42" \
1009 --trailer "ack: Peff" <complex_message >actual &&
1010 test_cmp expected actual
1013 test_expect_success
'using "ifExists = add" with "where = end"' '
1014 git config trailer.ack.ifExists "add" &&
1015 git config trailer.ack.where "end" &&
1016 cat complex_message_body >expected &&
1017 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1030 git interpret-trailers --trailer "ack: Peff" \
1031 --trailer "Acked-by= Peff" --trailer "review:" \
1032 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1033 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1034 --trailer "ack: Peff" <complex_message >actual &&
1035 test_cmp expected actual
1038 test_expect_success
'using "ifExists = add" with "where = after"' '
1039 git config trailer.ack.ifExists "add" &&
1040 git config trailer.ack.where "after" &&
1041 cat complex_message_body >expected &&
1042 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1053 git interpret-trailers --trailer "ack: Peff" \
1054 --trailer "Acked-by= Peff" --trailer "review:" \
1055 --trailer "ack: Junio" --trailer "bug: 42" \
1056 --trailer "ack: Peff" <complex_message >actual &&
1057 test_cmp expected actual
1060 test_expect_success
'overriding configuration with "--if-exists replace"' '
1061 git config trailer.fix.key "Fixes: " &&
1062 git config trailer.fix.ifExists "add" &&
1063 cat complex_message_body >expected &&
1064 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1071 git interpret-trailers --if-exists replace --trailer "review:" \
1072 --trailer "fix=53" --trailer "fix=22" --trailer "bug: 42" \
1073 <complex_message >actual &&
1074 test_cmp expected actual
1077 test_expect_success
'using "ifExists = replace"' '
1078 git config trailer.fix.key "Fixes: " &&
1079 git config trailer.fix.ifExists "replace" &&
1080 cat complex_message_body >expected &&
1081 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1090 git interpret-trailers --trailer "review:" \
1091 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1092 --trailer "bug: 42" --trailer "ack: Peff" \
1093 <complex_message >actual &&
1094 test_cmp expected actual
1097 test_expect_success
'using "ifExists = replace" with "where = after"' '
1098 git config trailer.fix.where "after" &&
1099 cat complex_message_body >expected &&
1100 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1109 git interpret-trailers --trailer "review:" \
1110 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1111 --trailer "bug: 42" --trailer "ack: Peff" \
1112 <complex_message >actual &&
1113 test_cmp expected actual
1116 test_expect_success
'using "ifExists = doNothing"' '
1117 git config trailer.fix.ifExists "doNothing" &&
1118 cat complex_message_body >expected &&
1119 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1128 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1129 --trailer "ack: Junio" --trailer "fix=22" \
1130 --trailer "bug: 42" --trailer "ack: Peff" \
1131 <complex_message >actual &&
1132 test_cmp expected actual
1135 test_expect_success
'the default is "ifMissing = add"' '
1136 git config trailer.cc.key "Cc: " &&
1137 git config trailer.cc.where "before" &&
1138 cat complex_message_body >expected &&
1139 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1149 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1150 --trailer "cc=Linus" --trailer "ack: Junio" \
1151 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1152 <complex_message >actual &&
1153 test_cmp expected actual
1156 test_expect_success
'overriding configuration with "--if-missing doNothing"' '
1157 git config trailer.ifmissing "add" &&
1158 cat complex_message_body >expected &&
1159 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1167 git interpret-trailers --if-missing doNothing \
1168 --trailer "review:" --trailer "fix=53" \
1169 --trailer "cc=Linus" --trailer "ack: Junio" \
1170 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1171 <complex_message >actual &&
1172 test_cmp expected actual
1175 test_expect_success
'when default "ifMissing" is "doNothing"' '
1176 git config trailer.ifmissing "doNothing" &&
1177 cat complex_message_body >expected &&
1178 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1186 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1187 --trailer "cc=Linus" --trailer "ack: Junio" \
1188 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1189 <complex_message >actual &&
1190 test_cmp expected actual &&
1191 git config trailer.ifmissing "add"
1194 test_expect_success
'using "ifMissing = add" with "where = end"' '
1195 git config trailer.cc.key "Cc: " &&
1196 git config trailer.cc.where "end" &&
1197 git config trailer.cc.ifMissing "add" &&
1198 cat complex_message_body >expected &&
1199 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1209 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1210 --trailer "ack: Junio" --trailer "fix=22" \
1211 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1212 <complex_message >actual &&
1213 test_cmp expected actual
1216 test_expect_success
'using "ifMissing = add" with "where = before"' '
1217 git config trailer.cc.key "Cc: " &&
1218 git config trailer.cc.where "before" &&
1219 git config trailer.cc.ifMissing "add" &&
1220 cat complex_message_body >expected &&
1221 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1231 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1232 --trailer "ack: Junio" --trailer "fix=22" \
1233 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1234 <complex_message >actual &&
1235 test_cmp expected actual
1238 test_expect_success
'using "ifMissing = doNothing"' '
1239 git config trailer.cc.ifMissing "doNothing" &&
1240 cat complex_message_body >expected &&
1241 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1250 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1251 --trailer "cc=Linus" --trailer "ack: Junio" \
1252 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1253 <complex_message >actual &&
1254 test_cmp expected actual
1257 test_expect_success
'default "where" is now "after"' '
1258 git config trailer.where "after" &&
1259 git config --unset trailer.ack.where &&
1260 cat complex_message_body >expected &&
1261 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1274 git interpret-trailers --trailer "ack: Peff" \
1275 --trailer "Acked-by= Peff" --trailer "review:" \
1276 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1277 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1278 --trailer "ack: Peff" <complex_message >actual &&
1279 test_cmp expected actual
1282 test_expect_success
'with simple command' '
1283 git config trailer.sign.key "Signed-off-by: " &&
1284 git config trailer.sign.where "after" &&
1285 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1286 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
1287 cat complex_message_body >expected &&
1288 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1293 Signed-off-by: A U Thor <author@example.com>
1295 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1296 <complex_message >actual &&
1297 test_cmp expected actual
1300 test_expect_success
'with command using committer information' '
1301 git config trailer.sign.ifExists "addIfDifferent" &&
1302 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
1303 cat complex_message_body >expected &&
1304 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1309 Signed-off-by: C O Mitter <committer@example.com>
1311 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1312 <complex_message >actual &&
1313 test_cmp expected actual
1316 test_expect_success
'with command using author information' '
1317 git config trailer.sign.key "Signed-off-by: " &&
1318 git config trailer.sign.where "after" &&
1319 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1320 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1321 cat complex_message_body >expected &&
1322 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1327 Signed-off-by: A U Thor <author@example.com>
1329 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1330 <complex_message >actual &&
1331 test_cmp expected actual
1334 test_expect_success
'setup a commit' '
1335 echo "Content of the first commit." > a.txt &&
1337 git commit -m "Add file a.txt"
1340 test_expect_success
'cmd takes precedence over command' '
1341 test_when_finished "git config --unset trailer.fix.cmd" &&
1342 git config trailer.fix.ifExists "replace" &&
1343 git config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \
1344 --abbrev-commit --abbrev=14 \"\$1\" || true" &&
1345 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \
1346 --abbrev-commit --abbrev=14 \$ARG" &&
1347 FIXED=$(git log -1 --oneline --format="%h (%aN)" --abbrev-commit --abbrev=14 HEAD) &&
1348 cat complex_message_body >expected2 &&
1349 sed -e "s/ Z\$/ /" >>expected2 <<-EOF &&
1354 Signed-off-by: A U Thor <author@example.com>
1356 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1357 <complex_message >actual2 &&
1358 test_cmp expected2 actual2
1361 test_expect_success
'with command using $ARG' '
1362 git config trailer.fix.ifExists "replace" &&
1363 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1364 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1365 cat complex_message_body >expected &&
1366 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1371 Signed-off-by: A U Thor <author@example.com>
1373 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1374 <complex_message >actual &&
1375 test_cmp expected actual
1378 test_expect_success
'with failing command using $ARG' '
1379 git config trailer.fix.ifExists "replace" &&
1380 git config trailer.fix.command "false \$ARG" &&
1381 cat complex_message_body >expected &&
1382 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1387 Signed-off-by: A U Thor <author@example.com>
1389 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1390 <complex_message >actual &&
1391 test_cmp expected actual
1394 test_expect_success
'with empty tokens' '
1395 git config --unset trailer.fix.command &&
1396 cat >expected <<-EOF &&
1398 Signed-off-by: A U Thor <author@example.com>
1400 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1402 test_cmp expected actual
1405 test_expect_success
'with command but no key' '
1406 git config --unset trailer.sign.key &&
1407 cat >expected <<-EOF &&
1409 sign: A U Thor <author@example.com>
1411 git interpret-trailers >actual <<-EOF &&
1413 test_cmp expected actual
1416 test_expect_success
'with no command and no key' '
1417 git config --unset trailer.review.key &&
1418 cat >expected <<-EOF &&
1421 sign: A U Thor <author@example.com>
1423 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1425 test_cmp expected actual
1428 test_expect_success
'with cut line' '
1429 cat >expected <<-\EOF &&
1433 sign: A U Thor <author@example.com>
1434 # ------------------------ >8 ------------------------
1437 git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
1439 # ------------------------ >8 ------------------------
1442 test_cmp expected actual
1445 test_expect_success
'only trailers' '
1446 git config trailer.sign.command "echo config-value" &&
1447 cat >expected <<-\EOF &&
1448 existing: existing-value
1452 git interpret-trailers \
1453 --trailer added:added-value \
1454 --only-trailers >actual <<-\EOF &&
1459 existing: existing-value
1461 test_cmp expected actual
1464 test_expect_success
'only-trailers omits non-trailer in middle of block' '
1465 git config trailer.sign.command "echo config-value" &&
1466 cat >expected <<-\EOF &&
1467 Signed-off-by: nobody <nobody@nowhere>
1468 Signed-off-by: somebody <somebody@somewhere>
1471 git interpret-trailers --only-trailers >actual <<-\EOF &&
1474 it is important that the trailers below are signed-off-by
1475 so that they meet the "25% trailers Git knows about" heuristic
1477 Signed-off-by: nobody <nobody@nowhere>
1478 this is not a trailer
1479 Signed-off-by: somebody <somebody@somewhere>
1481 test_cmp expected actual
1484 test_expect_success
'only input' '
1485 git config trailer.sign.command "echo config-value" &&
1486 cat >expected <<-\EOF &&
1487 existing: existing-value
1489 git interpret-trailers \
1490 --only-trailers --only-input >actual <<-\EOF &&
1495 existing: existing-value
1497 test_cmp expected actual
1500 test_expect_success
'unfold' '
1501 cat >expected <<-\EOF &&
1502 foo: continued across several lines
1504 # pass through tr to make leading and trailing whitespace more obvious
1517 git interpret-trailers --only-trailers --only-input --unfold >actual &&
1518 test_cmp expected actual
1521 test_expect_success
'handling of --- lines in input' '
1522 echo "real-trailer: just right" >expected &&
1524 git interpret-trailers --parse >actual <<-\EOF &&
1529 not-a-trailer: too soon
1530 ------ this is just a line in the commit message with a bunch of
1531 ------ dashes; it does not have any syntactic meaning.
1533 real-trailer: just right
1535 below the dashed line may be a patch, etc.
1537 not-a-trailer: too late
1540 test_cmp expected actual
1543 test_expect_success
'suppress --- handling' '
1544 echo "real-trailer: just right" >expected &&
1546 git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1549 This commit message has a "---" in it, but because we tell
1550 interpret-trailers not to respect that, it has no effect.
1552 not-a-trailer: too soon
1555 This is still the commit message body.
1557 real-trailer: just right
1560 test_cmp expected actual
1563 test_expect_success
'suppressing --- does not disable cut-line handling' '
1564 echo "real-trailer: before the cut" >expected &&
1566 git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1569 This input has a cut-line in it; we should stop parsing when we see it
1570 and consider only trailers before that line.
1572 real-trailer: before the cut
1574 # ------------------------ >8 ------------------------
1575 # Nothing below this line counts as part of the commit message.
1576 not-a-trailer: too late
1579 test_cmp expected actual