3 # Copyright (c) 2013, 2014 Christian Couder
6 test_description='git interpret-trailers'
10 # When we want one trailing space at the end of each line, let's use sed
11 # to make sure that these spaces are not removed by any automatic tool.
13 test_expect_success 'setup' '
15 cat >basic_message <<-\EOF &&
20 cat >complex_message_body <<-\EOF &&
24 and contains some special
28 sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF &&
34 cat >basic_patch <<-\EOF
37 1 file changed, 1 insertion(+), 1 deletion(-)
39 diff --git a/foo.txt b/foo.txt
40 index 0353767..1d91aa1 100644
54 test_expect_success 'without config' '
55 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
61 git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \
62 --trailer "Acked-by: Johan" empty >actual &&
63 test_cmp expected actual
66 test_expect_success 'without config in another order' '
67 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
73 git interpret-trailers --trailer "Acked-by: Johan" --trailer "Reviewed-by" \
74 --trailer "ack = Peff" empty >actual &&
75 test_cmp expected actual
78 test_expect_success '--trim-empty without config' '
79 cat >expected <<-\EOF &&
84 git interpret-trailers --trim-empty --trailer ack=Peff \
85 --trailer "Reviewed-by" --trailer "Acked-by: Johan" \
86 --trailer "sob:" empty >actual &&
87 test_cmp expected actual
90 test_expect_success 'with config option on the command line' '
91 cat >expected <<-\EOF &&
96 { echo; echo "Acked-by: Johan"; } |
97 git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
98 --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
99 test_cmp expected actual
102 test_expect_success 'with only a title in the message' '
103 cat >expected <<-\EOF &&
109 echo "area: change" |
110 git interpret-trailers --trailer "Reviewed-by: Peff" \
111 --trailer "Acked-by: Johan" >actual &&
112 test_cmp expected actual
115 test_expect_success 'with multiline title in the message' '
116 cat >expected <<-\EOF &&
123 printf "%s\n" "place of" "code: change" |
124 git interpret-trailers --trailer "Reviewed-by: Peff" \
125 --trailer "Acked-by: Johan" >actual &&
126 test_cmp expected actual
129 test_expect_success 'with non-trailer lines mixed with Signed-off-by' '
130 cat >patch <<-\EOF &&
132 this is not a trailer
133 this is not a trailer
134 Signed-off-by: a <a@example.com>
135 this is not a trailer
137 cat >expected <<-\EOF &&
139 this is not a trailer
140 this is not a trailer
141 Signed-off-by: a <a@example.com>
142 this is not a trailer
145 git interpret-trailers --trailer "token: value" patch >actual &&
146 test_cmp expected actual
149 test_expect_success 'with non-trailer lines mixed with cherry picked from' '
150 cat >patch <<-\EOF &&
152 this is not a trailer
153 this is not a trailer
154 (cherry picked from commit x)
155 this is not a trailer
157 cat >expected <<-\EOF &&
159 this is not a trailer
160 this is not a trailer
161 (cherry picked from commit x)
162 this is not a trailer
165 git interpret-trailers --trailer "token: value" patch >actual &&
166 test_cmp expected actual
169 test_expect_success 'with non-trailer lines mixed with a configured trailer' '
170 cat >patch <<-\EOF &&
172 this is not a trailer
173 this is not a trailer
175 this is not a trailer
177 cat >expected <<-\EOF &&
179 this is not a trailer
180 this is not a trailer
182 this is not a trailer
185 test_config trailer.my.key "My-trailer: " &&
186 git interpret-trailers --trailer "token: value" patch >actual &&
187 test_cmp expected actual
190 test_expect_success 'with non-trailer lines mixed with a non-configured trailer' '
191 cat >patch <<-\EOF &&
193 this is not a trailer
194 this is not a trailer
195 I-am-not-configured: x
196 this is not a trailer
198 cat >expected <<-\EOF &&
200 this is not a trailer
201 this is not a trailer
202 I-am-not-configured: x
203 this is not a trailer
207 test_config trailer.my.key "My-trailer: " &&
208 git interpret-trailers --trailer "token: value" patch >actual &&
209 test_cmp expected actual
212 test_expect_success 'with all non-configured trailers' '
213 cat >patch <<-\EOF &&
215 I-am-not-configured: x
216 I-am-also-not-configured: x
218 cat >expected <<-\EOF &&
220 I-am-not-configured: x
221 I-am-also-not-configured: x
224 test_config trailer.my.key "My-trailer: " &&
225 git interpret-trailers --trailer "token: value" patch >actual &&
226 test_cmp expected actual
229 test_expect_success 'with non-trailer lines only' '
230 cat >patch <<-\EOF &&
232 this is not a trailer
234 cat >expected <<-\EOF &&
236 this is not a trailer
240 git interpret-trailers --trailer "token: value" patch >actual &&
241 test_cmp expected actual
244 test_expect_success 'with config setup' '
245 git config trailer.ack.key "Acked-by: " &&
246 cat >expected <<-\EOF &&
250 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
251 test_cmp expected actual &&
252 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
253 test_cmp expected actual &&
254 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
255 test_cmp expected actual
258 test_expect_success 'with config setup and ":=" as separators' '
259 git config trailer.separators ":=" &&
260 git config trailer.ack.key "Acked-by= " &&
261 cat >expected <<-\EOF &&
265 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
266 test_cmp expected actual &&
267 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
268 test_cmp expected actual &&
269 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
270 test_cmp expected actual
273 test_expect_success 'with config setup and "%" as separators' '
274 git config trailer.separators "%" &&
275 cat >expected <<-\EOF &&
281 git interpret-trailers --trim-empty --trailer "bug = 42" \
282 --trailer count%10 --trailer "test: stuff" \
283 --trailer "bug % 422" empty >actual &&
284 test_cmp expected actual
287 test_expect_success 'with "%" as separators and a message with trailers' '
288 cat >special_message <<-\EOF &&
295 cat >expected <<-\EOF &&
303 git interpret-trailers --trailer count%100 \
304 special_message >actual &&
305 test_cmp expected actual
308 test_expect_success 'with config setup and ":=#" as separators' '
309 git config trailer.separators ":=#" &&
310 git config trailer.bug.key "Bug #" &&
311 cat >expected <<-\EOF &&
315 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
316 test_cmp expected actual
319 test_expect_success 'with commit basic message' '
320 cat basic_message >expected &&
322 git interpret-trailers <basic_message >actual &&
323 test_cmp expected actual
326 test_expect_success 'with basic patch' '
327 cat basic_message >input &&
328 cat basic_patch >>input &&
329 cat basic_message >expected &&
331 cat basic_patch >>expected &&
332 git interpret-trailers <input >actual &&
333 test_cmp expected actual
336 test_expect_success 'with commit complex message as argument' '
337 cat complex_message_body complex_message_trailers >complex_message &&
338 cat complex_message_body >expected &&
339 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
345 git interpret-trailers complex_message >actual &&
346 test_cmp expected actual
349 test_expect_success 'with 2 files arguments' '
350 cat basic_message >>expected &&
352 cat basic_patch >>expected &&
353 git interpret-trailers complex_message input >actual &&
354 test_cmp expected actual
357 test_expect_success 'with message that has comments' '
358 cat basic_message >message_with_comments &&
359 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
364 # yet another comment
370 cat basic_patch >>message_with_comments &&
371 cat basic_message >expected &&
372 cat >>expected <<-\EOF &&
380 cat basic_patch >>expected &&
381 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
382 test_cmp expected actual
385 test_expect_success 'with message that has an old style conflict block' '
386 cat basic_message >message_with_comments &&
387 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
392 # yet another comment
400 cat basic_message >expected &&
401 cat >>expected <<-\EOF &&
411 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
412 test_cmp expected actual
415 test_expect_success 'with commit complex message and trailer args' '
416 cat complex_message_body >expected &&
417 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
425 git interpret-trailers --trailer "ack: Peff" \
426 --trailer "bug: 42" <complex_message >actual &&
427 test_cmp expected actual
430 test_expect_success 'with complex patch, args and --trim-empty' '
431 cat complex_message >complex_patch &&
432 cat basic_patch >>complex_patch &&
433 cat complex_message_body >expected &&
434 cat >>expected <<-\EOF &&
438 cat basic_patch >>expected &&
439 git interpret-trailers --trim-empty --trailer "ack: Peff" \
440 --trailer "bug: 42" <complex_patch >actual &&
441 test_cmp expected actual
444 test_expect_success 'in-place editing with basic patch' '
445 cat basic_message >message &&
446 cat basic_patch >>message &&
447 cat basic_message >expected &&
449 cat basic_patch >>expected &&
450 git interpret-trailers --in-place message &&
451 test_cmp expected message
454 test_expect_success 'in-place editing with additional trailer' '
455 cat basic_message >message &&
456 cat basic_patch >>message &&
457 cat basic_message >expected &&
459 cat >>expected <<-\EOF &&
462 cat basic_patch >>expected &&
463 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
464 test_cmp expected message
467 test_expect_success 'in-place editing on stdin disallowed' '
468 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
471 test_expect_success 'in-place editing on non-existing file' '
472 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
473 test_path_is_missing nonexisting
476 test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" '
477 cat basic_message >message &&
479 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
481 test_cmp message basic_message
484 test_expect_success 'using "where = before"' '
485 git config trailer.bug.where "before" &&
486 cat complex_message_body >expected &&
487 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
495 git interpret-trailers --trailer "ack: Peff" \
496 --trailer "bug: 42" complex_message >actual &&
497 test_cmp expected actual
500 test_expect_success 'using "where = after"' '
501 git config trailer.ack.where "after" &&
502 cat complex_message_body >expected &&
503 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
511 git interpret-trailers --trailer "ack: Peff" \
512 --trailer "bug: 42" complex_message >actual &&
513 test_cmp expected actual
516 test_expect_success 'using "where = end"' '
517 git config trailer.review.key "Reviewed-by" &&
518 git config trailer.review.where "end" &&
519 cat complex_message_body >expected &&
520 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
527 Reviewed-by: Johannes
529 git interpret-trailers --trailer "ack: Peff" \
530 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
531 complex_message >actual &&
532 test_cmp expected actual
535 test_expect_success 'using "where = start"' '
536 git config trailer.review.key "Reviewed-by" &&
537 git config trailer.review.where "start" &&
538 cat complex_message_body >expected &&
539 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
540 Reviewed-by: Johannes
548 git interpret-trailers --trailer "ack: Peff" \
549 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
550 complex_message >actual &&
551 test_cmp expected actual
554 test_expect_success 'using "where = before" for a token in the middle of the message' '
555 git config trailer.review.key "Reviewed-by:" &&
556 git config trailer.review.where "before" &&
557 cat complex_message_body >expected &&
558 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
567 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
568 --trailer "review: Johan" <complex_message >actual &&
569 test_cmp expected actual
572 test_expect_success 'using "where = before" and --trim-empty' '
573 cat complex_message_body >expected &&
574 cat >>expected <<-\EOF &&
580 git interpret-trailers --trim-empty --trailer "ack: Peff" \
581 --trailer "bug: 42" --trailer "review: Johan" \
582 --trailer "Bug: 46" <complex_message >actual &&
583 test_cmp expected actual
586 test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
587 cat complex_message_body >expected &&
588 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
598 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
599 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
600 --trailer "ack: Peff" <complex_message >actual &&
601 test_cmp expected actual
604 test_expect_success 'default "ifExists" is now "addIfDifferent"' '
605 git config trailer.ifexists "addIfDifferent" &&
606 cat complex_message_body >expected &&
607 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
616 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
617 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
618 --trailer "ack: Peff" <complex_message >actual &&
619 test_cmp expected actual
622 test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
623 git config trailer.ack.ifExists "addIfDifferent" &&
624 git config trailer.ack.where "end" &&
625 cat complex_message_body >expected &&
626 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
634 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
635 --trailer "bug: 42" --trailer "ack: Peff" \
636 <complex_message >actual &&
637 test_cmp expected actual
640 test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
641 git config trailer.ack.ifExists "addIfDifferent" &&
642 git config trailer.ack.where "before" &&
643 cat complex_message_body >expected &&
644 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
652 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
653 --trailer "bug: 42" --trailer "ack: Peff" \
654 <complex_message >actual &&
655 test_cmp expected actual
658 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
659 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
660 git config trailer.ack.where "end" &&
661 cat complex_message_body >expected &&
662 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
674 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
675 --trailer "ack: Junio" --trailer "bug: 42" \
676 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
677 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
678 test_cmp expected actual
681 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
682 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
683 git config trailer.ack.where "after" &&
684 cat complex_message_body >expected &&
685 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
696 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
697 --trailer "ack: Junio" --trailer "bug: 42" \
698 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
699 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
700 test_cmp expected actual
703 test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
704 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
705 cat complex_message_body >expected &&
706 cat >>expected <<-\EOF &&
712 git interpret-trailers --trim-empty --trailer "ack: Peff" \
713 --trailer "Acked-by= Peff" --trailer "review:" \
714 --trailer "ack: Junio" --trailer "bug: 42" \
715 --trailer "ack: Peff" <complex_message >actual &&
716 test_cmp expected actual
719 test_expect_success 'using "ifExists = add" with "where = end"' '
720 git config trailer.ack.ifExists "add" &&
721 git config trailer.ack.where "end" &&
722 cat complex_message_body >expected &&
723 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
736 git interpret-trailers --trailer "ack: Peff" \
737 --trailer "Acked-by= Peff" --trailer "review:" \
738 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
739 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
740 --trailer "ack: Peff" <complex_message >actual &&
741 test_cmp expected actual
744 test_expect_success 'using "ifExists = add" with "where = after"' '
745 git config trailer.ack.ifExists "add" &&
746 git config trailer.ack.where "after" &&
747 cat complex_message_body >expected &&
748 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
759 git interpret-trailers --trailer "ack: Peff" \
760 --trailer "Acked-by= Peff" --trailer "review:" \
761 --trailer "ack: Junio" --trailer "bug: 42" \
762 --trailer "ack: Peff" <complex_message >actual &&
763 test_cmp expected actual
766 test_expect_success 'using "ifExists = replace"' '
767 git config trailer.fix.key "Fixes: " &&
768 git config trailer.fix.ifExists "replace" &&
769 cat complex_message_body >expected &&
770 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
779 git interpret-trailers --trailer "review:" \
780 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
781 --trailer "bug: 42" --trailer "ack: Peff" \
782 <complex_message >actual &&
783 test_cmp expected actual
786 test_expect_success 'using "ifExists = replace" with "where = after"' '
787 git config trailer.fix.where "after" &&
788 cat complex_message_body >expected &&
789 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
798 git interpret-trailers --trailer "review:" \
799 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
800 --trailer "bug: 42" --trailer "ack: Peff" \
801 <complex_message >actual &&
802 test_cmp expected actual
805 test_expect_success 'using "ifExists = doNothing"' '
806 git config trailer.fix.ifExists "doNothing" &&
807 cat complex_message_body >expected &&
808 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
817 git interpret-trailers --trailer "review:" --trailer "fix=53" \
818 --trailer "ack: Junio" --trailer "fix=22" \
819 --trailer "bug: 42" --trailer "ack: Peff" \
820 <complex_message >actual &&
821 test_cmp expected actual
824 test_expect_success 'the default is "ifMissing = add"' '
825 git config trailer.cc.key "Cc: " &&
826 git config trailer.cc.where "before" &&
827 cat complex_message_body >expected &&
828 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
838 git interpret-trailers --trailer "review:" --trailer "fix=53" \
839 --trailer "cc=Linus" --trailer "ack: Junio" \
840 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
841 <complex_message >actual &&
842 test_cmp expected actual
845 test_expect_success 'when default "ifMissing" is "doNothing"' '
846 git config trailer.ifmissing "doNothing" &&
847 cat complex_message_body >expected &&
848 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
856 git interpret-trailers --trailer "review:" --trailer "fix=53" \
857 --trailer "cc=Linus" --trailer "ack: Junio" \
858 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
859 <complex_message >actual &&
860 test_cmp expected actual &&
861 git config trailer.ifmissing "add"
864 test_expect_success 'using "ifMissing = add" with "where = end"' '
865 git config trailer.cc.key "Cc: " &&
866 git config trailer.cc.where "end" &&
867 git config trailer.cc.ifMissing "add" &&
868 cat complex_message_body >expected &&
869 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
879 git interpret-trailers --trailer "review:" --trailer "fix=53" \
880 --trailer "ack: Junio" --trailer "fix=22" \
881 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
882 <complex_message >actual &&
883 test_cmp expected actual
886 test_expect_success 'using "ifMissing = add" with "where = before"' '
887 git config trailer.cc.key "Cc: " &&
888 git config trailer.cc.where "before" &&
889 git config trailer.cc.ifMissing "add" &&
890 cat complex_message_body >expected &&
891 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
901 git interpret-trailers --trailer "review:" --trailer "fix=53" \
902 --trailer "ack: Junio" --trailer "fix=22" \
903 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
904 <complex_message >actual &&
905 test_cmp expected actual
908 test_expect_success 'using "ifMissing = doNothing"' '
909 git config trailer.cc.ifMissing "doNothing" &&
910 cat complex_message_body >expected &&
911 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
920 git interpret-trailers --trailer "review:" --trailer "fix=53" \
921 --trailer "cc=Linus" --trailer "ack: Junio" \
922 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
923 <complex_message >actual &&
924 test_cmp expected actual
927 test_expect_success 'default "where" is now "after"' '
928 git config trailer.where "after" &&
929 git config --unset trailer.ack.where &&
930 cat complex_message_body >expected &&
931 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
944 git interpret-trailers --trailer "ack: Peff" \
945 --trailer "Acked-by= Peff" --trailer "review:" \
946 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
947 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
948 --trailer "ack: Peff" <complex_message >actual &&
949 test_cmp expected actual
952 test_expect_success 'with simple command' '
953 git config trailer.sign.key "Signed-off-by: " &&
954 git config trailer.sign.where "after" &&
955 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
956 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
957 cat complex_message_body >expected &&
958 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
963 Signed-off-by: A U Thor <author@example.com>
965 git interpret-trailers --trailer "review:" --trailer "fix=22" \
966 <complex_message >actual &&
967 test_cmp expected actual
970 test_expect_success 'with command using commiter information' '
971 git config trailer.sign.ifExists "addIfDifferent" &&
972 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
973 cat complex_message_body >expected &&
974 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
979 Signed-off-by: C O Mitter <committer@example.com>
981 git interpret-trailers --trailer "review:" --trailer "fix=22" \
982 <complex_message >actual &&
983 test_cmp expected actual
986 test_expect_success 'with command using author information' '
987 git config trailer.sign.key "Signed-off-by: " &&
988 git config trailer.sign.where "after" &&
989 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
990 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
991 cat complex_message_body >expected &&
992 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
997 Signed-off-by: A U Thor <author@example.com>
999 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1000 <complex_message >actual &&
1001 test_cmp expected actual
1004 test_expect_success 'setup a commit' '
1005 echo "Content of the first commit." > a.txt &&
1007 git commit -m "Add file a.txt"
1010 test_expect_success 'with command using $ARG' '
1011 git config trailer.fix.ifExists "replace" &&
1012 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1013 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1014 cat complex_message_body >expected &&
1015 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1020 Signed-off-by: A U Thor <author@example.com>
1022 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1023 <complex_message >actual &&
1024 test_cmp expected actual
1027 test_expect_success 'with failing command using $ARG' '
1028 git config trailer.fix.ifExists "replace" &&
1029 git config trailer.fix.command "false \$ARG" &&
1030 cat complex_message_body >expected &&
1031 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1036 Signed-off-by: A U Thor <author@example.com>
1038 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1039 <complex_message >actual &&
1040 test_cmp expected actual
1043 test_expect_success 'with empty tokens' '
1044 git config --unset trailer.fix.command &&
1045 cat >expected <<-EOF &&
1047 Signed-off-by: A U Thor <author@example.com>
1049 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1051 test_cmp expected actual
1054 test_expect_success 'with command but no key' '
1055 git config --unset trailer.sign.key &&
1056 cat >expected <<-EOF &&
1058 sign: A U Thor <author@example.com>
1060 git interpret-trailers >actual <<-EOF &&
1062 test_cmp expected actual
1065 test_expect_success 'with no command and no key' '
1066 git config --unset trailer.review.key &&
1067 cat >expected <<-EOF &&
1070 sign: A U Thor <author@example.com>
1072 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1074 test_cmp expected actual