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 "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 config setup' '
103 git config trailer.ack.key "Acked-by: " &&
104 cat >expected <<-\EOF &&
108 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
109 test_cmp expected actual &&
110 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
111 test_cmp expected actual &&
112 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
113 test_cmp expected actual
116 test_expect_success 'with config setup and ":=" as separators' '
117 git config trailer.separators ":=" &&
118 git config trailer.ack.key "Acked-by= " &&
119 cat >expected <<-\EOF &&
123 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
124 test_cmp expected actual &&
125 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
126 test_cmp expected actual &&
127 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
128 test_cmp expected actual
131 test_expect_success 'with config setup and "%" as separators' '
132 git config trailer.separators "%" &&
133 cat >expected <<-\EOF &&
139 git interpret-trailers --trim-empty --trailer "bug = 42" \
140 --trailer count%10 --trailer "test: stuff" \
141 --trailer "bug % 422" empty >actual &&
142 test_cmp expected actual
145 test_expect_success 'with "%" as separators and a message with trailers' '
146 cat >special_message <<-\EOF &&
153 cat >expected <<-\EOF &&
161 git interpret-trailers --trailer count%100 \
162 special_message >actual &&
163 test_cmp expected actual
166 test_expect_success 'with config setup and ":=#" as separators' '
167 git config trailer.separators ":=#" &&
168 git config trailer.bug.key "Bug #" &&
169 cat >expected <<-\EOF &&
173 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
174 test_cmp expected actual
177 test_expect_success 'with commit basic message' '
178 cat basic_message >expected &&
180 git interpret-trailers <basic_message >actual &&
181 test_cmp expected actual
184 test_expect_success 'with basic patch' '
185 cat basic_message >input &&
186 cat basic_patch >>input &&
187 cat basic_message >expected &&
189 cat basic_patch >>expected &&
190 git interpret-trailers <input >actual &&
191 test_cmp expected actual
194 test_expect_success 'with commit complex message as argument' '
195 cat complex_message_body complex_message_trailers >complex_message &&
196 cat complex_message_body >expected &&
197 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
203 git interpret-trailers complex_message >actual &&
204 test_cmp expected actual
207 test_expect_success 'with 2 files arguments' '
208 cat basic_message >>expected &&
210 cat basic_patch >>expected &&
211 git interpret-trailers complex_message input >actual &&
212 test_cmp expected actual
215 test_expect_success 'with message that has comments' '
216 cat basic_message >message_with_comments &&
217 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
222 # yet another comment
228 cat basic_patch >>message_with_comments &&
229 cat basic_message >expected &&
230 cat >>expected <<-\EOF &&
238 cat basic_patch >>expected &&
239 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
240 test_cmp expected actual
243 test_expect_success 'with message that has an old style conflict block' '
244 cat basic_message >message_with_comments &&
245 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
250 # yet another comment
258 cat basic_message >expected &&
259 cat >>expected <<-\EOF &&
269 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
270 test_cmp expected actual
273 test_expect_success 'with commit complex message and trailer args' '
274 cat complex_message_body >expected &&
275 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
283 git interpret-trailers --trailer "ack: Peff" \
284 --trailer "bug: 42" <complex_message >actual &&
285 test_cmp expected actual
288 test_expect_success 'with complex patch, args and --trim-empty' '
289 cat complex_message >complex_patch &&
290 cat basic_patch >>complex_patch &&
291 cat complex_message_body >expected &&
292 cat >>expected <<-\EOF &&
296 cat basic_patch >>expected &&
297 git interpret-trailers --trim-empty --trailer "ack: Peff" \
298 --trailer "bug: 42" <complex_patch >actual &&
299 test_cmp expected actual
302 test_expect_success 'using "where = before"' '
303 git config trailer.bug.where "before" &&
304 cat complex_message_body >expected &&
305 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
313 git interpret-trailers --trailer "ack: Peff" \
314 --trailer "bug: 42" complex_message >actual &&
315 test_cmp expected actual
318 test_expect_success 'using "where = after"' '
319 git config trailer.ack.where "after" &&
320 cat complex_message_body >expected &&
321 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
329 git interpret-trailers --trailer "ack: Peff" \
330 --trailer "bug: 42" complex_message >actual &&
331 test_cmp expected actual
334 test_expect_success 'using "where = end"' '
335 git config trailer.review.key "Reviewed-by" &&
336 git config trailer.review.where "end" &&
337 cat complex_message_body >expected &&
338 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
345 Reviewed-by: Johannes
347 git interpret-trailers --trailer "ack: Peff" \
348 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
349 complex_message >actual &&
350 test_cmp expected actual
353 test_expect_success 'using "where = start"' '
354 git config trailer.review.key "Reviewed-by" &&
355 git config trailer.review.where "start" &&
356 cat complex_message_body >expected &&
357 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
358 Reviewed-by: Johannes
366 git interpret-trailers --trailer "ack: Peff" \
367 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
368 complex_message >actual &&
369 test_cmp expected actual
372 test_expect_success 'using "where = before" for a token in the middle of the message' '
373 git config trailer.review.key "Reviewed-by:" &&
374 git config trailer.review.where "before" &&
375 cat complex_message_body >expected &&
376 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
385 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
386 --trailer "review: Johan" <complex_message >actual &&
387 test_cmp expected actual
390 test_expect_success 'using "where = before" and --trim-empty' '
391 cat complex_message_body >expected &&
392 cat >>expected <<-\EOF &&
398 git interpret-trailers --trim-empty --trailer "ack: Peff" \
399 --trailer "bug: 42" --trailer "review: Johan" \
400 --trailer "Bug: 46" <complex_message >actual &&
401 test_cmp expected actual
404 test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
405 cat complex_message_body >expected &&
406 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
416 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
417 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
418 --trailer "ack: Peff" <complex_message >actual &&
419 test_cmp expected actual
422 test_expect_success 'default "ifExists" is now "addIfDifferent"' '
423 git config trailer.ifexists "addIfDifferent" &&
424 cat complex_message_body >expected &&
425 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
434 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
435 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
436 --trailer "ack: Peff" <complex_message >actual &&
437 test_cmp expected actual
440 test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
441 git config trailer.ack.ifExists "addIfDifferent" &&
442 git config trailer.ack.where "end" &&
443 cat complex_message_body >expected &&
444 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
452 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
453 --trailer "bug: 42" --trailer "ack: Peff" \
454 <complex_message >actual &&
455 test_cmp expected actual
458 test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
459 git config trailer.ack.ifExists "addIfDifferent" &&
460 git config trailer.ack.where "before" &&
461 cat complex_message_body >expected &&
462 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
470 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
471 --trailer "bug: 42" --trailer "ack: Peff" \
472 <complex_message >actual &&
473 test_cmp expected actual
476 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
477 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
478 git config trailer.ack.where "end" &&
479 cat complex_message_body >expected &&
480 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
492 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
493 --trailer "ack: Junio" --trailer "bug: 42" \
494 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
495 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
496 test_cmp expected actual
499 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
500 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
501 git config trailer.ack.where "after" &&
502 cat complex_message_body >expected &&
503 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
514 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
515 --trailer "ack: Junio" --trailer "bug: 42" \
516 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
517 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
518 test_cmp expected actual
521 test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
522 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
523 cat complex_message_body >expected &&
524 cat >>expected <<-\EOF &&
530 git interpret-trailers --trim-empty --trailer "ack: Peff" \
531 --trailer "Acked-by= Peff" --trailer "review:" \
532 --trailer "ack: Junio" --trailer "bug: 42" \
533 --trailer "ack: Peff" <complex_message >actual &&
534 test_cmp expected actual
537 test_expect_success 'using "ifExists = add" with "where = end"' '
538 git config trailer.ack.ifExists "add" &&
539 git config trailer.ack.where "end" &&
540 cat complex_message_body >expected &&
541 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
554 git interpret-trailers --trailer "ack: Peff" \
555 --trailer "Acked-by= Peff" --trailer "review:" \
556 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
557 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
558 --trailer "ack: Peff" <complex_message >actual &&
559 test_cmp expected actual
562 test_expect_success 'using "ifExists = add" with "where = after"' '
563 git config trailer.ack.ifExists "add" &&
564 git config trailer.ack.where "after" &&
565 cat complex_message_body >expected &&
566 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
577 git interpret-trailers --trailer "ack: Peff" \
578 --trailer "Acked-by= Peff" --trailer "review:" \
579 --trailer "ack: Junio" --trailer "bug: 42" \
580 --trailer "ack: Peff" <complex_message >actual &&
581 test_cmp expected actual
584 test_expect_success 'using "ifExists = replace"' '
585 git config trailer.fix.key "Fixes: " &&
586 git config trailer.fix.ifExists "replace" &&
587 cat complex_message_body >expected &&
588 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
597 git interpret-trailers --trailer "review:" \
598 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
599 --trailer "bug: 42" --trailer "ack: Peff" \
600 <complex_message >actual &&
601 test_cmp expected actual
604 test_expect_success 'using "ifExists = replace" with "where = after"' '
605 git config trailer.fix.where "after" &&
606 cat complex_message_body >expected &&
607 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
616 git interpret-trailers --trailer "review:" \
617 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
618 --trailer "bug: 42" --trailer "ack: Peff" \
619 <complex_message >actual &&
620 test_cmp expected actual
623 test_expect_success 'using "ifExists = doNothing"' '
624 git config trailer.fix.ifExists "doNothing" &&
625 cat complex_message_body >expected &&
626 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
635 git interpret-trailers --trailer "review:" --trailer "fix=53" \
636 --trailer "ack: Junio" --trailer "fix=22" \
637 --trailer "bug: 42" --trailer "ack: Peff" \
638 <complex_message >actual &&
639 test_cmp expected actual
642 test_expect_success 'the default is "ifMissing = add"' '
643 git config trailer.cc.key "Cc: " &&
644 git config trailer.cc.where "before" &&
645 cat complex_message_body >expected &&
646 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
656 git interpret-trailers --trailer "review:" --trailer "fix=53" \
657 --trailer "cc=Linus" --trailer "ack: Junio" \
658 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
659 <complex_message >actual &&
660 test_cmp expected actual
663 test_expect_success 'when default "ifMissing" is "doNothing"' '
664 git config trailer.ifmissing "doNothing" &&
665 cat complex_message_body >expected &&
666 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
674 git interpret-trailers --trailer "review:" --trailer "fix=53" \
675 --trailer "cc=Linus" --trailer "ack: Junio" \
676 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
677 <complex_message >actual &&
678 test_cmp expected actual &&
679 git config trailer.ifmissing "add"
682 test_expect_success 'using "ifMissing = add" with "where = end"' '
683 git config trailer.cc.key "Cc: " &&
684 git config trailer.cc.where "end" &&
685 git config trailer.cc.ifMissing "add" &&
686 cat complex_message_body >expected &&
687 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
697 git interpret-trailers --trailer "review:" --trailer "fix=53" \
698 --trailer "ack: Junio" --trailer "fix=22" \
699 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
700 <complex_message >actual &&
701 test_cmp expected actual
704 test_expect_success 'using "ifMissing = add" with "where = before"' '
705 git config trailer.cc.key "Cc: " &&
706 git config trailer.cc.where "before" &&
707 git config trailer.cc.ifMissing "add" &&
708 cat complex_message_body >expected &&
709 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
719 git interpret-trailers --trailer "review:" --trailer "fix=53" \
720 --trailer "ack: Junio" --trailer "fix=22" \
721 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
722 <complex_message >actual &&
723 test_cmp expected actual
726 test_expect_success 'using "ifMissing = doNothing"' '
727 git config trailer.cc.ifMissing "doNothing" &&
728 cat complex_message_body >expected &&
729 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
738 git interpret-trailers --trailer "review:" --trailer "fix=53" \
739 --trailer "cc=Linus" --trailer "ack: Junio" \
740 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
741 <complex_message >actual &&
742 test_cmp expected actual
745 test_expect_success 'default "where" is now "after"' '
746 git config trailer.where "after" &&
747 git config --unset trailer.ack.where &&
748 cat complex_message_body >expected &&
749 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
762 git interpret-trailers --trailer "ack: Peff" \
763 --trailer "Acked-by= Peff" --trailer "review:" \
764 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
765 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
766 --trailer "ack: Peff" <complex_message >actual &&
767 test_cmp expected actual
770 test_expect_success 'with simple command' '
771 git config trailer.sign.key "Signed-off-by: " &&
772 git config trailer.sign.where "after" &&
773 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
774 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
775 cat complex_message_body >expected &&
776 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
781 Signed-off-by: A U Thor <author@example.com>
783 git interpret-trailers --trailer "review:" --trailer "fix=22" \
784 <complex_message >actual &&
785 test_cmp expected actual
788 test_expect_success 'with command using commiter information' '
789 git config trailer.sign.ifExists "addIfDifferent" &&
790 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
791 cat complex_message_body >expected &&
792 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
797 Signed-off-by: C O Mitter <committer@example.com>
799 git interpret-trailers --trailer "review:" --trailer "fix=22" \
800 <complex_message >actual &&
801 test_cmp expected actual
804 test_expect_success 'with command using author information' '
805 git config trailer.sign.key "Signed-off-by: " &&
806 git config trailer.sign.where "after" &&
807 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
808 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
809 cat complex_message_body >expected &&
810 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
815 Signed-off-by: A U Thor <author@example.com>
817 git interpret-trailers --trailer "review:" --trailer "fix=22" \
818 <complex_message >actual &&
819 test_cmp expected actual
822 test_expect_success 'setup a commit' '
823 echo "Content of the first commit." > a.txt &&
825 git commit -m "Add file a.txt"
828 test_expect_success 'with command using $ARG' '
829 git config trailer.fix.ifExists "replace" &&
830 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
831 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
832 cat complex_message_body >expected &&
833 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
838 Signed-off-by: A U Thor <author@example.com>
840 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
841 <complex_message >actual &&
842 test_cmp expected actual
845 test_expect_success 'with failing command using $ARG' '
846 git config trailer.fix.ifExists "replace" &&
847 git config trailer.fix.command "false \$ARG" &&
848 cat complex_message_body >expected &&
849 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
854 Signed-off-by: A U Thor <author@example.com>
856 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
857 <complex_message >actual &&
858 test_cmp expected actual
861 test_expect_success 'with empty tokens' '
862 git config --unset trailer.fix.command &&
863 cat >expected <<-EOF &&
865 Signed-off-by: A U Thor <author@example.com>
867 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
869 test_cmp expected actual
872 test_expect_success 'with command but no key' '
873 git config --unset trailer.sign.key &&
874 cat >expected <<-EOF &&
876 sign: A U Thor <author@example.com>
878 git interpret-trailers >actual <<-EOF &&
880 test_cmp expected actual
883 test_expect_success 'with no command and no key' '
884 git config --unset trailer.review.key &&
885 cat >expected <<-EOF &&
888 sign: A U Thor <author@example.com>
890 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
892 test_cmp expected actual