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 a bodiless message that lacks a trailing newline after the subject' '
179 cat >expected <<-\EOF &&
185 printf "area: change" |
186 git interpret-trailers --trailer "Reviewed-by: Peff" \
187 --trailer "Acked-by: Johan" >actual &&
188 test_cmp expected actual
191 test_expect_success
'with a bodied message that lacks a trailing newline after the body' '
192 cat >expected <<-\EOF &&
195 details about the change.
200 printf "area: change\n\ndetails about the change." |
201 git interpret-trailers --trailer "Reviewed-by: Peff" \
202 --trailer "Acked-by: Johan" >actual &&
203 test_cmp expected actual
206 test_expect_success
'with a message that lacks a trailing newline after the trailers' '
207 cat >expected <<-\EOF &&
213 printf "area: change\n\nReviewed-by: Peff" |
214 git interpret-trailers --trailer "Acked-by: Johan" >actual &&
215 test_cmp expected actual
218 test_expect_success
'with multiline title in the message' '
219 cat >expected <<-\EOF &&
226 printf "%s\n" "place of" "code: change" |
227 git interpret-trailers --trailer "Reviewed-by: Peff" \
228 --trailer "Acked-by: Johan" >actual &&
229 test_cmp expected actual
232 test_expect_success
'with non-trailer lines mixed with Signed-off-by' '
233 cat >patch <<-\EOF &&
235 this is not a trailer
236 this is not a trailer
237 Signed-off-by: a <a@example.com>
238 this is not a trailer
240 cat >expected <<-\EOF &&
242 this is not a trailer
243 this is not a trailer
244 Signed-off-by: a <a@example.com>
245 this is not a trailer
248 git interpret-trailers --trailer "token: value" patch >actual &&
249 test_cmp expected actual
252 test_expect_success
'with non-trailer lines mixed with cherry picked from' '
253 cat >patch <<-\EOF &&
255 this is not a trailer
256 this is not a trailer
257 (cherry picked from commit x)
258 this is not a trailer
260 cat >expected <<-\EOF &&
262 this is not a trailer
263 this is not a trailer
264 (cherry picked from commit x)
265 this is not a trailer
268 git interpret-trailers --trailer "token: value" patch >actual &&
269 test_cmp expected actual
272 test_expect_success
'with non-trailer lines mixed with a configured trailer' '
273 cat >patch <<-\EOF &&
275 this is not a trailer
276 this is not a trailer
278 this is not a trailer
280 cat >expected <<-\EOF &&
282 this is not a trailer
283 this is not a trailer
285 this is not a trailer
288 test_config trailer.my.key "My-trailer: " &&
289 git interpret-trailers --trailer "token: value" patch >actual &&
290 test_cmp expected actual
293 test_expect_success
'with non-trailer lines mixed with a non-configured trailer' '
294 cat >patch <<-\EOF &&
296 this is not a trailer
297 this is not a trailer
298 I-am-not-configured: x
299 this is not a trailer
301 cat >expected <<-\EOF &&
303 this is not a trailer
304 this is not a trailer
305 I-am-not-configured: x
306 this is not a trailer
310 test_config trailer.my.key "My-trailer: " &&
311 git interpret-trailers --trailer "token: value" patch >actual &&
312 test_cmp expected actual
315 test_expect_success
'with all non-configured trailers' '
316 cat >patch <<-\EOF &&
318 I-am-not-configured: x
319 I-am-also-not-configured: x
321 cat >expected <<-\EOF &&
323 I-am-not-configured: x
324 I-am-also-not-configured: x
327 test_config trailer.my.key "My-trailer: " &&
328 git interpret-trailers --trailer "token: value" patch >actual &&
329 test_cmp expected actual
332 test_expect_success
'with non-trailer lines only' '
333 cat >patch <<-\EOF &&
335 this is not a trailer
337 cat >expected <<-\EOF &&
339 this is not a trailer
343 git interpret-trailers --trailer "token: value" patch >actual &&
344 test_cmp expected actual
347 test_expect_success
'line with leading whitespace is not trailer' '
348 q_to_tab >patch <<-\EOF &&
352 q_to_tab >expected <<-\EOF &&
358 git interpret-trailers --trailer "token: value" patch >actual &&
359 test_cmp expected actual
362 test_expect_success
'multiline field treated as one trailer for 25% check' '
363 q_to_tab >patch <<-\EOF &&
365 Signed-off-by: a <a@example.com>
368 this is not a trailer
369 this is not a trailer
370 this is not a trailer
371 this is not a trailer
372 this is not a trailer
373 this is not a trailer
375 q_to_tab >expected <<-\EOF &&
377 Signed-off-by: a <a@example.com>
380 this is not a trailer
381 this is not a trailer
382 this is not a trailer
383 this is not a trailer
384 this is not a trailer
385 this is not a trailer
388 git interpret-trailers --trailer "name: value" patch >actual &&
389 test_cmp expected actual
392 test_expect_success
'multiline field treated as atomic for placement' '
393 q_to_tab >patch <<-\EOF &&
400 q_to_tab >expected <<-\EOF &&
408 test_config trailer.name.where after &&
409 git interpret-trailers --trailer "name: value" patch >actual &&
410 test_cmp expected actual
413 test_expect_success
'multiline field treated as atomic for replacement' '
414 q_to_tab >patch <<-\EOF &&
421 q_to_tab >expected <<-\EOF &&
427 test_config trailer.name.ifexists replace &&
428 git interpret-trailers --trailer "name: value" patch >actual &&
429 test_cmp expected actual
432 test_expect_success
'multiline field treated as atomic for difference check' '
433 q_to_tab >patch <<-\EOF &&
440 test_config trailer.name.ifexists addIfDifferent &&
442 q_to_tab >trailer <<-\EOF &&
446 q_to_tab >expected <<-\EOF &&
453 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
454 test_cmp expected actual &&
456 q_to_tab >trailer <<-\EOF &&
460 q_to_tab >expected <<-\EOF &&
469 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
470 test_cmp expected actual &&
472 q_to_tab >trailer <<-\EOF &&
473 name: first line *DIFFERENT*
476 q_to_tab >expected <<-\EOF &&
482 name: first line *DIFFERENT*
485 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
486 test_cmp expected actual
489 test_expect_success
'multiline field treated as atomic for neighbor check' '
490 q_to_tab >patch <<-\EOF &&
497 test_config trailer.name.where after &&
498 test_config trailer.name.ifexists addIfDifferentNeighbor &&
500 q_to_tab >trailer <<-\EOF &&
504 q_to_tab >expected <<-\EOF &&
511 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
512 test_cmp expected actual &&
514 q_to_tab >trailer <<-\EOF &&
518 q_to_tab >expected <<-\EOF &&
527 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
528 test_cmp expected actual
531 test_expect_success
'with config setup' '
532 test_config trailer.ack.key "Acked-by: " &&
533 cat >expected <<-\EOF &&
537 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
538 test_cmp expected actual &&
539 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
540 test_cmp expected actual &&
541 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
542 test_cmp expected actual
545 test_expect_success
'with config setup and ":=" as separators' '
546 test_config trailer.separators ":=" &&
547 test_config trailer.ack.key "Acked-by= " &&
548 cat >expected <<-\EOF &&
552 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
553 test_cmp expected actual &&
554 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
555 test_cmp expected actual &&
556 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
557 test_cmp expected actual
560 test_expect_success
'with config setup and "%" as separators' '
561 test_config trailer.separators "%" &&
562 cat >expected <<-\EOF &&
568 git interpret-trailers --trim-empty --trailer "bug = 42" \
569 --trailer count%10 --trailer "test: stuff" \
570 --trailer "bug % 422" empty >actual &&
571 test_cmp expected actual
574 test_expect_success
'with "%" as separators and a message with trailers' '
575 test_config trailer.separators "%" &&
576 cat >special_message <<-\EOF &&
583 cat >expected <<-\EOF &&
591 git interpret-trailers --trailer count%100 \
592 special_message >actual &&
593 test_cmp expected actual
596 test_expect_success
'with config setup and ":=#" as separators' '
597 test_config trailer.separators ":=#" &&
598 test_config trailer.bug.key "Bug #" &&
599 cat >expected <<-\EOF &&
603 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
604 test_cmp expected actual
607 test_expect_success
'with commit basic message' '
608 cat basic_message >expected &&
610 git interpret-trailers <basic_message >actual &&
611 test_cmp expected actual
614 test_expect_success
'with basic patch' '
615 cat basic_message >input &&
616 cat basic_patch >>input &&
617 cat basic_message >expected &&
619 cat basic_patch >>expected &&
620 git interpret-trailers <input >actual &&
621 test_cmp expected actual
624 test_expect_success
'with commit complex message as argument' '
625 test_config trailer.separators ":=" &&
626 test_config trailer.ack.key "Acked-by= " &&
627 cat complex_message_body complex_message_trailers >complex_message &&
628 cat complex_message_body >expected &&
629 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
635 git interpret-trailers complex_message >actual &&
636 test_cmp expected actual
639 test_expect_success
'with 2 files arguments' '
640 test_config trailer.separators ":=" &&
641 test_config trailer.ack.key "Acked-by= " &&
642 cat basic_message >>expected &&
644 cat basic_patch >>expected &&
645 git interpret-trailers complex_message input >actual &&
646 test_cmp expected actual
649 # Cover multiple comment characters with the same test input.
654 # This is the default, so let's explicitly _not_
655 # set any config to make sure it behaves as we expect.
658 config
="-c core.commentChar=$char"
662 test_expect_success
"with message that has comments ($char)" '
663 cat basic_message >message_with_comments &&
665 -e "s/#/$char/g" >>message_with_comments <<-EOF &&
670 # yet another comment
676 cat basic_patch >>message_with_comments &&
677 cat basic_message >expected &&
678 sed -e "s/#/$char/g" >>expected <<-\EOF &&
686 cat basic_patch >>expected &&
687 git $config interpret-trailers \
688 --trim-empty --trailer "Cc: Peff" \
689 message_with_comments >actual &&
690 test_cmp expected actual
694 test_expect_success
'with message that has an old style conflict block' '
695 cat basic_message >message_with_comments &&
696 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
701 # yet another comment
709 cat basic_message >expected &&
710 cat >>expected <<-\EOF &&
720 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
721 test_cmp expected actual
724 test_expect_success
'with commit complex message and trailer args' '
725 test_config trailer.separators ":=#" &&
726 test_config trailer.ack.key "Acked-by= " &&
727 test_config trailer.bug.key "Bug #" &&
728 cat complex_message_body >expected &&
729 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
737 git interpret-trailers --trailer "ack: Peff" \
738 --trailer "bug: 42" <complex_message >actual &&
739 test_cmp expected actual
742 test_expect_success
'with complex patch, args and --trim-empty' '
743 test_config trailer.separators ":=#" &&
744 test_config trailer.ack.key "Acked-by= " &&
745 test_config trailer.bug.key "Bug #" &&
746 cat complex_message >complex_patch &&
747 cat basic_patch >>complex_patch &&
748 cat complex_message_body >expected &&
749 cat >>expected <<-\EOF &&
753 cat basic_patch >>expected &&
754 git interpret-trailers --trim-empty --trailer "ack: Peff" \
755 --trailer "bug: 42" <complex_patch >actual &&
756 test_cmp expected actual
759 test_expect_success
'in-place editing with basic patch' '
760 cat basic_message >message &&
761 cat basic_patch >>message &&
762 cat basic_message >expected &&
764 cat basic_patch >>expected &&
765 git interpret-trailers --in-place message &&
766 test_cmp expected message
769 test_expect_success
'in-place editing with additional trailer' '
770 cat basic_message >message &&
771 cat basic_patch >>message &&
772 cat basic_message >expected &&
774 cat >>expected <<-\EOF &&
777 cat basic_patch >>expected &&
778 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
779 test_cmp expected message
782 test_expect_success
'in-place editing on stdin disallowed' '
783 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
786 test_expect_success
'in-place editing on non-existing file' '
787 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
788 test_path_is_missing nonexisting
791 test_expect_success POSIXPERM
,SANITY
"in-place editing doesn't clobber original file on error" '
792 cat basic_message >message &&
794 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
796 test_cmp message basic_message
799 test_expect_success
'using "where = before"' '
800 test_config trailer.separators ":=#" &&
801 test_config trailer.ack.key "Acked-by= " &&
802 test_config trailer.bug.key "Bug #" &&
803 test_config trailer.bug.where "before" &&
804 cat complex_message_body >expected &&
805 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
813 git interpret-trailers --trailer "ack: Peff" \
814 --trailer "bug: 42" complex_message >actual &&
815 test_cmp expected actual
818 test_expect_success
'overriding configuration with "--where after"' '
819 test_config trailer.separators ":=" &&
820 test_config trailer.ack.key "Acked-by= " &&
821 test_config trailer.ack.where "before" &&
822 cat complex_message_body >expected &&
823 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
830 git interpret-trailers --where after --trailer "ack: Peff" \
831 complex_message >actual &&
832 test_cmp expected actual
835 test_expect_success
'using "--where after" with "--no-where"' '
836 test_config trailer.ack.key "Acked-by= " &&
837 test_config trailer.ack.where "before" &&
838 test_config trailer.bug.key "Bug #" &&
839 test_config trailer.bug.where "before" &&
840 test_config trailer.separators ":=#" &&
841 cat complex_message_body >expected &&
842 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
850 git interpret-trailers --where after --no-where --trailer "ack: Peff" \
851 --trailer "bug: 42" complex_message >actual &&
852 test_cmp expected actual
855 # Check whether using "--no-where" clears out only the "--where after", such
856 # that we still use the configuration in trailer.where (which is different from
857 # the hardcoded default (in WHERE_END) assuming the absence of .gitconfig).
858 # Here, the "start" setting of trailer.where is respected, so the new "Acked-by"
859 # and "Bug" trailers are placed at the beginning, and not at the end which is
860 # the harcoded default.
861 test_expect_success
'using "--where after" with "--no-where" defaults to configuration' '
862 test_config trailer.ack.key "Acked-by= " &&
863 test_config trailer.bug.key "Bug #" &&
864 test_config trailer.separators ":=#" &&
865 test_config trailer.where "start" &&
866 cat complex_message_body >expected &&
867 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
875 git interpret-trailers --where after --no-where --trailer "ack: Peff" \
876 --trailer "bug: 42" complex_message >actual &&
877 test_cmp expected actual
880 # The "--where after" will only get respected for the trailer that came
881 # immediately after it. For the next trailer (Bug #42), we default to using the
882 # hardcoded WHERE_END because we don't have any "trailer.where" or
883 # "trailer.bug.where" configured.
884 test_expect_success
'using "--no-where" defaults to harcoded default if nothing configured' '
885 test_config trailer.ack.key "Acked-by= " &&
886 test_config trailer.bug.key "Bug #" &&
887 test_config trailer.separators ":=#" &&
888 cat complex_message_body >expected &&
889 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
897 git interpret-trailers --where after --trailer "ack: Peff" --no-where \
898 --trailer "bug: 42" complex_message >actual &&
899 test_cmp expected actual
902 test_expect_success
'using "where = after"' '
903 test_config trailer.ack.key "Acked-by= " &&
904 test_config trailer.ack.where "after" &&
905 test_config trailer.bug.key "Bug #" &&
906 test_config trailer.bug.where "before" &&
907 test_config trailer.separators ":=#" &&
908 cat complex_message_body >expected &&
909 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
917 git interpret-trailers --trailer "ack: Peff" \
918 --trailer "bug: 42" complex_message >actual &&
919 test_cmp expected actual
922 test_expect_success
'using "where = end"' '
923 test_config trailer.review.key "Reviewed-by" &&
924 test_config trailer.review.where "end" &&
925 test_config trailer.ack.key "Acked-by= " &&
926 test_config trailer.ack.where "after" &&
927 test_config trailer.separators ":=" &&
928 cat complex_message_body >expected &&
929 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
936 Reviewed-by: Johannes
938 git interpret-trailers --trailer "ack: Peff" \
939 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
940 complex_message >actual &&
941 test_cmp expected actual
944 test_expect_success
'using "where = start"' '
945 test_config trailer.review.key "Reviewed-by" &&
946 test_config trailer.review.where "start" &&
947 test_config trailer.ack.key "Acked-by= " &&
948 test_config trailer.ack.where "after" &&
949 test_config trailer.separators ":=" &&
950 cat complex_message_body >expected &&
951 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
952 Reviewed-by: Johannes
960 git interpret-trailers --trailer "ack: Peff" \
961 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
962 complex_message >actual &&
963 test_cmp expected actual
966 test_expect_success
'using "where = before" for a token in the middle of the message' '
967 test_config trailer.review.key "Reviewed-by:" &&
968 test_config trailer.review.where "before" &&
969 test_config trailer.ack.key "Acked-by= " &&
970 test_config trailer.ack.where "after" &&
971 test_config trailer.bug.key "Bug #" &&
972 test_config trailer.bug.where "before" &&
973 test_config trailer.separators ":=#" &&
974 cat complex_message_body >expected &&
975 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
984 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
985 --trailer "review: Johan" <complex_message >actual &&
986 test_cmp expected actual
989 test_expect_success
'using "where = before" and --trim-empty' '
990 test_config trailer.ack.key "Acked-by= " &&
991 test_config trailer.ack.where "after" &&
992 test_config trailer.bug.key "Bug #" &&
993 test_config trailer.bug.where "before" &&
994 test_config trailer.review.key "Reviewed-by:" &&
995 test_config trailer.separators ":=#" &&
996 cat complex_message_body >expected &&
997 cat >>expected <<-\EOF &&
1003 git interpret-trailers --trim-empty --trailer "ack: Peff" \
1004 --trailer "bug: 42" --trailer "review: Johan" \
1005 --trailer "Bug: 46" <complex_message >actual &&
1006 test_cmp expected actual
1009 test_expect_success
'the default is "ifExists = addIfDifferentNeighbor"' '
1010 test_config trailer.ack.key "Acked-by= " &&
1011 test_config trailer.ack.where "after" &&
1012 test_config trailer.bug.key "Bug #" &&
1013 test_config trailer.bug.where "before" &&
1014 test_config trailer.review.key "Reviewed-by:" &&
1015 test_config trailer.review.where "before" &&
1016 test_config trailer.separators ":=#" &&
1017 cat complex_message_body >expected &&
1018 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1028 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1029 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
1030 --trailer "ack: Peff" <complex_message >actual &&
1031 test_cmp expected actual
1034 test_expect_success
'default "ifExists" is now "addIfDifferent"' '
1035 test_config trailer.ifexists "addIfDifferent" &&
1036 test_config trailer.ack.key "Acked-by= " &&
1037 test_config trailer.ack.where "after" &&
1038 test_config trailer.bug.key "Bug #" &&
1039 test_config trailer.bug.where "before" &&
1040 test_config trailer.review.key "Reviewed-by:" &&
1041 test_config trailer.separators ":=#" &&
1042 cat complex_message_body >expected &&
1043 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1052 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1053 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
1054 --trailer "ack: Peff" <complex_message >actual &&
1055 test_cmp expected actual
1058 test_expect_success
'using "ifExists = addIfDifferent" with "where = end"' '
1059 test_config trailer.ack.ifExists "addIfDifferent" &&
1060 test_config trailer.ack.key "Acked-by= " &&
1061 test_config trailer.ack.where "end" &&
1062 test_config trailer.bug.key "Bug #" &&
1063 test_config trailer.bug.where "before" &&
1064 test_config trailer.review.key "Reviewed-by:" &&
1065 test_config trailer.ifexists "addIfDifferent" &&
1066 test_config trailer.separators ":=#" &&
1067 cat complex_message_body >expected &&
1068 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1076 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1077 --trailer "bug: 42" --trailer "ack: Peff" \
1078 <complex_message >actual &&
1079 test_cmp expected actual
1082 test_expect_success
'using "ifExists = addIfDifferent" with "where = before"' '
1083 test_config trailer.ack.ifExists "addIfDifferent" &&
1084 test_config trailer.ack.key "Acked-by= " &&
1085 test_config trailer.ack.where "before" &&
1086 test_config trailer.bug.key "Bug #" &&
1087 test_config trailer.bug.where "before" &&
1088 test_config trailer.review.key "Reviewed-by:" &&
1089 test_config trailer.ifexists "addIfDifferent" &&
1090 test_config trailer.separators ":=#" &&
1091 cat complex_message_body >expected &&
1092 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1100 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1101 --trailer "bug: 42" --trailer "ack: Peff" \
1102 <complex_message >actual &&
1103 test_cmp expected actual
1106 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
1107 test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1108 test_config trailer.ack.key "Acked-by= " &&
1109 test_config trailer.ack.where "end" &&
1110 test_config trailer.bug.key "Bug #" &&
1111 test_config trailer.bug.where "before" &&
1112 test_config trailer.review.key "Reviewed-by:" &&
1113 test_config trailer.ifexists "addIfDifferent" &&
1114 test_config trailer.separators ":=#" &&
1115 cat complex_message_body >expected &&
1116 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1128 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1129 --trailer "ack: Junio" --trailer "bug: 42" \
1130 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1131 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
1132 test_cmp expected actual
1135 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
1136 test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1137 test_config trailer.ack.key "Acked-by= " &&
1138 test_config trailer.ack.where "after" &&
1139 test_config trailer.bug.key "Bug #" &&
1140 test_config trailer.bug.where "before" &&
1141 test_config trailer.review.key "Reviewed-by:" &&
1142 test_config trailer.ifexists "addIfDifferent" &&
1143 test_config trailer.separators ":=#" &&
1144 cat complex_message_body >expected &&
1145 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1156 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
1157 --trailer "ack: Junio" --trailer "bug: 42" \
1158 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1159 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
1160 test_cmp expected actual
1163 test_expect_success
'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
1164 test_config trailer.ack.ifExists "addIfDifferentNeighbor" &&
1165 test_config trailer.ack.key "Acked-by= " &&
1166 test_config trailer.bug.key "Bug #" &&
1167 test_config trailer.bug.where "before" &&
1168 test_config trailer.separators ":=#" &&
1169 cat complex_message_body >expected &&
1170 cat >>expected <<-\EOF &&
1176 git interpret-trailers --trim-empty --trailer "ack: Peff" \
1177 --trailer "Acked-by= Peff" --trailer "review:" \
1178 --trailer "ack: Junio" --trailer "bug: 42" \
1179 --trailer "ack: Peff" <complex_message >actual &&
1180 test_cmp expected actual
1183 test_expect_success
'using "ifExists = add" with "where = end"' '
1184 test_config trailer.ack.ifExists "add" &&
1185 test_config trailer.ack.key "Acked-by= " &&
1186 test_config trailer.ack.where "end" &&
1187 test_config trailer.bug.key "Bug #" &&
1188 test_config trailer.bug.where "before" &&
1189 test_config trailer.review.key "Reviewed-by:" &&
1190 test_config trailer.ifexists "addIfDifferent" &&
1191 test_config trailer.separators ":=#" &&
1192 cat complex_message_body >expected &&
1193 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1206 git interpret-trailers --trailer "ack: Peff" \
1207 --trailer "Acked-by= Peff" --trailer "review:" \
1208 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1209 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1210 --trailer "ack: Peff" <complex_message >actual &&
1211 test_cmp expected actual
1214 test_expect_success
'using "ifExists = add" with "where = after"' '
1215 test_config trailer.ack.ifExists "add" &&
1216 test_config trailer.ack.key "Acked-by= " &&
1217 test_config trailer.ack.where "after" &&
1218 test_config trailer.bug.key "Bug #" &&
1219 test_config trailer.bug.where "before" &&
1220 test_config trailer.review.key "Reviewed-by:" &&
1221 test_config trailer.ifexists "addIfDifferent" &&
1222 test_config trailer.separators ":=#" &&
1223 cat complex_message_body >expected &&
1224 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1235 git interpret-trailers --trailer "ack: Peff" \
1236 --trailer "Acked-by= Peff" --trailer "review:" \
1237 --trailer "ack: Junio" --trailer "bug: 42" \
1238 --trailer "ack: Peff" <complex_message >actual &&
1239 test_cmp expected actual
1242 test_expect_success
'overriding configuration with "--if-exists replace"' '
1243 test_config trailer.fix.key "Fixes: " &&
1244 test_config trailer.fix.ifExists "add" &&
1245 test_config trailer.ack.key "Acked-by= " &&
1246 test_config trailer.ack.where "after" &&
1247 test_config trailer.bug.key "Bug #" &&
1248 test_config trailer.bug.where "before" &&
1249 test_config trailer.review.key "Reviewed-by:" &&
1250 test_config trailer.review.where "before" &&
1251 test_config trailer.separators ":=#" &&
1252 cat complex_message_body >expected &&
1253 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1260 git interpret-trailers --if-exists replace --trailer "review:" \
1261 --trailer "fix=53" --trailer "fix=22" --trailer "bug: 42" \
1262 <complex_message >actual &&
1263 test_cmp expected actual
1266 # "trailer.ifexists" is set to "doNothing", so using "--no-if-exists" defaults
1267 # to this "doNothing" behavior. So the "Fixes: 53" trailer does not get added.
1268 test_expect_success
'using "--if-exists replace" with "--no-if-exists" defaults to configuration' '
1269 test_config trailer.ifexists "doNothing" &&
1270 cat complex_message_body >expected &&
1271 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1277 git interpret-trailers --if-exists replace --no-if-exists --trailer "Fixes: 53" \
1278 <complex_message >actual &&
1279 test_cmp expected actual
1282 # No "ifexists" configuration is set, so using "--no-if-exists" makes it default
1283 # to addIfDifferentNeighbor. Because we do have a different neighbor "Fixes: 53"
1284 # (because it got added by overriding with "--if-exists replace" earlier in the
1285 # arguments list), we add "Signed-off-by: addme".
1286 test_expect_success
'using "--no-if-exists" defaults to hardcoded default if nothing configured' '
1287 cat complex_message_body >expected &&
1288 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1293 Signed-off-by: addme
1295 git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
1296 --trailer "Signed-off-by: addme" <complex_message >actual &&
1297 test_cmp expected actual
1300 # The second "Fixes: 53" trailer is discarded, because the "--no-if-exists" here
1301 # makes us default to addIfDifferentNeighbor, and we already added the "Fixes:
1302 # 53" trailer earlier in the argument list.
1303 test_expect_success
'using "--no-if-exists" defaults to hardcoded default if nothing configured (no addition)' '
1304 cat complex_message_body >expected &&
1305 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1311 git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
1312 --trailer "Fixes: 53" <complex_message >actual &&
1313 test_cmp expected actual
1316 test_expect_success
'using "ifExists = replace"' '
1317 test_config trailer.fix.key "Fixes: " &&
1318 test_config trailer.fix.ifExists "replace" &&
1319 test_config trailer.ack.key "Acked-by= " &&
1320 test_config trailer.ack.where "after" &&
1321 test_config trailer.bug.key "Bug #" &&
1322 test_config trailer.bug.where "before" &&
1323 test_config trailer.review.key "Reviewed-by:" &&
1324 test_config trailer.ifexists "addIfDifferent" &&
1325 test_config trailer.separators ":=#" &&
1326 cat complex_message_body >expected &&
1327 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1336 git interpret-trailers --trailer "review:" \
1337 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1338 --trailer "bug: 42" --trailer "ack: Peff" \
1339 <complex_message >actual &&
1340 test_cmp expected actual
1343 test_expect_success
'using "ifExists = replace" with "where = after"' '
1344 test_config trailer.ack.key "Acked-by= " &&
1345 test_config trailer.ack.where "after" &&
1346 test_config trailer.bug.key "Bug #" &&
1347 test_config trailer.bug.where "before" &&
1348 test_config trailer.fix.key "Fixes: " &&
1349 test_config trailer.fix.ifExists "replace" &&
1350 test_config trailer.fix.where "after" &&
1351 test_config trailer.review.key "Reviewed-by:" &&
1352 test_config trailer.ifexists "addIfDifferent" &&
1353 test_config trailer.separators ":=#" &&
1354 cat complex_message_body >expected &&
1355 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1364 git interpret-trailers --trailer "review:" \
1365 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
1366 --trailer "bug: 42" --trailer "ack: Peff" \
1367 <complex_message >actual &&
1368 test_cmp expected actual
1371 test_expect_success
'using "ifExists = doNothing"' '
1372 test_config trailer.fix.ifExists "doNothing" &&
1373 test_config trailer.ack.key "Acked-by= " &&
1374 test_config trailer.ack.where "after" &&
1375 test_config trailer.bug.key "Bug #" &&
1376 test_config trailer.bug.where "before" &&
1377 test_config trailer.fix.key "Fixes: " &&
1378 test_config trailer.review.key "Reviewed-by:" &&
1379 test_config trailer.ifexists "addIfDifferent" &&
1380 test_config trailer.separators ":=#" &&
1381 cat complex_message_body >expected &&
1382 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1391 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1392 --trailer "ack: Junio" --trailer "fix=22" \
1393 --trailer "bug: 42" --trailer "ack: Peff" \
1394 <complex_message >actual &&
1395 test_cmp expected actual
1398 test_expect_success
'the default is "ifMissing = add"' '
1399 test_config trailer.ack.key "Acked-by= " &&
1400 test_config trailer.ack.where "after" &&
1401 test_config trailer.bug.key "Bug #" &&
1402 test_config trailer.bug.where "before" &&
1403 test_config trailer.cc.key "Cc: " &&
1404 test_config trailer.cc.where "before" &&
1405 test_config trailer.fix.key "Fixes: " &&
1406 test_config trailer.fix.ifExists "doNothing" &&
1407 test_config trailer.review.key "Reviewed-by:" &&
1408 test_config trailer.ifexists "addIfDifferent" &&
1409 test_config trailer.separators ":=#" &&
1410 cat complex_message_body >expected &&
1411 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1421 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1422 --trailer "cc=Linus" --trailer "ack: Junio" \
1423 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1424 <complex_message >actual &&
1425 test_cmp expected actual
1428 test_expect_success
'overriding configuration with "--if-missing doNothing"' '
1429 test_config trailer.ack.key "Acked-by= " &&
1430 test_config trailer.ack.where "after" &&
1431 test_config trailer.fix.key "Fixes: " &&
1432 test_config trailer.fix.ifExists "doNothing" &&
1433 test_config trailer.review.key "Reviewed-by:" &&
1434 test_config trailer.ifexists "addIfDifferent" &&
1435 test_config trailer.ifmissing "add" &&
1436 test_config trailer.separators ":=" &&
1437 cat complex_message_body >expected &&
1438 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1446 git interpret-trailers --if-missing doNothing \
1447 --trailer "review:" --trailer "fix=53" \
1448 --trailer "cc=Linus" --trailer "ack: Junio" \
1449 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1450 <complex_message >actual &&
1451 test_cmp expected actual
1454 test_expect_success
'when default "ifMissing" is "doNothing"' '
1455 test_config trailer.ack.key "Acked-by= " &&
1456 test_config trailer.ack.where "after" &&
1457 test_config trailer.fix.ifExists "doNothing" &&
1458 test_config trailer.review.key "Reviewed-by:" &&
1459 test_config trailer.ifexists "addIfDifferent" &&
1460 test_config trailer.ifmissing "doNothing" &&
1461 test_config trailer.separators ":=" &&
1462 cat complex_message_body >expected &&
1463 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1471 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1472 --trailer "cc=Linus" --trailer "ack: Junio" \
1473 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1474 <complex_message >actual &&
1475 test_cmp expected actual
1478 test_expect_success
'using "ifMissing = add" with "where = end"' '
1479 test_config trailer.ack.key "Acked-by= " &&
1480 test_config trailer.ack.where "after" &&
1481 test_config trailer.bug.key "Bug #" &&
1482 test_config trailer.bug.where "before" &&
1483 test_config trailer.cc.key "Cc: " &&
1484 test_config trailer.cc.ifMissing "add" &&
1485 test_config trailer.cc.where "end" &&
1486 test_config trailer.fix.ifExists "doNothing" &&
1487 test_config trailer.review.key "Reviewed-by:" &&
1488 test_config trailer.ifexists "addIfDifferent" &&
1489 test_config trailer.separators ":=#" &&
1490 cat complex_message_body >expected &&
1491 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1501 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1502 --trailer "ack: Junio" --trailer "fix=22" \
1503 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1504 <complex_message >actual &&
1505 test_cmp expected actual
1508 test_expect_success
'using "ifMissing = add" with "where = before"' '
1509 test_config trailer.ack.key "Acked-by= " &&
1510 test_config trailer.ack.where "after" &&
1511 test_config trailer.bug.key "Bug #" &&
1512 test_config trailer.bug.where "before" &&
1513 test_config trailer.cc.key "Cc: " &&
1514 test_config trailer.cc.ifMissing "add" &&
1515 test_config trailer.cc.where "before" &&
1516 test_config trailer.fix.ifExists "doNothing" &&
1517 test_config trailer.review.key "Reviewed-by:" &&
1518 test_config trailer.ifexists "addIfDifferent" &&
1519 test_config trailer.separators ":=#" &&
1520 cat complex_message_body >expected &&
1521 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1531 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1532 --trailer "ack: Junio" --trailer "fix=22" \
1533 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
1534 <complex_message >actual &&
1535 test_cmp expected actual
1538 test_expect_success
'using "ifMissing = doNothing"' '
1539 test_config trailer.ack.key "Acked-by= " &&
1540 test_config trailer.ack.where "after" &&
1541 test_config trailer.bug.key "Bug #" &&
1542 test_config trailer.bug.where "before" &&
1543 test_config trailer.cc.ifMissing "doNothing" &&
1544 test_config trailer.fix.ifExists "doNothing" &&
1545 test_config trailer.review.key "Reviewed-by:" &&
1546 test_config trailer.ifexists "addIfDifferent" &&
1547 test_config trailer.separators ":=#" &&
1548 cat complex_message_body >expected &&
1549 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1558 git interpret-trailers --trailer "review:" --trailer "fix=53" \
1559 --trailer "cc=Linus" --trailer "ack: Junio" \
1560 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
1561 <complex_message >actual &&
1562 test_cmp expected actual
1565 # Ignore the "IgnoredTrailer" because of "--if-missing doNothing", but also
1566 # ignore the "StillIgnoredTrailer" because we set "trailer.ifMissing" to
1567 # "doNothing" in configuration.
1568 test_expect_success
'using "--no-if-missing" defaults to configuration' '
1569 test_config trailer.ifMissing "doNothing" &&
1570 cat complex_message_body >expected &&
1571 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1577 git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
1578 --trailer "StillIgnoredTrailer: ignoreme" <complex_message >actual &&
1579 test_cmp expected actual
1582 # Add the "AddedTrailer" because the "--no-if-missing" clears the "--if-missing
1583 # doNothing" from earlier in the argument list.
1584 test_expect_success
'using "--no-if-missing" defaults to hardcoded default if nothing configured' '
1585 cat complex_message_body >expected &&
1586 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1593 git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
1594 --trailer "AddedTrailer: addme" <complex_message >actual &&
1595 test_cmp expected actual
1598 test_expect_success
'default "where" is now "after"' '
1599 git config trailer.where "after" &&
1600 test_config trailer.ack.ifExists "add" &&
1601 test_config trailer.ack.key "Acked-by= " &&
1602 test_config trailer.ack.where "after" &&
1603 test_config trailer.bug.key "Bug #" &&
1604 test_config trailer.bug.where "before" &&
1605 test_config trailer.fix.ifExists "doNothing" &&
1606 test_config trailer.review.key "Reviewed-by:" &&
1607 test_config trailer.ifexists "addIfDifferent" &&
1608 test_config trailer.separators ":=#" &&
1609 cat complex_message_body >expected &&
1610 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1623 git interpret-trailers --trailer "ack: Peff" \
1624 --trailer "Acked-by= Peff" --trailer "review:" \
1625 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
1626 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
1627 --trailer "ack: Peff" <complex_message >actual &&
1628 test_cmp expected actual
1631 test_expect_success
'with simple command' '
1632 test_config trailer.ack.key "Acked-by= " &&
1633 test_config trailer.fix.ifExists "doNothing" &&
1634 test_config trailer.review.key "Reviewed-by:" &&
1635 test_config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
1636 test_config trailer.sign.key "Signed-off-by: " &&
1637 test_config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1638 test_config trailer.sign.where "after" &&
1639 test_config trailer.ifexists "addIfDifferent" &&
1640 test_config trailer.separators ":=" &&
1641 cat complex_message_body >expected &&
1642 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1647 Signed-off-by: A U Thor <author@example.com>
1649 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1650 <complex_message >actual &&
1651 test_cmp expected actual
1654 test_expect_success
'with command using committer information' '
1655 test_config trailer.ack.key "Acked-by= " &&
1656 test_config trailer.fix.ifExists "doNothing" &&
1657 test_config trailer.review.key "Reviewed-by:" &&
1658 test_config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
1659 test_config trailer.sign.key "Signed-off-by: " &&
1660 test_config trailer.sign.ifExists "addIfDifferent" &&
1661 test_config trailer.ifexists "addIfDifferent" &&
1662 test_config trailer.separators ":=" &&
1663 cat complex_message_body >expected &&
1664 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1669 Signed-off-by: C O Mitter <committer@example.com>
1671 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1672 <complex_message >actual &&
1673 test_cmp expected actual
1676 test_expect_success
'with command using author information' '
1677 test_config trailer.ack.key "Acked-by= " &&
1678 test_config trailer.fix.ifExists "doNothing" &&
1679 test_config trailer.review.key "Reviewed-by:" &&
1680 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1681 test_config trailer.sign.key "Signed-off-by: " &&
1682 test_config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1683 test_config trailer.sign.where "after" &&
1684 test_config trailer.ifexists "addIfDifferent" &&
1685 test_config trailer.separators ":=" &&
1686 cat complex_message_body >expected &&
1687 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1692 Signed-off-by: A U Thor <author@example.com>
1694 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1695 <complex_message >actual &&
1696 test_cmp expected actual
1699 test_expect_success
'setup a commit' '
1700 echo "Content of the first commit." > a.txt &&
1702 git commit -m "Add file a.txt"
1705 test_expect_success
'cmd takes precedence over command' '
1706 test_config trailer.ack.key "Acked-by= " &&
1707 test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \
1708 --abbrev-commit --abbrev=14 \$ARG" &&
1709 test_config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \
1710 --abbrev-commit --abbrev=14 \"\$1\" || true" &&
1711 test_config trailer.fix.key "Fixes: " &&
1712 test_config trailer.fix.ifExists "replace" &&
1713 test_config trailer.fix.where "after" &&
1714 test_config trailer.review.key "Reviewed-by:" &&
1715 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1716 test_config trailer.sign.key "Signed-off-by: " &&
1717 test_config trailer.ifexists "addIfDifferent" &&
1718 test_config trailer.separators ":=" &&
1719 FIXED=$(git log -1 --oneline --format="%h (%aN)" --abbrev-commit --abbrev=14 HEAD) &&
1720 cat complex_message_body >expected2 &&
1721 sed -e "s/ Z\$/ /" >>expected2 <<-EOF &&
1726 Signed-off-by: A U Thor <author@example.com>
1728 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1729 <complex_message >actual2 &&
1730 test_cmp expected2 actual2
1733 test_expect_success
'with command using $ARG' '
1734 test_config trailer.ack.key "Acked-by= " &&
1735 test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1736 test_config trailer.fix.key "Fixes: " &&
1737 test_config trailer.fix.ifExists "replace" &&
1738 test_config trailer.fix.where "after" &&
1739 test_config trailer.review.key "Reviewed-by:" &&
1740 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1741 test_config trailer.sign.key "Signed-off-by: " &&
1742 test_config trailer.ifexists "addIfDifferent" &&
1743 test_config trailer.separators ":=" &&
1744 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1745 cat complex_message_body >expected &&
1746 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1751 Signed-off-by: A U Thor <author@example.com>
1753 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1754 <complex_message >actual &&
1755 test_cmp expected actual
1758 test_expect_success
'with failing command using $ARG' '
1759 test_config trailer.ack.key "Acked-by= " &&
1760 test_config trailer.fix.command "false \$ARG" &&
1761 test_config trailer.fix.key "Fixes: " &&
1762 test_config trailer.fix.ifExists "replace" &&
1763 test_config trailer.fix.where "after" &&
1764 test_config trailer.review.key "Reviewed-by:" &&
1765 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1766 test_config trailer.sign.key "Signed-off-by: " &&
1767 test_config trailer.ifexists "addIfDifferent" &&
1768 test_config trailer.separators ":=" &&
1769 cat complex_message_body >expected &&
1770 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1775 Signed-off-by: A U Thor <author@example.com>
1777 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1778 <complex_message >actual &&
1779 test_cmp expected actual
1782 test_expect_success
'with empty tokens' '
1783 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1784 test_config trailer.sign.key "Signed-off-by: " &&
1785 test_config trailer.ifexists "addIfDifferent" &&
1786 cat >expected <<-EOF &&
1788 Signed-off-by: A U Thor <author@example.com>
1790 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1792 test_cmp expected actual
1795 test_expect_success
'with command but no key' '
1796 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1797 test_config trailer.ifexists "addIfDifferent" &&
1798 cat >expected <<-EOF &&
1800 sign: A U Thor <author@example.com>
1802 git interpret-trailers >actual <<-EOF &&
1804 test_cmp expected actual
1807 test_expect_success
'with no command and no key' '
1808 test_config trailer.review.where "before" &&
1809 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1810 test_config trailer.ifexists "addIfDifferent" &&
1811 cat >expected <<-EOF &&
1814 sign: A U Thor <author@example.com>
1816 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1818 test_cmp expected actual
1821 test_expect_success
'with cut line' '
1822 test_config trailer.review.where "before" &&
1823 test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1824 cat >expected <<-\EOF &&
1828 sign: A U Thor <author@example.com>
1829 # ------------------------ >8 ------------------------
1832 git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
1834 # ------------------------ >8 ------------------------
1837 test_cmp expected actual
1840 test_expect_success
'only trailers' '
1841 test_config trailer.sign.command "echo config-value" &&
1842 test_config trailer.ifexists "addIfDifferent" &&
1843 cat >expected <<-\EOF &&
1844 existing: existing-value
1848 git interpret-trailers \
1849 --trailer added:added-value \
1850 --only-trailers >actual <<-\EOF &&
1855 existing: existing-value
1857 test_cmp expected actual
1860 test_expect_success
'only-trailers omits non-trailer in middle of block' '
1861 test_config trailer.sign.command "echo config-value" &&
1862 cat >expected <<-\EOF &&
1863 Signed-off-by: nobody <nobody@nowhere>
1864 Signed-off-by: somebody <somebody@somewhere>
1867 git interpret-trailers --only-trailers >actual <<-\EOF &&
1870 it is important that the trailers below are signed-off-by
1871 so that they meet the "25% trailers Git knows about" heuristic
1873 Signed-off-by: nobody <nobody@nowhere>
1874 this is not a trailer
1875 Signed-off-by: somebody <somebody@somewhere>
1877 test_cmp expected actual
1880 test_expect_success
'only input' '
1881 test_config trailer.sign.command "echo config-value" &&
1882 cat >expected <<-\EOF &&
1883 existing: existing-value
1885 git interpret-trailers \
1886 --only-trailers --only-input >actual <<-\EOF &&
1891 existing: existing-value
1893 test_cmp expected actual
1896 test_expect_success
'unfold' '
1897 cat >expected <<-\EOF &&
1898 foo: continued across several lines
1900 # pass through tr to make leading and trailing whitespace more obvious
1913 git interpret-trailers --only-trailers --only-input --unfold >actual &&
1914 test_cmp expected actual
1917 test_expect_success
'handling of --- lines in input' '
1918 echo "real-trailer: just right" >expected &&
1920 git interpret-trailers --parse >actual <<-\EOF &&
1925 not-a-trailer: too soon
1926 ------ this is just a line in the commit message with a bunch of
1927 ------ dashes; it does not have any syntactic meaning.
1929 real-trailer: just right
1931 below the dashed line may be a patch, etc.
1933 not-a-trailer: too late
1936 test_cmp expected actual
1939 test_expect_success
'suppress --- handling' '
1940 echo "real-trailer: just right" >expected &&
1942 git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1945 This commit message has a "---" in it, but because we tell
1946 interpret-trailers not to respect that, it has no effect.
1948 not-a-trailer: too soon
1951 This is still the commit message body.
1953 real-trailer: just right
1956 test_cmp expected actual
1959 test_expect_success
'suppressing --- does not disable cut-line handling' '
1960 echo "real-trailer: before the cut" >expected &&
1962 git interpret-trailers --parse --no-divider >actual <<-\EOF &&
1965 This input has a cut-line in it; we should stop parsing when we see it
1966 and consider only trailers before that line.
1968 real-trailer: before the cut
1970 # ------------------------ >8 ------------------------
1971 # Nothing below this line counts as part of the commit message.
1972 not-a-trailer: too late
1975 test_cmp expected actual
1978 test_expect_success
'handling of --- lines in conjunction with cut-lines' '
1979 echo "my-trailer: here" >expected &&
1981 git interpret-trailers --parse >actual <<-\EOF &&
1986 # ------------------------ >8 ------------------------
1989 test_cmp expected actual