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 test_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 test_config trailer.separators ":=" &&
507 test_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 test_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 test_config trailer.separators "%" &&
536 cat >special_message <<-\EOF &&
543 cat >expected <<-\EOF &&
551 git interpret-trailers --trailer count%100 \
552 special_message >actual &&
553 test_cmp expected actual
556 test_expect_success
'with config setup and ":=#" as separators' '
557 test_config trailer.separators ":=#" &&
558 test_config trailer.bug.key "Bug #" &&
559 cat >expected <<-\EOF &&
563 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
564 test_cmp expected actual
567 test_expect_success
'with commit basic message' '
568 cat basic_message >expected &&
570 git interpret-trailers <basic_message >actual &&
571 test_cmp expected actual
574 test_expect_success
'with basic patch' '
575 cat basic_message >input &&
576 cat basic_patch >>input &&
577 cat basic_message >expected &&
579 cat basic_patch >>expected &&
580 git interpret-trailers <input >actual &&
581 test_cmp expected actual
584 test_expect_success
'with commit complex message as argument' '
585 test_config trailer.separators ":=" &&
586 test_config trailer.ack.key "Acked-by= " &&
587 cat complex_message_body complex_message_trailers >complex_message &&
588 cat complex_message_body >expected &&
589 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
595 git interpret-trailers complex_message >actual &&
596 test_cmp expected actual
599 test_expect_success
'with 2 files arguments' '
600 test_config trailer.separators ":=" &&
601 test_config trailer.ack.key "Acked-by= " &&
602 cat basic_message >>expected &&
604 cat basic_patch >>expected &&
605 git interpret-trailers complex_message input >actual &&
606 test_cmp expected actual
609 # Cover multiple comment characters with the same test input.
614 # This is the default, so let's explicitly _not_
615 # set any config to make sure it behaves as we expect.
618 config
="-c core.commentChar=$char"
622 test_expect_success
"with message that has comments ($char)" '
623 cat basic_message >message_with_comments &&
625 -e "s/#/$char/g" >>message_with_comments <<-EOF &&
630 # yet another comment
636 cat basic_patch >>message_with_comments &&
637 cat basic_message >expected &&
638 sed -e "s/#/$char/g" >>expected <<-\EOF &&
646 cat basic_patch >>expected &&
647 git $config interpret-trailers \
648 --trim-empty --trailer "Cc: Peff" \
649 message_with_comments >actual &&
650 test_cmp expected actual
654 test_expect_success
'with message that has an old style conflict block' '
655 cat basic_message >message_with_comments &&
656 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
661 # yet another comment
669 cat basic_message >expected &&
670 cat >>expected <<-\EOF &&
680 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
681 test_cmp expected actual
684 test_expect_success
'with commit complex message and trailer args' '
685 test_config trailer.separators ":=#" &&
686 test_config trailer.ack.key "Acked-by= " &&
687 test_config trailer.bug.key "Bug #" &&
688 cat complex_message_body >expected &&
689 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
697 git interpret-trailers --trailer "ack: Peff" \
698 --trailer "bug: 42" <complex_message >actual &&
699 test_cmp expected actual
702 test_expect_success
'with complex patch, args and --trim-empty' '
703 test_config trailer.separators ":=#" &&
704 test_config trailer.ack.key "Acked-by= " &&
705 test_config trailer.bug.key "Bug #" &&
706 cat complex_message >complex_patch &&
707 cat basic_patch >>complex_patch &&
708 cat complex_message_body >expected &&
709 cat >>expected <<-\EOF &&
713 cat basic_patch >>expected &&
714 git interpret-trailers --trim-empty --trailer "ack: Peff" \
715 --trailer "bug: 42" <complex_patch >actual &&
716 test_cmp expected actual
719 test_expect_success
'in-place editing with basic patch' '
720 cat basic_message >message &&
721 cat basic_patch >>message &&
722 cat basic_message >expected &&
724 cat basic_patch >>expected &&
725 git interpret-trailers --in-place message &&
726 test_cmp expected message
729 test_expect_success
'in-place editing with additional trailer' '
730 cat basic_message >message &&
731 cat basic_patch >>message &&
732 cat basic_message >expected &&
734 cat >>expected <<-\EOF &&
737 cat basic_patch >>expected &&
738 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
739 test_cmp expected message
742 test_expect_success
'in-place editing on stdin disallowed' '
743 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
746 test_expect_success
'in-place editing on non-existing file' '
747 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
748 test_path_is_missing nonexisting
751 test_expect_success POSIXPERM
,SANITY
"in-place editing doesn't clobber original file on error" '
752 cat basic_message >message &&
754 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
756 test_cmp message basic_message
759 test_expect_success
'using "where = before"' '
760 test_config trailer.separators ":=#" &&
761 test_config trailer.ack.key "Acked-by= " &&
762 test_config trailer.bug.key "Bug #" &&
763 test_config trailer.bug.where "before" &&
764 cat complex_message_body >expected &&
765 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
773 git interpret-trailers --trailer "ack: Peff" \
774 --trailer "bug: 42" complex_message >actual &&
775 test_cmp expected actual
778 test_expect_success
'overriding configuration with "--where after"' '
779 test_config trailer.separators ":=" &&
780 test_config trailer.ack.key "Acked-by= " &&
781 test_config trailer.ack.where "before" &&
782 cat complex_message_body >expected &&
783 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
790 git interpret-trailers --where after --trailer "ack: Peff" \
791 complex_message >actual &&
792 test_cmp expected actual
795 test_expect_success
'using "--where after" with "--no-where"' '
796 test_config trailer.ack.key "Acked-by= " &&
797 test_config trailer.ack.where "before" &&
798 test_config trailer.bug.key "Bug #" &&
799 test_config trailer.bug.where "before" &&
800 test_config trailer.separators ":=#" &&
801 cat complex_message_body >expected &&
802 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
810 git interpret-trailers --where after --no-where --trailer "ack: Peff" \
811 --trailer "bug: 42" complex_message >actual &&
812 test_cmp expected actual
815 # Check whether using "--no-where" clears out only the "--where after", such
816 # that we still use the configuration in trailer.where (which is different from
817 # the hardcoded default (in WHERE_END) assuming the absence of .gitconfig).
818 # Here, the "start" setting of trailer.where is respected, so the new "Acked-by"
819 # and "Bug" trailers are placed at the beginning, and not at the end which is
820 # the harcoded default.
821 test_expect_success
'using "--where after" with "--no-where" defaults to configuration' '
822 test_config trailer.ack.key "Acked-by= " &&
823 test_config trailer.bug.key "Bug #" &&
824 test_config trailer.separators ":=#" &&
825 test_config trailer.where "start" &&
826 cat complex_message_body >expected &&
827 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
835 git interpret-trailers --where after --no-where --trailer "ack: Peff" \
836 --trailer "bug: 42" complex_message >actual &&
837 test_cmp expected actual
840 # The "--where after" will only get respected for the trailer that came
841 # immediately after it. For the next trailer (Bug #42), we default to using the
842 # hardcoded WHERE_END because we don't have any "trailer.where" or
843 # "trailer.bug.where" configured.
844 test_expect_success
'using "--no-where" defaults to harcoded default if nothing configured' '
845 test_config trailer.ack.key "Acked-by= " &&
846 test_config trailer.bug.key "Bug #" &&
847 test_config trailer.separators ":=#" &&
848 cat complex_message_body >expected &&
849 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
857 git interpret-trailers --where after --trailer "ack: Peff" --no-where \
858 --trailer "bug: 42" complex_message >actual &&
859 test_cmp expected actual
862 test_expect_success
'using "where = after"' '
863 test_config trailer.ack.key "Acked-by= " &&
864 test_config trailer.ack.where "after" &&
865 test_config trailer.bug.key "Bug #" &&
866 test_config trailer.bug.where "before" &&
867 test_config trailer.separators ":=#" &&
868 cat complex_message_body >expected &&
869 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
877 git interpret-trailers --trailer "ack: Peff" \
878 --trailer "bug: 42" complex_message >actual &&
879 test_cmp expected actual
882 test_expect_success
'using "where = end"' '
883 test_config trailer.review.key "Reviewed-by" &&
884 test_config trailer.review.where "end" &&
885 test_config trailer.ack.key "Acked-by= " &&
886 test_config trailer.ack.where "after" &&
887 test_config trailer.separators ":=" &&
888 cat complex_message_body >expected &&
889 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
896 Reviewed-by: Johannes
898 git interpret-trailers --trailer "ack: Peff" \
899 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
900 complex_message >actual &&
901 test_cmp expected actual
904 test_expect_success
'using "where = start"' '
905 test_config trailer.review.key "Reviewed-by" &&
906 test_config trailer.review.where "start" &&
907 test_config trailer.ack.key "Acked-by= " &&
908 test_config trailer.ack.where "after" &&
909 test_config trailer.separators ":=" &&
910 cat complex_message_body >expected &&
911 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
912 Reviewed-by: Johannes
920 git interpret-trailers --trailer "ack: Peff" \
921 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
922 complex_message >actual &&
923 test_cmp expected actual
926 test_expect_success
'using "where = before" for a token in the middle of the message' '
927 test_config trailer.review.key "Reviewed-by:" &&
928 test_config trailer.review.where "before" &&
929 test_config trailer.ack.key "Acked-by= " &&
930 test_config trailer.ack.where "after" &&
931 test_config trailer.bug.key "Bug #" &&
932 test_config trailer.bug.where "before" &&
933 test_config trailer.separators ":=#" &&
934 cat complex_message_body >expected &&
935 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
944 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
945 --trailer "review: Johan" <complex_message >actual &&
946 test_cmp expected actual
949 test_expect_success
'using "where = before" and --trim-empty' '
950 test_config trailer.ack.key "Acked-by= " &&
951 test_config trailer.ack.where "after" &&
952 test_config trailer.bug.key "Bug #" &&
953 test_config trailer.bug.where "before" &&
954 test_config trailer.review.key "Reviewed-by:" &&
955 test_config trailer.separators ":=#" &&
956 cat complex_message_body >expected &&
957 cat >>expected <<-\EOF &&
963 git interpret-trailers --trim-empty --trailer "ack: Peff" \
964 --trailer "bug: 42" --trailer "review: Johan" \
965 --trailer "Bug: 46" <complex_message >actual &&
966 test_cmp expected actual
969 test_expect_success
'the default is "ifExists = addIfDifferentNeighbor"' '
970 test_config trailer.ack.key "Acked-by= " &&
971 test_config trailer.ack.where "after" &&
972 test_config trailer.bug.key "Bug #" &&
973 test_config trailer.bug.where "before" &&
974 test_config trailer.review.key "Reviewed-by:" &&
975 test_config trailer.review.where "before" &&
976 test_config trailer.separators ":=#" &&
977 cat complex_message_body >expected &&
978 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
988 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
989 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
990 --trailer "ack: Peff" <complex_message >actual &&
991 test_cmp expected actual
994 test_expect_success
'default "ifExists" is now "addIfDifferent"' '
995 test_config trailer.ifexists "addIfDifferent" &&
996 test_config trailer.ack.key "Acked-by= " &&
997 test_config trailer.ack.where "after" &&
998 test_config trailer.bug.key "Bug #" &&
999 test_config trailer.bug.where "before" &&
1000 test_config trailer.review.key "Reviewed-by:" &&
1001 test_config trailer.separators ":=#" &&
1002 cat complex_message_body >expected &&
1003 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1012 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1013 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
1014 --trailer "ack: Peff" <complex_message >actual &&
1015 test_cmp expected actual
1018 test_expect_success
'using "ifExists = addIfDifferent" with "where = end"' '
1019 test_config trailer.ack.ifExists "addIfDifferent" &&
1020 test_config trailer.ack.key "Acked-by= " &&
1021 test_config trailer.ack.where "end" &&
1022 test_config trailer.bug.key "Bug #" &&
1023 test_config trailer.bug.where "before" &&
1024 test_config trailer.review.key "Reviewed-by:" &&
1025 test_config trailer.ifexists "addIfDifferent" &&
1026 test_config trailer.separators ":=#" &&
1027 cat complex_message_body >expected &&
1028 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1036 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1037 --trailer "bug: 42" --trailer "ack: Peff" \
1038 <complex_message >actual &&
1039 test_cmp expected actual
1042 test_expect_success
'using "ifExists = addIfDifferent" with "where = before"' '
1043 test_config trailer.ack.ifExists "addIfDifferent" &&
1044 test_config trailer.ack.key "Acked-by= " &&
1045 test_config trailer.ack.where "before" &&
1046 test_config trailer.bug.key "Bug #" &&
1047 test_config trailer.bug.where "before" &&
1048 test_config trailer.review.key "Reviewed-by:" &&
1049 test_config trailer.ifexists "addIfDifferent" &&
1050 test_config trailer.separators ":=#" &&
1051 cat complex_message_body >expected &&
1052 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1060 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1061 --trailer "bug: 42" --trailer "ack: Peff" \
1062 <complex_message >actual &&
1063 test_cmp expected actual
1066 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
1067 test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1068 test_config trailer.ack.key "Acked-by= " &&
1069 test_config trailer.ack.where "end" &&
1070 test_config trailer.bug.key "Bug #" &&
1071 test_config trailer.bug.where "before" &&
1072 test_config trailer.review.key "Reviewed-by:" &&
1073 test_config trailer.ifexists "addIfDifferent" &&
1074 test_config trailer.separators ":=#" &&
1075 cat complex_message_body >expected &&
1076 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1088 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1089 --trailer "ack: Junio" --trailer "bug: 42" \
1090 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1091 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
1092 test_cmp expected actual
1095 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
1096 test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1097 test_config trailer.ack.key "Acked-by= " &&
1098 test_config trailer.ack.where "after" &&
1099 test_config trailer.bug.key "Bug #" &&
1100 test_config trailer.bug.where "before" &&
1101 test_config trailer.review.key "Reviewed-by:" &&
1102 test_config trailer.ifexists "addIfDifferent" &&
1103 test_config trailer.separators ":=#" &&
1104 cat complex_message_body >expected &&
1105 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1116 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1117 --trailer "ack: Junio" --trailer "bug: 42" \
1118 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1119 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
1120 test_cmp expected actual
1123 test_expect_success
'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
1124 test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1125 test_config trailer.ack.key "Acked-by= " &&
1126 test_config trailer.bug.key "Bug #" &&
1127 test_config trailer.bug.where "before" &&
1128 test_config trailer.separators ":=#" &&
1129 cat complex_message_body >expected &&
1130 cat >>expected <<-\EOF &&
1136 git interpret-trailers --trim-empty --trailer "ack: Peff" \
1137 --trailer "Acked-by= Peff" --trailer "review:" \
1138 --trailer "ack: Junio" --trailer "bug: 42" \
1139 --trailer "ack: Peff" <complex_message >actual &&
1140 test_cmp expected actual
1143 test_expect_success
'using "ifExists = add" with "where = end"' '
1144 test_config trailer.ack.ifExists "add" &&
1145 test_config trailer.ack.key "Acked-by= " &&
1146 test_config trailer.ack.where "end" &&
1147 test_config trailer.bug.key "Bug #" &&
1148 test_config trailer.bug.where "before" &&
1149 test_config trailer.review.key "Reviewed-by:" &&
1150 test_config trailer.ifexists "addIfDifferent" &&
1151 test_config trailer.separators ":=#" &&
1152 cat complex_message_body >expected &&
1153 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1166 git interpret-trailers --trailer "ack: Peff" \
1167 --trailer "Acked-by= Peff" --trailer "review:" \
1168 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1169 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1170 --trailer "ack: Peff" <complex_message >actual &&
1171 test_cmp expected actual
1174 test_expect_success
'using "ifExists = add" with "where = after"' '
1175 test_config trailer.ack.ifExists "add" &&
1176 test_config trailer.ack.key "Acked-by= " &&
1177 test_config trailer.ack.where "after" &&
1178 test_config trailer.bug.key "Bug #" &&
1179 test_config trailer.bug.where "before" &&
1180 test_config trailer.review.key "Reviewed-by:" &&
1181 test_config trailer.ifexists "addIfDifferent" &&
1182 test_config trailer.separators ":=#" &&
1183 cat complex_message_body >expected &&
1184 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1195 git interpret-trailers --trailer "ack: Peff" \
1196 --trailer "Acked-by= Peff" --trailer "review:" \
1197 --trailer "ack: Junio" --trailer "bug: 42" \
1198 --trailer "ack: Peff" <complex_message >actual &&
1199 test_cmp expected actual
1202 test_expect_success
'overriding configuration with "--if-exists replace"' '
1203 test_config trailer.fix.key "Fixes: " &&
1204 test_config trailer.fix.ifExists "add" &&
1205 test_config trailer.ack.key "Acked-by= " &&
1206 test_config trailer.ack.where "after" &&
1207 test_config trailer.bug.key "Bug #" &&
1208 test_config trailer.bug.where "before" &&
1209 test_config trailer.review.key "Reviewed-by:" &&
1210 test_config trailer.review.where "before" &&
1211 test_config trailer.separators ":=#" &&
1212 cat complex_message_body >expected &&
1213 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1220 git interpret-trailers --if-exists replace --trailer "review:" \
1221 --trailer "fix=53" --trailer "fix=22" --trailer "bug: 42" \
1222 <complex_message >actual &&
1223 test_cmp expected actual
1226 # "trailer.ifexists" is set to "doNothing", so using "--no-if-exists" defaults
1227 # to this "doNothing" behavior. So the "Fixes: 53" trailer does not get added.
1228 test_expect_success
'using "--if-exists replace" with "--no-if-exists" defaults to configuration' '
1229 test_config trailer.ifexists "doNothing" &&
1230 cat complex_message_body >expected &&
1231 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1237 git interpret-trailers --if-exists replace --no-if-exists --trailer "Fixes: 53" \
1238 <complex_message >actual &&
1239 test_cmp expected actual
1242 # No "ifexists" configuration is set, so using "--no-if-exists" makes it default
1243 # to addIfDifferentNeighbor. Because we do have a different neighbor "Fixes: 53"
1244 # (because it got added by overriding with "--if-exists replace" earlier in the
1245 # arguments list), we add "Signed-off-by: addme".
1246 test_expect_success
'using "--no-if-exists" defaults to hardcoded default if nothing configured' '
1247 cat complex_message_body >expected &&
1248 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1253 Signed-off-by: addme
1255 git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
1256 --trailer "Signed-off-by: addme" <complex_message >actual &&
1257 test_cmp expected actual
1260 # The second "Fixes: 53" trailer is discarded, because the "--no-if-exists" here
1261 # makes us default to addIfDifferentNeighbor, and we already added the "Fixes:
1262 # 53" trailer earlier in the argument list.
1263 test_expect_success
'using "--no-if-exists" defaults to hardcoded default if nothing configured (no addition)' '
1264 cat complex_message_body >expected &&
1265 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1271 git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
1272 --trailer "Fixes: 53" <complex_message >actual &&
1273 test_cmp expected actual
1276 test_expect_success
'using "ifExists = replace"' '
1277 test_config trailer.fix.key "Fixes: " &&
1278 test_config trailer.fix.ifExists "replace" &&
1279 test_config trailer.ack.key "Acked-by= " &&
1280 test_config trailer.ack.where "after" &&
1281 test_config trailer.bug.key "Bug #" &&
1282 test_config trailer.bug.where "before" &&
1283 test_config trailer.review.key "Reviewed-by:" &&
1284 test_config trailer.ifexists "addIfDifferent" &&
1285 test_config trailer.separators ":=#" &&
1286 cat complex_message_body >expected &&
1287 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1296 git interpret-trailers --trailer "review:" \
1297 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1298 --trailer "bug: 42" --trailer "ack: Peff" \
1299 <complex_message >actual &&
1300 test_cmp expected actual
1303 test_expect_success
'using "ifExists = replace" with "where = after"' '
1304 test_config trailer.ack.key "Acked-by= " &&
1305 test_config trailer.ack.where "after" &&
1306 test_config trailer.bug.key "Bug #" &&
1307 test_config trailer.bug.where "before" &&
1308 test_config trailer.fix.key "Fixes: " &&
1309 test_config trailer.fix.ifExists "replace" &&
1310 test_config trailer.fix.where "after" &&
1311 test_config trailer.review.key "Reviewed-by:" &&
1312 test_config trailer.ifexists "addIfDifferent" &&
1313 test_config trailer.separators ":=#" &&
1314 cat complex_message_body >expected &&
1315 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1324 git interpret-trailers --trailer "review:" \
1325 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1326 --trailer "bug: 42" --trailer "ack: Peff" \
1327 <complex_message >actual &&
1328 test_cmp expected actual
1331 test_expect_success
'using "ifExists = doNothing"' '
1332 test_config trailer.fix.ifExists "doNothing" &&
1333 test_config trailer.ack.key "Acked-by= " &&
1334 test_config trailer.ack.where "after" &&
1335 test_config trailer.bug.key "Bug #" &&
1336 test_config trailer.bug.where "before" &&
1337 test_config trailer.fix.key "Fixes: " &&
1338 test_config trailer.review.key "Reviewed-by:" &&
1339 test_config trailer.ifexists "addIfDifferent" &&
1340 test_config trailer.separators ":=#" &&
1341 cat complex_message_body >expected &&
1342 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1351 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1352 --trailer "ack: Junio" --trailer "fix=22" \
1353 --trailer "bug: 42" --trailer "ack: Peff" \
1354 <complex_message >actual &&
1355 test_cmp expected actual
1358 test_expect_success
'the default is "ifMissing = add"' '
1359 test_config trailer.ack.key "Acked-by= " &&
1360 test_config trailer.ack.where "after" &&
1361 test_config trailer.bug.key "Bug #" &&
1362 test_config trailer.bug.where "before" &&
1363 test_config trailer.cc.key "Cc: " &&
1364 test_config trailer.cc.where "before" &&
1365 test_config trailer.fix.key "Fixes: " &&
1366 test_config trailer.fix.ifExists "doNothing" &&
1367 test_config trailer.review.key "Reviewed-by:" &&
1368 test_config trailer.ifexists "addIfDifferent" &&
1369 test_config trailer.separators ":=#" &&
1370 cat complex_message_body >expected &&
1371 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1381 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1382 --trailer "cc=Linus" --trailer "ack: Junio" \
1383 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1384 <complex_message >actual &&
1385 test_cmp expected actual
1388 test_expect_success
'overriding configuration with "--if-missing doNothing"' '
1389 test_config trailer.ack.key "Acked-by= " &&
1390 test_config trailer.ack.where "after" &&
1391 test_config trailer.fix.key "Fixes: " &&
1392 test_config trailer.fix.ifExists "doNothing" &&
1393 test_config trailer.review.key "Reviewed-by:" &&
1394 test_config trailer.ifexists "addIfDifferent" &&
1395 test_config trailer.ifmissing "add" &&
1396 test_config trailer.separators ":=" &&
1397 cat complex_message_body >expected &&
1398 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1406 git interpret-trailers --if-missing doNothing \
1407 --trailer "review:" --trailer "fix=53" \
1408 --trailer "cc=Linus" --trailer "ack: Junio" \
1409 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1410 <complex_message >actual &&
1411 test_cmp expected actual
1414 test_expect_success
'when default "ifMissing" is "doNothing"' '
1415 test_config trailer.ack.key "Acked-by= " &&
1416 test_config trailer.ack.where "after" &&
1417 test_config trailer.fix.ifExists "doNothing" &&
1418 test_config trailer.review.key "Reviewed-by:" &&
1419 test_config trailer.ifexists "addIfDifferent" &&
1420 test_config trailer.ifmissing "doNothing" &&
1421 test_config trailer.separators ":=" &&
1422 cat complex_message_body >expected &&
1423 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1431 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1432 --trailer "cc=Linus" --trailer "ack: Junio" \
1433 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1434 <complex_message >actual &&
1435 test_cmp expected actual
1438 test_expect_success
'using "ifMissing = add" with "where = end"' '
1439 test_config trailer.ack.key "Acked-by= " &&
1440 test_config trailer.ack.where "after" &&
1441 test_config trailer.bug.key "Bug #" &&
1442 test_config trailer.bug.where "before" &&
1443 test_config trailer.cc.key "Cc: " &&
1444 test_config trailer.cc.ifMissing "add" &&
1445 test_config trailer.cc.where "end" &&
1446 test_config trailer.fix.ifExists "doNothing" &&
1447 test_config trailer.review.key "Reviewed-by:" &&
1448 test_config trailer.ifexists "addIfDifferent" &&
1449 test_config trailer.separators ":=#" &&
1450 cat complex_message_body >expected &&
1451 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1461 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1462 --trailer "ack: Junio" --trailer "fix=22" \
1463 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1464 <complex_message >actual &&
1465 test_cmp expected actual
1468 test_expect_success
'using "ifMissing = add" with "where = before"' '
1469 test_config trailer.ack.key "Acked-by= " &&
1470 test_config trailer.ack.where "after" &&
1471 test_config trailer.bug.key "Bug #" &&
1472 test_config trailer.bug.where "before" &&
1473 test_config trailer.cc.key "Cc: " &&
1474 test_config trailer.cc.ifMissing "add" &&
1475 test_config trailer.cc.where "before" &&
1476 test_config trailer.fix.ifExists "doNothing" &&
1477 test_config trailer.review.key "Reviewed-by:" &&
1478 test_config trailer.ifexists "addIfDifferent" &&
1479 test_config trailer.separators ":=#" &&
1480 cat complex_message_body >expected &&
1481 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1491 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1492 --trailer "ack: Junio" --trailer "fix=22" \
1493 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1494 <complex_message >actual &&
1495 test_cmp expected actual
1498 test_expect_success
'using "ifMissing = doNothing"' '
1499 test_config trailer.ack.key "Acked-by= " &&
1500 test_config trailer.ack.where "after" &&
1501 test_config trailer.bug.key "Bug #" &&
1502 test_config trailer.bug.where "before" &&
1503 test_config trailer.cc.ifMissing "doNothing" &&
1504 test_config trailer.fix.ifExists "doNothing" &&
1505 test_config trailer.review.key "Reviewed-by:" &&
1506 test_config trailer.ifexists "addIfDifferent" &&
1507 test_config trailer.separators ":=#" &&
1508 cat complex_message_body >expected &&
1509 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1518 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1519 --trailer "cc=Linus" --trailer "ack: Junio" \
1520 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1521 <complex_message >actual &&
1522 test_cmp expected actual
1525 # Ignore the "IgnoredTrailer" because of "--if-missing doNothing", but also
1526 # ignore the "StillIgnoredTrailer" because we set "trailer.ifMissing" to
1527 # "doNothing" in configuration.
1528 test_expect_success
'using "--no-if-missing" defaults to configuration' '
1529 test_config trailer.ifMissing "doNothing" &&
1530 cat complex_message_body >expected &&
1531 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1537 git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
1538 --trailer "StillIgnoredTrailer: ignoreme" <complex_message >actual &&
1539 test_cmp expected actual
1542 # Add the "AddedTrailer" because the "--no-if-missing" clears the "--if-missing
1543 # doNothing" from earlier in the argument list.
1544 test_expect_success
'using "--no-if-missing" defaults to hardcoded default if nothing configured' '
1545 cat complex_message_body >expected &&
1546 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1553 git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
1554 --trailer "AddedTrailer: addme" <complex_message >actual &&
1555 test_cmp expected actual
1558 test_expect_success
'default "where" is now "after"' '
1559 git config trailer.where "after" &&
1560 test_config trailer.ack.ifExists "add" &&
1561 test_config trailer.ack.key "Acked-by= " &&
1562 test_config trailer.ack.where "after" &&
1563 test_config trailer.bug.key "Bug #" &&
1564 test_config trailer.bug.where "before" &&
1565 test_config trailer.fix.ifExists "doNothing" &&
1566 test_config trailer.review.key "Reviewed-by:" &&
1567 test_config trailer.ifexists "addIfDifferent" &&
1568 test_config trailer.separators ":=#" &&
1569 cat complex_message_body >expected &&
1570 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1583 git interpret-trailers --trailer "ack: Peff" \
1584 --trailer "Acked-by= Peff" --trailer "review:" \
1585 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1586 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1587 --trailer "ack: Peff" <complex_message >actual &&
1588 test_cmp expected actual
1591 test_expect_success
'with simple command' '
1592 test_config trailer.ack.key "Acked-by= " &&
1593 test_config trailer.fix.ifExists "doNothing" &&
1594 test_config trailer.review.key "Reviewed-by:" &&
1595 test_config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
1596 test_config trailer.sign.key "Signed-off-by: " &&
1597 test_config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1598 test_config trailer.sign.where "after" &&
1599 test_config trailer.ifexists "addIfDifferent" &&
1600 test_config trailer.separators ":=" &&
1601 cat complex_message_body >expected &&
1602 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1607 Signed-off-by: A U Thor <author@example.com>
1609 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1610 <complex_message >actual &&
1611 test_cmp expected actual
1614 test_expect_success
'with command using committer information' '
1615 test_config trailer.ack.key "Acked-by= " &&
1616 test_config trailer.fix.ifExists "doNothing" &&
1617 test_config trailer.review.key "Reviewed-by:" &&
1618 test_config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
1619 test_config trailer.sign.key "Signed-off-by: " &&
1620 test_config trailer.sign.ifExists "addIfDifferent" &&
1621 test_config trailer.ifexists "addIfDifferent" &&
1622 test_config trailer.separators ":=" &&
1623 cat complex_message_body >expected &&
1624 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1629 Signed-off-by: C O Mitter <committer@example.com>
1631 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1632 <complex_message >actual &&
1633 test_cmp expected actual
1636 test_expect_success
'with command using author information' '
1637 test_config trailer.ack.key "Acked-by= " &&
1638 test_config trailer.fix.ifExists "doNothing" &&
1639 test_config trailer.review.key "Reviewed-by:" &&
1640 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1641 test_config trailer.sign.key "Signed-off-by: " &&
1642 test_config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1643 test_config trailer.sign.where "after" &&
1644 test_config trailer.ifexists "addIfDifferent" &&
1645 test_config trailer.separators ":=" &&
1646 cat complex_message_body >expected &&
1647 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1652 Signed-off-by: A U Thor <author@example.com>
1654 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1655 <complex_message >actual &&
1656 test_cmp expected actual
1659 test_expect_success
'setup a commit' '
1660 echo "Content of the first commit." > a.txt &&
1662 git commit -m "Add file a.txt"
1665 test_expect_success
'cmd takes precedence over command' '
1666 test_config trailer.ack.key "Acked-by= " &&
1667 test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \
1668 --abbrev-commit --abbrev=14 \$ARG" &&
1669 test_config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \
1670 --abbrev-commit --abbrev=14 \"\$1\" || true" &&
1671 test_config trailer.fix.key "Fixes: " &&
1672 test_config trailer.fix.ifExists "replace" &&
1673 test_config trailer.fix.where "after" &&
1674 test_config trailer.review.key "Reviewed-by:" &&
1675 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1676 test_config trailer.sign.key "Signed-off-by: " &&
1677 test_config trailer.ifexists "addIfDifferent" &&
1678 test_config trailer.separators ":=" &&
1679 FIXED=$(git log -1 --oneline --format="%h (%aN)" --abbrev-commit --abbrev=14 HEAD) &&
1680 cat complex_message_body >expected2 &&
1681 sed -e "s/ Z\$/ /" >>expected2 <<-EOF &&
1686 Signed-off-by: A U Thor <author@example.com>
1688 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1689 <complex_message >actual2 &&
1690 test_cmp expected2 actual2
1693 test_expect_success
'with command using $ARG' '
1694 test_config trailer.ack.key "Acked-by= " &&
1695 test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1696 test_config trailer.fix.key "Fixes: " &&
1697 test_config trailer.fix.ifExists "replace" &&
1698 test_config trailer.fix.where "after" &&
1699 test_config trailer.review.key "Reviewed-by:" &&
1700 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1701 test_config trailer.sign.key "Signed-off-by: " &&
1702 test_config trailer.ifexists "addIfDifferent" &&
1703 test_config trailer.separators ":=" &&
1704 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1705 cat complex_message_body >expected &&
1706 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1711 Signed-off-by: A U Thor <author@example.com>
1713 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1714 <complex_message >actual &&
1715 test_cmp expected actual
1718 test_expect_success
'with failing command using $ARG' '
1719 test_config trailer.ack.key "Acked-by= " &&
1720 test_config trailer.fix.command "false \$ARG" &&
1721 test_config trailer.fix.key "Fixes: " &&
1722 test_config trailer.fix.ifExists "replace" &&
1723 test_config trailer.fix.where "after" &&
1724 test_config trailer.review.key "Reviewed-by:" &&
1725 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1726 test_config trailer.sign.key "Signed-off-by: " &&
1727 test_config trailer.ifexists "addIfDifferent" &&
1728 test_config trailer.separators ":=" &&
1729 cat complex_message_body >expected &&
1730 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1735 Signed-off-by: A U Thor <author@example.com>
1737 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1738 <complex_message >actual &&
1739 test_cmp expected actual
1742 test_expect_success
'with empty tokens' '
1743 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1744 test_config trailer.sign.key "Signed-off-by: " &&
1745 test_config trailer.ifexists "addIfDifferent" &&
1746 cat >expected <<-EOF &&
1748 Signed-off-by: A U Thor <author@example.com>
1750 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1752 test_cmp expected actual
1755 test_expect_success
'with command but no key' '
1756 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1757 test_config trailer.ifexists "addIfDifferent" &&
1758 cat >expected <<-EOF &&
1760 sign: A U Thor <author@example.com>
1762 git interpret-trailers >actual <<-EOF &&
1764 test_cmp expected actual
1767 test_expect_success
'with no command and no key' '
1768 test_config trailer.review.where "before" &&
1769 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1770 test_config trailer.ifexists "addIfDifferent" &&
1771 cat >expected <<-EOF &&
1774 sign: A U Thor <author@example.com>
1776 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1778 test_cmp expected actual
1781 test_expect_success
'with cut line' '
1782 test_config trailer.review.where "before" &&
1783 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1784 cat >expected <<-\EOF &&
1788 sign: A U Thor <author@example.com>
1789 # ------------------------ >8 ------------------------
1792 git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
1794 # ------------------------ >8 ------------------------
1797 test_cmp expected actual
1800 test_expect_success
'only trailers' '
1801 test_config trailer.sign.command "echo config-value" &&
1802 test_config trailer.ifexists "addIfDifferent" &&
1803 cat >expected <<-\EOF &&
1804 existing: existing-value
1808 git interpret-trailers \
1809 --trailer added:added-value \
1810 --only-trailers >actual <<-\EOF &&
1815 existing: existing-value
1817 test_cmp expected actual
1820 test_expect_success
'only-trailers omits non-trailer in middle of block' '
1821 test_config trailer.sign.command "echo config-value" &&
1822 cat >expected <<-\EOF &&
1823 Signed-off-by: nobody <nobody@nowhere>
1824 Signed-off-by: somebody <somebody@somewhere>
1827 git interpret-trailers --only-trailers >actual <<-\EOF &&
1830 it is important that the trailers below are signed-off-by
1831 so that they meet the "25% trailers Git knows about" heuristic
1833 Signed-off-by: nobody <nobody@nowhere>
1834 this is not a trailer
1835 Signed-off-by: somebody <somebody@somewhere>
1837 test_cmp expected actual
1840 test_expect_success
'only input' '
1841 test_config trailer.sign.command "echo config-value" &&
1842 cat >expected <<-\EOF &&
1843 existing: existing-value
1845 git interpret-trailers \
1846 --only-trailers --only-input >actual <<-\EOF &&
1851 existing: existing-value
1853 test_cmp expected actual
1856 test_expect_success
'unfold' '
1857 cat >expected <<-\EOF &&
1858 foo: continued across several lines
1860 # pass through tr to make leading and trailing whitespace more obvious
1873 git interpret-trailers --only-trailers --only-input --unfold >actual &&
1874 test_cmp expected actual
1877 test_expect_success
'handling of --- lines in input' '
1878 echo "real-trailer: just right" >expected &&
1880 git interpret-trailers --parse >actual <<-\EOF &&
1885 not-a-trailer: too soon
1886 ------ this is just a line in the commit message with a bunch of
1887 ------ dashes; it does not have any syntactic meaning.
1889 real-trailer: just right
1891 below the dashed line may be a patch, etc.
1893 not-a-trailer: too late
1896 test_cmp expected actual
1899 test_expect_success
'suppress --- handling' '
1900 echo "real-trailer: just right" >expected &&
1902 git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1905 This commit message has a "---" in it, but because we tell
1906 interpret-trailers not to respect that, it has no effect.
1908 not-a-trailer: too soon
1911 This is still the commit message body.
1913 real-trailer: just right
1916 test_cmp expected actual
1919 test_expect_success
'suppressing --- does not disable cut-line handling' '
1920 echo "real-trailer: before the cut" >expected &&
1922 git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1925 This input has a cut-line in it; we should stop parsing when we see it
1926 and consider only trailers before that line.
1928 real-trailer: before the cut
1930 # ------------------------ >8 ------------------------
1931 # Nothing below this line counts as part of the commit message.
1932 not-a-trailer: too late
1935 test_cmp expected actual
1938 test_expect_success
'handling of --- lines in conjunction with cut-lines' '
1939 echo "my-trailer: here" >expected &&
1941 git interpret-trailers --parse >actual <<-\EOF &&
1946 # ------------------------ >8 ------------------------
1949 test_cmp expected actual