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 config setup' '
130 git config trailer.ack.key "Acked-by: " &&
131 cat >expected <<-\EOF &&
135 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
136 test_cmp expected actual &&
137 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
138 test_cmp expected actual &&
139 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
140 test_cmp expected actual
143 test_expect_success
'with config setup and ":=" as separators' '
144 git config trailer.separators ":=" &&
145 git config trailer.ack.key "Acked-by= " &&
146 cat >expected <<-\EOF &&
150 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
151 test_cmp expected actual &&
152 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
153 test_cmp expected actual &&
154 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
155 test_cmp expected actual
158 test_expect_success
'with config setup and "%" as separators' '
159 git config trailer.separators "%" &&
160 cat >expected <<-\EOF &&
166 git interpret-trailers --trim-empty --trailer "bug = 42" \
167 --trailer count%10 --trailer "test: stuff" \
168 --trailer "bug % 422" empty >actual &&
169 test_cmp expected actual
172 test_expect_success
'with "%" as separators and a message with trailers' '
173 cat >special_message <<-\EOF &&
180 cat >expected <<-\EOF &&
188 git interpret-trailers --trailer count%100 \
189 special_message >actual &&
190 test_cmp expected actual
193 test_expect_success
'with config setup and ":=#" as separators' '
194 git config trailer.separators ":=#" &&
195 git config trailer.bug.key "Bug #" &&
196 cat >expected <<-\EOF &&
200 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
201 test_cmp expected actual
204 test_expect_success
'with commit basic message' '
205 cat basic_message >expected &&
207 git interpret-trailers <basic_message >actual &&
208 test_cmp expected actual
211 test_expect_success
'with basic patch' '
212 cat basic_message >input &&
213 cat basic_patch >>input &&
214 cat basic_message >expected &&
216 cat basic_patch >>expected &&
217 git interpret-trailers <input >actual &&
218 test_cmp expected actual
221 test_expect_success
'with commit complex message as argument' '
222 cat complex_message_body complex_message_trailers >complex_message &&
223 cat complex_message_body >expected &&
224 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
230 git interpret-trailers complex_message >actual &&
231 test_cmp expected actual
234 test_expect_success
'with 2 files arguments' '
235 cat basic_message >>expected &&
237 cat basic_patch >>expected &&
238 git interpret-trailers complex_message input >actual &&
239 test_cmp expected actual
242 test_expect_success
'with message that has comments' '
243 cat basic_message >message_with_comments &&
244 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
249 # yet another comment
255 cat basic_patch >>message_with_comments &&
256 cat basic_message >expected &&
257 cat >>expected <<-\EOF &&
265 cat basic_patch >>expected &&
266 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
267 test_cmp expected actual
270 test_expect_success
'with message that has an old style conflict block' '
271 cat basic_message >message_with_comments &&
272 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
277 # yet another comment
285 cat basic_message >expected &&
286 cat >>expected <<-\EOF &&
296 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
297 test_cmp expected actual
300 test_expect_success
'with commit complex message and trailer args' '
301 cat complex_message_body >expected &&
302 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
310 git interpret-trailers --trailer "ack: Peff" \
311 --trailer "bug: 42" <complex_message >actual &&
312 test_cmp expected actual
315 test_expect_success
'with complex patch, args and --trim-empty' '
316 cat complex_message >complex_patch &&
317 cat basic_patch >>complex_patch &&
318 cat complex_message_body >expected &&
319 cat >>expected <<-\EOF &&
323 cat basic_patch >>expected &&
324 git interpret-trailers --trim-empty --trailer "ack: Peff" \
325 --trailer "bug: 42" <complex_patch >actual &&
326 test_cmp expected actual
329 test_expect_success
'using "where = before"' '
330 git config trailer.bug.where "before" &&
331 cat complex_message_body >expected &&
332 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
340 git interpret-trailers --trailer "ack: Peff" \
341 --trailer "bug: 42" complex_message >actual &&
342 test_cmp expected actual
345 test_expect_success
'using "where = after"' '
346 git config trailer.ack.where "after" &&
347 cat complex_message_body >expected &&
348 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
356 git interpret-trailers --trailer "ack: Peff" \
357 --trailer "bug: 42" complex_message >actual &&
358 test_cmp expected actual
361 test_expect_success
'using "where = end"' '
362 git config trailer.review.key "Reviewed-by" &&
363 git config trailer.review.where "end" &&
364 cat complex_message_body >expected &&
365 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
372 Reviewed-by: Johannes
374 git interpret-trailers --trailer "ack: Peff" \
375 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
376 complex_message >actual &&
377 test_cmp expected actual
380 test_expect_success
'using "where = start"' '
381 git config trailer.review.key "Reviewed-by" &&
382 git config trailer.review.where "start" &&
383 cat complex_message_body >expected &&
384 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
385 Reviewed-by: Johannes
393 git interpret-trailers --trailer "ack: Peff" \
394 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
395 complex_message >actual &&
396 test_cmp expected actual
399 test_expect_success
'using "where = before" for a token in the middle of the message' '
400 git config trailer.review.key "Reviewed-by:" &&
401 git config trailer.review.where "before" &&
402 cat complex_message_body >expected &&
403 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
412 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
413 --trailer "review: Johan" <complex_message >actual &&
414 test_cmp expected actual
417 test_expect_success
'using "where = before" and --trim-empty' '
418 cat complex_message_body >expected &&
419 cat >>expected <<-\EOF &&
425 git interpret-trailers --trim-empty --trailer "ack: Peff" \
426 --trailer "bug: 42" --trailer "review: Johan" \
427 --trailer "Bug: 46" <complex_message >actual &&
428 test_cmp expected actual
431 test_expect_success
'the default is "ifExists = addIfDifferentNeighbor"' '
432 cat complex_message_body >expected &&
433 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
443 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
444 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
445 --trailer "ack: Peff" <complex_message >actual &&
446 test_cmp expected actual
449 test_expect_success
'default "ifExists" is now "addIfDifferent"' '
450 git config trailer.ifexists "addIfDifferent" &&
451 cat complex_message_body >expected &&
452 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
461 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
462 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
463 --trailer "ack: Peff" <complex_message >actual &&
464 test_cmp expected actual
467 test_expect_success
'using "ifExists = addIfDifferent" with "where = end"' '
468 git config trailer.ack.ifExists "addIfDifferent" &&
469 git config trailer.ack.where "end" &&
470 cat complex_message_body >expected &&
471 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
479 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
480 --trailer "bug: 42" --trailer "ack: Peff" \
481 <complex_message >actual &&
482 test_cmp expected actual
485 test_expect_success
'using "ifExists = addIfDifferent" with "where = before"' '
486 git config trailer.ack.ifExists "addIfDifferent" &&
487 git config trailer.ack.where "before" &&
488 cat complex_message_body >expected &&
489 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
497 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
498 --trailer "bug: 42" --trailer "ack: Peff" \
499 <complex_message >actual &&
500 test_cmp expected actual
503 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
504 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
505 git config trailer.ack.where "end" &&
506 cat complex_message_body >expected &&
507 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
519 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
520 --trailer "ack: Junio" --trailer "bug: 42" \
521 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
522 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
523 test_cmp expected actual
526 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
527 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
528 git config trailer.ack.where "after" &&
529 cat complex_message_body >expected &&
530 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
541 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
542 --trailer "ack: Junio" --trailer "bug: 42" \
543 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
544 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
545 test_cmp expected actual
548 test_expect_success
'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
549 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
550 cat complex_message_body >expected &&
551 cat >>expected <<-\EOF &&
557 git interpret-trailers --trim-empty --trailer "ack: Peff" \
558 --trailer "Acked-by= Peff" --trailer "review:" \
559 --trailer "ack: Junio" --trailer "bug: 42" \
560 --trailer "ack: Peff" <complex_message >actual &&
561 test_cmp expected actual
564 test_expect_success
'using "ifExists = add" with "where = end"' '
565 git config trailer.ack.ifExists "add" &&
566 git config trailer.ack.where "end" &&
567 cat complex_message_body >expected &&
568 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
581 git interpret-trailers --trailer "ack: Peff" \
582 --trailer "Acked-by= Peff" --trailer "review:" \
583 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
584 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
585 --trailer "ack: Peff" <complex_message >actual &&
586 test_cmp expected actual
589 test_expect_success
'using "ifExists = add" with "where = after"' '
590 git config trailer.ack.ifExists "add" &&
591 git config trailer.ack.where "after" &&
592 cat complex_message_body >expected &&
593 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
604 git interpret-trailers --trailer "ack: Peff" \
605 --trailer "Acked-by= Peff" --trailer "review:" \
606 --trailer "ack: Junio" --trailer "bug: 42" \
607 --trailer "ack: Peff" <complex_message >actual &&
608 test_cmp expected actual
611 test_expect_success
'using "ifExists = replace"' '
612 git config trailer.fix.key "Fixes: " &&
613 git config trailer.fix.ifExists "replace" &&
614 cat complex_message_body >expected &&
615 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
624 git interpret-trailers --trailer "review:" \
625 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
626 --trailer "bug: 42" --trailer "ack: Peff" \
627 <complex_message >actual &&
628 test_cmp expected actual
631 test_expect_success
'using "ifExists = replace" with "where = after"' '
632 git config trailer.fix.where "after" &&
633 cat complex_message_body >expected &&
634 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
643 git interpret-trailers --trailer "review:" \
644 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
645 --trailer "bug: 42" --trailer "ack: Peff" \
646 <complex_message >actual &&
647 test_cmp expected actual
650 test_expect_success
'using "ifExists = doNothing"' '
651 git config trailer.fix.ifExists "doNothing" &&
652 cat complex_message_body >expected &&
653 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
662 git interpret-trailers --trailer "review:" --trailer "fix=53" \
663 --trailer "ack: Junio" --trailer "fix=22" \
664 --trailer "bug: 42" --trailer "ack: Peff" \
665 <complex_message >actual &&
666 test_cmp expected actual
669 test_expect_success
'the default is "ifMissing = add"' '
670 git config trailer.cc.key "Cc: " &&
671 git config trailer.cc.where "before" &&
672 cat complex_message_body >expected &&
673 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
683 git interpret-trailers --trailer "review:" --trailer "fix=53" \
684 --trailer "cc=Linus" --trailer "ack: Junio" \
685 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
686 <complex_message >actual &&
687 test_cmp expected actual
690 test_expect_success
'when default "ifMissing" is "doNothing"' '
691 git config trailer.ifmissing "doNothing" &&
692 cat complex_message_body >expected &&
693 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
701 git interpret-trailers --trailer "review:" --trailer "fix=53" \
702 --trailer "cc=Linus" --trailer "ack: Junio" \
703 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
704 <complex_message >actual &&
705 test_cmp expected actual &&
706 git config trailer.ifmissing "add"
709 test_expect_success
'using "ifMissing = add" with "where = end"' '
710 git config trailer.cc.key "Cc: " &&
711 git config trailer.cc.where "end" &&
712 git config trailer.cc.ifMissing "add" &&
713 cat complex_message_body >expected &&
714 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
724 git interpret-trailers --trailer "review:" --trailer "fix=53" \
725 --trailer "ack: Junio" --trailer "fix=22" \
726 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
727 <complex_message >actual &&
728 test_cmp expected actual
731 test_expect_success
'using "ifMissing = add" with "where = before"' '
732 git config trailer.cc.key "Cc: " &&
733 git config trailer.cc.where "before" &&
734 git config trailer.cc.ifMissing "add" &&
735 cat complex_message_body >expected &&
736 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
746 git interpret-trailers --trailer "review:" --trailer "fix=53" \
747 --trailer "ack: Junio" --trailer "fix=22" \
748 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
749 <complex_message >actual &&
750 test_cmp expected actual
753 test_expect_success
'using "ifMissing = doNothing"' '
754 git config trailer.cc.ifMissing "doNothing" &&
755 cat complex_message_body >expected &&
756 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
765 git interpret-trailers --trailer "review:" --trailer "fix=53" \
766 --trailer "cc=Linus" --trailer "ack: Junio" \
767 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
768 <complex_message >actual &&
769 test_cmp expected actual
772 test_expect_success
'default "where" is now "after"' '
773 git config trailer.where "after" &&
774 git config --unset trailer.ack.where &&
775 cat complex_message_body >expected &&
776 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
789 git interpret-trailers --trailer "ack: Peff" \
790 --trailer "Acked-by= Peff" --trailer "review:" \
791 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
792 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
793 --trailer "ack: Peff" <complex_message >actual &&
794 test_cmp expected actual
797 test_expect_success
'with simple command' '
798 git config trailer.sign.key "Signed-off-by: " &&
799 git config trailer.sign.where "after" &&
800 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
801 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
802 cat complex_message_body >expected &&
803 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
808 Signed-off-by: A U Thor <author@example.com>
810 git interpret-trailers --trailer "review:" --trailer "fix=22" \
811 <complex_message >actual &&
812 test_cmp expected actual
815 test_expect_success
'with command using commiter information' '
816 git config trailer.sign.ifExists "addIfDifferent" &&
817 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
818 cat complex_message_body >expected &&
819 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
824 Signed-off-by: C O Mitter <committer@example.com>
826 git interpret-trailers --trailer "review:" --trailer "fix=22" \
827 <complex_message >actual &&
828 test_cmp expected actual
831 test_expect_success
'with command using author information' '
832 git config trailer.sign.key "Signed-off-by: " &&
833 git config trailer.sign.where "after" &&
834 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
835 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
836 cat complex_message_body >expected &&
837 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
842 Signed-off-by: A U Thor <author@example.com>
844 git interpret-trailers --trailer "review:" --trailer "fix=22" \
845 <complex_message >actual &&
846 test_cmp expected actual
849 test_expect_success
'setup a commit' '
850 echo "Content of the first commit." > a.txt &&
852 git commit -m "Add file a.txt"
855 test_expect_success
'with command using $ARG' '
856 git config trailer.fix.ifExists "replace" &&
857 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
858 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
859 cat complex_message_body >expected &&
860 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
865 Signed-off-by: A U Thor <author@example.com>
867 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
868 <complex_message >actual &&
869 test_cmp expected actual
872 test_expect_success
'with failing command using $ARG' '
873 git config trailer.fix.ifExists "replace" &&
874 git config trailer.fix.command "false \$ARG" &&
875 cat complex_message_body >expected &&
876 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
881 Signed-off-by: A U Thor <author@example.com>
883 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
884 <complex_message >actual &&
885 test_cmp expected actual
888 test_expect_success
'with empty tokens' '
889 git config --unset trailer.fix.command &&
890 cat >expected <<-EOF &&
892 Signed-off-by: A U Thor <author@example.com>
894 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
896 test_cmp expected actual
899 test_expect_success
'with command but no key' '
900 git config --unset trailer.sign.key &&
901 cat >expected <<-EOF &&
903 sign: A U Thor <author@example.com>
905 git interpret-trailers >actual <<-EOF &&
907 test_cmp expected actual
910 test_expect_success
'with no command and no key' '
911 git config --unset trailer.review.key &&
912 cat >expected <<-EOF &&
915 sign: A U Thor <author@example.com>
917 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
919 test_cmp expected actual