Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t7513-interpret-trailers.sh
blob0f7d8938d984d9a2c560b4b8d491c10124a9c301
1 #!/bin/sh
3 # Copyright (c) 2013, 2014 Christian Couder
6 test_description='git interpret-trailers'
8 . ./test-lib.sh
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' '
14 : >empty &&
15 cat >basic_message <<-\EOF &&
16 subject
18 body
19 EOF
20 cat >complex_message_body <<-\EOF &&
21 my subject
23 my body which is long
24 and contains some special
25 chars like : = ? !
27 EOF
28 sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF &&
29 Fixes: Z
30 Acked-by: Z
31 Reviewed-by: Z
32 Signed-off-by: Z
33 EOF
34 cat >basic_patch <<-\EOF
35 ---
36 foo.txt | 2 +-
37 1 file changed, 1 insertion(+), 1 deletion(-)
39 diff --git a/foo.txt b/foo.txt
40 index 0353767..1d91aa1 100644
41 --- a/foo.txt
42 +++ b/foo.txt
43 @@ -1,3 +1,3 @@
45 -bar
46 +baz
49 1.9.rc0.11.ga562ddc
51 EOF
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
63 EOF
64 git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
65 >actual2 &&
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 &&
76 Bug-maker: him is him
77 Bug-maker: me is me
78 EOF
79 git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
80 >actual2 &&
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 &&
91 Bug-maker: who is me
92 EOF
93 git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
94 >actual2 &&
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 &&
105 Bug-maker: who is me
107 cat >echoscript <<-EOF &&
108 #!/bin/sh
109 echo who is "\$1"
111 chmod +x echoscript &&
112 git interpret-trailers --trailer "bug: him" --trailer "bug:me" \
113 >actual2 &&
114 test_cmp expected2 actual2
117 test_expect_success 'without config' '
118 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
120 ack: Peff
121 Reviewed-by: Z
122 Acked-by: Johan
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 &&
132 Acked-by: Johan
133 Reviewed-by: Z
134 ack: Peff
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 &&
144 ack: Peff
145 Acked-by: Johan
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 &&
156 Acked-by: Johan
157 Reviewed-by: Peff
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 &&
167 area: change
169 Reviewed-by: Peff
170 Acked-by: Johan
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 &&
180 area: change
182 Reviewed-by: Peff
183 Acked-by: Johan
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 &&
193 area: change
195 details about the change.
197 Reviewed-by: Peff
198 Acked-by: Johan
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 &&
208 area: change
210 Reviewed-by: Peff
211 Acked-by: Johan
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 &&
220 place of
221 code: change
223 Reviewed-by: Peff
224 Acked-by: Johan
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
246 token: value
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
266 token: value
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
277 My-trailer: x
278 this is not a trailer
280 cat >expected <<-\EOF &&
282 this is not a trailer
283 this is not a trailer
284 My-trailer: x
285 this is not a trailer
286 token: value
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
308 token: value
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
325 token: value
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
341 token: value
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 &&
350 Qtoken: value
352 q_to_tab >expected <<-\EOF &&
354 Qtoken: value
356 token: value
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>
366 name: value on
367 Qmultiple lines
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>
378 name: value on
379 Qmultiple lines
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
386 name: value
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 &&
395 another: trailer
396 name: value on
397 Qmultiple lines
398 another: trailer
400 q_to_tab >expected <<-\EOF &&
402 another: trailer
403 name: value on
404 Qmultiple lines
405 name: value
406 another: trailer
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 &&
416 another: trailer
417 name: value on
418 Qmultiple lines
419 another: trailer
421 q_to_tab >expected <<-\EOF &&
423 another: trailer
424 another: trailer
425 name: value
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 &&
435 another: trailer
436 name: first line
437 Qsecond line
438 another: trailer
440 test_config trailer.name.ifexists addIfDifferent &&
442 q_to_tab >trailer <<-\EOF &&
443 name: first line
444 Qsecond line
446 q_to_tab >expected <<-\EOF &&
448 another: trailer
449 name: first line
450 Qsecond line
451 another: trailer
453 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
454 test_cmp expected actual &&
456 q_to_tab >trailer <<-\EOF &&
457 name: first line
458 QQQQQsecond line
460 q_to_tab >expected <<-\EOF &&
462 another: trailer
463 name: first line
464 Qsecond line
465 another: trailer
466 name: first line
467 QQQQQsecond line
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*
474 Qsecond line
476 q_to_tab >expected <<-\EOF &&
478 another: trailer
479 name: first line
480 Qsecond line
481 another: trailer
482 name: first line *DIFFERENT*
483 Qsecond line
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 &&
492 another: trailer
493 name: first line
494 Qsecond line
495 another: trailer
497 test_config trailer.name.where after &&
498 test_config trailer.name.ifexists addIfDifferentNeighbor &&
500 q_to_tab >trailer <<-\EOF &&
501 name: first line
502 Qsecond line
504 q_to_tab >expected <<-\EOF &&
506 another: trailer
507 name: first line
508 Qsecond line
509 another: trailer
511 git interpret-trailers --trailer "$(cat trailer)" patch >actual &&
512 test_cmp expected actual &&
514 q_to_tab >trailer <<-\EOF &&
515 name: first line
516 QQQQQsecond line
518 q_to_tab >expected <<-\EOF &&
520 another: trailer
521 name: first line
522 Qsecond line
523 name: first line
524 QQQQQsecond line
525 another: trailer
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 &&
535 Acked-by: Peff
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 &&
550 Acked-by= Peff
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 &&
564 bug% 42
565 count% 10
566 bug% 422
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 &&
577 Special Message
579 bug% 42
580 count% 10
581 bug% 422
583 cat >expected <<-\EOF &&
584 Special Message
586 bug% 42
587 count% 10
588 bug% 422
589 count% 100
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 &&
601 Bug #42
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 &&
609 echo >>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 &&
618 echo >>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 &&
630 Fixes: Z
631 Acked-by= Z
632 Reviewed-by: Z
633 Signed-off-by: Z
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 &&
643 echo >>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.
650 for char in "#" ";"
652 case "$char" in
653 "#")
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"
660 esac
662 test_expect_success "with message that has comments ($char)" '
663 cat basic_message >message_with_comments &&
664 sed -e "s/ Z\$/ /" \
665 -e "s/#/$char/g" >>message_with_comments <<-EOF &&
666 # comment
668 # other comment
669 Cc: Z
670 # yet another comment
671 Reviewed-by: Johan
672 Reviewed-by: Z
673 # last comment
676 cat basic_patch >>message_with_comments &&
677 cat basic_message >expected &&
678 sed -e "s/#/$char/g" >>expected <<-\EOF &&
679 # comment
681 Reviewed-by: Johan
682 Cc: Peff
683 # last comment
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
692 done
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 &&
697 # comment
699 # other comment
700 Cc: Z
701 # yet another comment
702 Reviewed-by: Johan
703 Reviewed-by: Z
704 # last comment
706 Conflicts:
709 cat basic_message >expected &&
710 cat >>expected <<-\EOF &&
711 # comment
713 Reviewed-by: Johan
714 Cc: Peff
715 # last comment
717 Conflicts:
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 &&
730 Fixes: Z
731 Acked-by= Z
732 Reviewed-by: Z
733 Signed-off-by: Z
734 Acked-by= Peff
735 Bug #42
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 &&
750 Acked-by= Peff
751 Bug #42
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 &&
763 echo >>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 &&
773 echo >>expected &&
774 cat >>expected <<-\EOF &&
775 Reviewed-by: Alice
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 &&
793 chmod -r message &&
794 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
795 chmod +r 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 &&
806 Bug #42
807 Fixes: Z
808 Acked-by= Z
809 Reviewed-by: Z
810 Signed-off-by: Z
811 Acked-by= Peff
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 &&
824 Fixes: Z
825 Acked-by= Z
826 Acked-by= Peff
827 Reviewed-by: Z
828 Signed-off-by: Z
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 &&
843 Bug #42
844 Fixes: Z
845 Acked-by= Peff
846 Acked-by= Z
847 Reviewed-by: Z
848 Signed-off-by: Z
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 &&
868 Bug #42
869 Acked-by= Peff
870 Fixes: Z
871 Acked-by= Z
872 Reviewed-by: Z
873 Signed-off-by: Z
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 &&
890 Fixes: Z
891 Acked-by= Z
892 Acked-by= Peff
893 Reviewed-by: Z
894 Signed-off-by: Z
895 Bug #42
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 &&
910 Bug #42
911 Fixes: Z
912 Acked-by= Z
913 Acked-by= Peff
914 Reviewed-by: Z
915 Signed-off-by: Z
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 &&
930 Fixes: Z
931 Acked-by= Z
932 Acked-by= Peff
933 Reviewed-by: Z
934 Signed-off-by: Z
935 Reviewed-by: Junio
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
953 Reviewed-by: Junio
954 Fixes: Z
955 Acked-by= Z
956 Acked-by= Peff
957 Reviewed-by: Z
958 Signed-off-by: Z
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 &&
976 Bug #42
977 Fixes: Z
978 Acked-by= Z
979 Acked-by= Peff
980 Reviewed-by:Johan
981 Reviewed-by:
982 Signed-off-by: Z
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 &&
998 Bug #46
999 Bug #42
1000 Acked-by= Peff
1001 Reviewed-by:Johan
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 &&
1019 Bug #42
1020 Fixes: Z
1021 Acked-by= Z
1022 Acked-by= Peff
1023 Acked-by= Junio
1024 Acked-by= Peff
1025 Reviewed-by:
1026 Signed-off-by: Z
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 &&
1044 Bug #42
1045 Fixes: Z
1046 Acked-by= Z
1047 Acked-by= Peff
1048 Acked-by= Junio
1049 Reviewed-by:
1050 Signed-off-by: Z
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 &&
1069 Bug #42
1070 Fixes: Z
1071 Acked-by= Z
1072 Reviewed-by:
1073 Signed-off-by: Z
1074 Acked-by= Peff
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 &&
1093 Bug #42
1094 Fixes: Z
1095 Acked-by= Peff
1096 Acked-by= Z
1097 Reviewed-by:
1098 Signed-off-by: Z
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 &&
1117 Bug #42
1118 Fixes: Z
1119 Acked-by= Z
1120 Reviewed-by:
1121 Signed-off-by: Z
1122 Acked-by= Peff
1123 Acked-by= Junio
1124 Tested-by: Jakub
1125 Acked-by= Junio
1126 Acked-by= Peff
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 &&
1146 Bug #42
1147 Fixes: Z
1148 Acked-by= Z
1149 Acked-by= Peff
1150 Acked-by= Junio
1151 Acked-by= Peff
1152 Reviewed-by:
1153 Signed-off-by: Z
1154 Tested-by: Jakub
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 &&
1171 Bug #42
1172 Acked-by= Peff
1173 Acked-by= Junio
1174 Acked-by= Peff
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 &&
1194 Bug #42
1195 Fixes: Z
1196 Acked-by= Z
1197 Reviewed-by:
1198 Signed-off-by: Z
1199 Acked-by= Peff
1200 Acked-by= Peff
1201 Tested-by: Jakub
1202 Acked-by= Junio
1203 Tested-by: Johannes
1204 Acked-by= Peff
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 &&
1225 Bug #42
1226 Fixes: Z
1227 Acked-by= Z
1228 Acked-by= Peff
1229 Acked-by= Peff
1230 Acked-by= Junio
1231 Acked-by= Peff
1232 Reviewed-by:
1233 Signed-off-by: Z
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 &&
1254 Bug #42
1255 Acked-by= Z
1256 Reviewed-by:
1257 Signed-off-by: Z
1258 Fixes: 22
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 &&
1272 Fixes: Z
1273 Acked-by: Z
1274 Reviewed-by: Z
1275 Signed-off-by: Z
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 &&
1289 Acked-by: Z
1290 Reviewed-by: Z
1291 Signed-off-by: Z
1292 Fixes: 53
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 &&
1306 Acked-by: Z
1307 Reviewed-by: Z
1308 Signed-off-by: Z
1309 Fixes: 53
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 &&
1328 Bug #42
1329 Acked-by= Z
1330 Acked-by= Junio
1331 Acked-by= Peff
1332 Reviewed-by:
1333 Signed-off-by: Z
1334 Fixes: 22
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 &&
1356 Bug #42
1357 Fixes: 22
1358 Acked-by= Z
1359 Acked-by= Junio
1360 Acked-by= Peff
1361 Reviewed-by:
1362 Signed-off-by: Z
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 &&
1383 Bug #42
1384 Fixes: Z
1385 Acked-by= Z
1386 Acked-by= Junio
1387 Acked-by= Peff
1388 Reviewed-by:
1389 Signed-off-by: Z
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 &&
1412 Bug #42
1413 Cc: Linus
1414 Fixes: Z
1415 Acked-by= Z
1416 Acked-by= Junio
1417 Acked-by= Peff
1418 Reviewed-by:
1419 Signed-off-by: Z
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 &&
1439 Fixes: Z
1440 Acked-by= Z
1441 Acked-by= Junio
1442 Acked-by= Peff
1443 Reviewed-by:
1444 Signed-off-by: Z
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 &&
1464 Fixes: Z
1465 Acked-by= Z
1466 Acked-by= Junio
1467 Acked-by= Peff
1468 Reviewed-by:
1469 Signed-off-by: Z
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 &&
1492 Bug #42
1493 Fixes: Z
1494 Acked-by= Z
1495 Acked-by= Junio
1496 Acked-by= Peff
1497 Reviewed-by:
1498 Signed-off-by: Z
1499 Cc: Linus
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 &&
1522 Cc: Linus
1523 Bug #42
1524 Fixes: Z
1525 Acked-by= Z
1526 Acked-by= Junio
1527 Acked-by= Peff
1528 Reviewed-by:
1529 Signed-off-by: Z
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 &&
1550 Bug #42
1551 Fixes: Z
1552 Acked-by= Z
1553 Acked-by= Junio
1554 Acked-by= Peff
1555 Reviewed-by:
1556 Signed-off-by: Z
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 &&
1572 Fixes: Z
1573 Acked-by: Z
1574 Reviewed-by: Z
1575 Signed-off-by: Z
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 &&
1587 Fixes: Z
1588 Acked-by: Z
1589 Reviewed-by: Z
1590 Signed-off-by: Z
1591 AddedTrailer: addme
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 &&
1611 Bug #42
1612 Fixes: Z
1613 Acked-by= Z
1614 Acked-by= Peff
1615 Acked-by= Peff
1616 Acked-by= Junio
1617 Acked-by= Peff
1618 Reviewed-by:
1619 Signed-off-by: Z
1620 Tested-by: Jakub
1621 Tested-by: Johannes
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 &&
1643 Fixes: Z
1644 Acked-by= Z
1645 Reviewed-by:
1646 Signed-off-by: Z
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 &&
1665 Fixes: Z
1666 Acked-by= Z
1667 Reviewed-by:
1668 Signed-off-by: Z
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 &&
1688 Fixes: Z
1689 Acked-by= Z
1690 Reviewed-by:
1691 Signed-off-by: Z
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 &&
1701 git add 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 &&
1722 Fixes: $FIXED
1723 Acked-by= Z
1724 Reviewed-by:
1725 Signed-off-by: Z
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 &&
1747 Fixes: $FIXED
1748 Acked-by= Z
1749 Reviewed-by:
1750 Signed-off-by: Z
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 &&
1771 Fixes: Z
1772 Acked-by= Z
1773 Reviewed-by:
1774 Signed-off-by: Z
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 &&
1813 review: Junio
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 &&
1825 my subject
1827 review: Brian
1828 sign: A U Thor <author@example.com>
1829 # ------------------------ >8 ------------------------
1830 ignore this
1832 git interpret-trailers --trailer review:Brian >actual <<-\EOF &&
1833 my subject
1834 # ------------------------ >8 ------------------------
1835 ignore this
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
1845 sign: config-value
1846 added: added-value
1848 git interpret-trailers \
1849 --trailer added:added-value \
1850 --only-trailers >actual <<-\EOF &&
1851 my subject
1853 my body
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>
1865 sign: config-value
1867 git interpret-trailers --only-trailers >actual <<-\EOF &&
1868 subject
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 &&
1887 my subject
1889 my body
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
1901 tr _ " " <<-\EOF |
1902 my subject
1904 my body
1906 foo:_
1907 __continued
1908 ___across
1909 ____several
1910 _____lines
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 &&
1921 subject
1923 body
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 &&
1943 subject
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 &&
1963 subject
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 &&
1982 subject
1984 my-trailer: here
1986 # ------------------------ >8 ------------------------
1989 test_cmp expected actual
1992 test_done