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 &&
236 cat basic_patch >>expected &&
237 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
238 test_cmp expected actual
241 test_expect_success
'with commit complex message and trailer args' '
242 cat complex_message_body >expected &&
243 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
251 git interpret-trailers --trailer "ack: Peff" \
252 --trailer "bug: 42" <complex_message >actual &&
253 test_cmp expected actual
256 test_expect_success
'with complex patch, args and --trim-empty' '
257 cat complex_message >complex_patch &&
258 cat basic_patch >>complex_patch &&
259 cat complex_message_body >expected &&
260 cat >>expected <<-\EOF &&
264 cat basic_patch >>expected &&
265 git interpret-trailers --trim-empty --trailer "ack: Peff" \
266 --trailer "bug: 42" <complex_patch >actual &&
267 test_cmp expected actual
270 test_expect_success
'using "where = before"' '
271 git config trailer.bug.where "before" &&
272 cat complex_message_body >expected &&
273 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
281 git interpret-trailers --trailer "ack: Peff" \
282 --trailer "bug: 42" complex_message >actual &&
283 test_cmp expected actual
286 test_expect_success
'using "where = after"' '
287 git config trailer.ack.where "after" &&
288 cat complex_message_body >expected &&
289 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
297 git interpret-trailers --trailer "ack: Peff" \
298 --trailer "bug: 42" complex_message >actual &&
299 test_cmp expected actual
302 test_expect_success
'using "where = end"' '
303 git config trailer.review.key "Reviewed-by" &&
304 git config trailer.review.where "end" &&
305 cat complex_message_body >expected &&
306 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
313 Reviewed-by: Johannes
315 git interpret-trailers --trailer "ack: Peff" \
316 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
317 complex_message >actual &&
318 test_cmp expected actual
321 test_expect_success
'using "where = start"' '
322 git config trailer.review.key "Reviewed-by" &&
323 git config trailer.review.where "start" &&
324 cat complex_message_body >expected &&
325 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
326 Reviewed-by: Johannes
334 git interpret-trailers --trailer "ack: Peff" \
335 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
336 complex_message >actual &&
337 test_cmp expected actual
340 test_expect_success
'using "where = before" for a token in the middle of the message' '
341 git config trailer.review.key "Reviewed-by:" &&
342 git config trailer.review.where "before" &&
343 cat complex_message_body >expected &&
344 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
353 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
354 --trailer "review: Johan" <complex_message >actual &&
355 test_cmp expected actual
358 test_expect_success
'using "where = before" and --trim-empty' '
359 cat complex_message_body >expected &&
360 cat >>expected <<-\EOF &&
366 git interpret-trailers --trim-empty --trailer "ack: Peff" \
367 --trailer "bug: 42" --trailer "review: Johan" \
368 --trailer "Bug: 46" <complex_message >actual &&
369 test_cmp expected actual
372 test_expect_success
'the default is "ifExists = addIfDifferentNeighbor"' '
373 cat complex_message_body >expected &&
374 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
384 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
385 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
386 --trailer "ack: Peff" <complex_message >actual &&
387 test_cmp expected actual
390 test_expect_success
'default "ifExists" is now "addIfDifferent"' '
391 git config trailer.ifexists "addIfDifferent" &&
392 cat complex_message_body >expected &&
393 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
402 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
403 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
404 --trailer "ack: Peff" <complex_message >actual &&
405 test_cmp expected actual
408 test_expect_success
'using "ifExists = addIfDifferent" with "where = end"' '
409 git config trailer.ack.ifExists "addIfDifferent" &&
410 git config trailer.ack.where "end" &&
411 cat complex_message_body >expected &&
412 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
420 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
421 --trailer "bug: 42" --trailer "ack: Peff" \
422 <complex_message >actual &&
423 test_cmp expected actual
426 test_expect_success
'using "ifExists = addIfDifferent" with "where = before"' '
427 git config trailer.ack.ifExists "addIfDifferent" &&
428 git config trailer.ack.where "before" &&
429 cat complex_message_body >expected &&
430 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
438 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
439 --trailer "bug: 42" --trailer "ack: Peff" \
440 <complex_message >actual &&
441 test_cmp expected actual
444 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
445 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
446 git config trailer.ack.where "end" &&
447 cat complex_message_body >expected &&
448 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
460 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
461 --trailer "ack: Junio" --trailer "bug: 42" \
462 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
463 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
464 test_cmp expected actual
467 test_expect_success
'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
468 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
469 git config trailer.ack.where "after" &&
470 cat complex_message_body >expected &&
471 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
482 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
483 --trailer "ack: Junio" --trailer "bug: 42" \
484 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
485 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
486 test_cmp expected actual
489 test_expect_success
'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
490 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
491 cat complex_message_body >expected &&
492 cat >>expected <<-\EOF &&
498 git interpret-trailers --trim-empty --trailer "ack: Peff" \
499 --trailer "Acked-by= Peff" --trailer "review:" \
500 --trailer "ack: Junio" --trailer "bug: 42" \
501 --trailer "ack: Peff" <complex_message >actual &&
502 test_cmp expected actual
505 test_expect_success
'using "ifExists = add" with "where = end"' '
506 git config trailer.ack.ifExists "add" &&
507 git config trailer.ack.where "end" &&
508 cat complex_message_body >expected &&
509 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
522 git interpret-trailers --trailer "ack: Peff" \
523 --trailer "Acked-by= Peff" --trailer "review:" \
524 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
525 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
526 --trailer "ack: Peff" <complex_message >actual &&
527 test_cmp expected actual
530 test_expect_success
'using "ifExists = add" with "where = after"' '
531 git config trailer.ack.ifExists "add" &&
532 git config trailer.ack.where "after" &&
533 cat complex_message_body >expected &&
534 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
545 git interpret-trailers --trailer "ack: Peff" \
546 --trailer "Acked-by= Peff" --trailer "review:" \
547 --trailer "ack: Junio" --trailer "bug: 42" \
548 --trailer "ack: Peff" <complex_message >actual &&
549 test_cmp expected actual
552 test_expect_success
'using "ifExists = replace"' '
553 git config trailer.fix.key "Fixes: " &&
554 git config trailer.fix.ifExists "replace" &&
555 cat complex_message_body >expected &&
556 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
565 git interpret-trailers --trailer "review:" \
566 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
567 --trailer "bug: 42" --trailer "ack: Peff" \
568 <complex_message >actual &&
569 test_cmp expected actual
572 test_expect_success
'using "ifExists = replace" with "where = after"' '
573 git config trailer.fix.where "after" &&
574 cat complex_message_body >expected &&
575 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
584 git interpret-trailers --trailer "review:" \
585 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
586 --trailer "bug: 42" --trailer "ack: Peff" \
587 <complex_message >actual &&
588 test_cmp expected actual
591 test_expect_success
'using "ifExists = doNothing"' '
592 git config trailer.fix.ifExists "doNothing" &&
593 cat complex_message_body >expected &&
594 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
603 git interpret-trailers --trailer "review:" --trailer "fix=53" \
604 --trailer "ack: Junio" --trailer "fix=22" \
605 --trailer "bug: 42" --trailer "ack: Peff" \
606 <complex_message >actual &&
607 test_cmp expected actual
610 test_expect_success
'the default is "ifMissing = add"' '
611 git config trailer.cc.key "Cc: " &&
612 git config trailer.cc.where "before" &&
613 cat complex_message_body >expected &&
614 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
624 git interpret-trailers --trailer "review:" --trailer "fix=53" \
625 --trailer "cc=Linus" --trailer "ack: Junio" \
626 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
627 <complex_message >actual &&
628 test_cmp expected actual
631 test_expect_success
'when default "ifMissing" is "doNothing"' '
632 git config trailer.ifmissing "doNothing" &&
633 cat complex_message_body >expected &&
634 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
642 git interpret-trailers --trailer "review:" --trailer "fix=53" \
643 --trailer "cc=Linus" --trailer "ack: Junio" \
644 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
645 <complex_message >actual &&
646 test_cmp expected actual &&
647 git config trailer.ifmissing "add"
650 test_expect_success
'using "ifMissing = add" with "where = end"' '
651 git config trailer.cc.key "Cc: " &&
652 git config trailer.cc.where "end" &&
653 git config trailer.cc.ifMissing "add" &&
654 cat complex_message_body >expected &&
655 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
665 git interpret-trailers --trailer "review:" --trailer "fix=53" \
666 --trailer "ack: Junio" --trailer "fix=22" \
667 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
668 <complex_message >actual &&
669 test_cmp expected actual
672 test_expect_success
'using "ifMissing = add" with "where = before"' '
673 git config trailer.cc.key "Cc: " &&
674 git config trailer.cc.where "before" &&
675 git config trailer.cc.ifMissing "add" &&
676 cat complex_message_body >expected &&
677 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
687 git interpret-trailers --trailer "review:" --trailer "fix=53" \
688 --trailer "ack: Junio" --trailer "fix=22" \
689 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
690 <complex_message >actual &&
691 test_cmp expected actual
694 test_expect_success
'using "ifMissing = doNothing"' '
695 git config trailer.cc.ifMissing "doNothing" &&
696 cat complex_message_body >expected &&
697 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
706 git interpret-trailers --trailer "review:" --trailer "fix=53" \
707 --trailer "cc=Linus" --trailer "ack: Junio" \
708 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
709 <complex_message >actual &&
710 test_cmp expected actual
713 test_expect_success
'default "where" is now "after"' '
714 git config trailer.where "after" &&
715 git config --unset trailer.ack.where &&
716 cat complex_message_body >expected &&
717 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
730 git interpret-trailers --trailer "ack: Peff" \
731 --trailer "Acked-by= Peff" --trailer "review:" \
732 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
733 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
734 --trailer "ack: Peff" <complex_message >actual &&
735 test_cmp expected actual
738 test_expect_success
'with simple command' '
739 git config trailer.sign.key "Signed-off-by: " &&
740 git config trailer.sign.where "after" &&
741 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
742 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
743 cat complex_message_body >expected &&
744 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
749 Signed-off-by: A U Thor <author@example.com>
751 git interpret-trailers --trailer "review:" --trailer "fix=22" \
752 <complex_message >actual &&
753 test_cmp expected actual
756 test_expect_success
'with command using commiter information' '
757 git config trailer.sign.ifExists "addIfDifferent" &&
758 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
759 cat complex_message_body >expected &&
760 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
765 Signed-off-by: C O Mitter <committer@example.com>
767 git interpret-trailers --trailer "review:" --trailer "fix=22" \
768 <complex_message >actual &&
769 test_cmp expected actual
772 test_expect_success
'with command using author information' '
773 git config trailer.sign.key "Signed-off-by: " &&
774 git config trailer.sign.where "after" &&
775 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
776 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
777 cat complex_message_body >expected &&
778 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
783 Signed-off-by: A U Thor <author@example.com>
785 git interpret-trailers --trailer "review:" --trailer "fix=22" \
786 <complex_message >actual &&
787 test_cmp expected actual
790 test_expect_success
'setup a commit' '
791 echo "Content of the first commit." > a.txt &&
793 git commit -m "Add file a.txt"
796 test_expect_success
'with command using $ARG' '
797 git config trailer.fix.ifExists "replace" &&
798 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
799 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
800 cat complex_message_body >expected &&
801 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
806 Signed-off-by: A U Thor <author@example.com>
808 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
809 <complex_message >actual &&
810 test_cmp expected actual
813 test_expect_success
'with failing command using $ARG' '
814 git config trailer.fix.ifExists "replace" &&
815 git config trailer.fix.command "false \$ARG" &&
816 cat complex_message_body >expected &&
817 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
822 Signed-off-by: A U Thor <author@example.com>
824 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
825 <complex_message >actual &&
826 test_cmp expected actual
829 test_expect_success
'with empty tokens' '
830 git config --unset trailer.fix.command &&
831 cat >expected <<-EOF &&
833 Signed-off-by: A U Thor <author@example.com>
835 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
837 test_cmp expected actual
840 test_expect_success
'with command but no key' '
841 git config --unset trailer.sign.key &&
842 cat >expected <<-EOF &&
844 sign: A U Thor <author@example.com>
846 git interpret-trailers >actual <<-EOF &&
848 test_cmp expected actual
851 test_expect_success
'with no command and no key' '
852 git config --unset trailer.review.key &&
853 cat >expected <<-EOF &&
856 sign: A U Thor <author@example.com>
858 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
860 test_cmp expected actual