Merge branch 'jc/am-i-v-fix'
[git/git-svn.git] / t / t7513-interpret-trailers.sh
blobaee785cffa8d656fa52e6b893921153faf748fe9
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 'without config' '
55 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
57 ack: Peff
58 Reviewed-by: Z
59 Acked-by: Johan
60 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 &&
69 Acked-by: Johan
70 Reviewed-by: Z
71 ack: Peff
72 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 &&
81 ack: Peff
82 Acked-by: Johan
83 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 &&
93 Acked-by: Johan
94 Reviewed-by: Peff
95 EOF
96 { echo; echo "Acked-by: Johan"; } |
97 git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
98 --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
99 test_cmp expected actual
102 test_expect_success 'with only a title in the message' '
103 cat >expected <<-\EOF &&
104 area: change
106 Reviewed-by: Peff
107 Acked-by: Johan
109 echo "area: change" |
110 git interpret-trailers --trailer "Reviewed-by: Peff" \
111 --trailer "Acked-by: Johan" >actual &&
112 test_cmp expected actual
115 test_expect_success 'with multiline title in the message' '
116 cat >expected <<-\EOF &&
117 place of
118 code: change
120 Reviewed-by: Peff
121 Acked-by: Johan
123 printf "%s\n" "place of" "code: change" |
124 git interpret-trailers --trailer "Reviewed-by: Peff" \
125 --trailer "Acked-by: Johan" >actual &&
126 test_cmp expected actual
129 test_expect_success 'with config setup' '
130 git config trailer.ack.key "Acked-by: " &&
131 cat >expected <<-\EOF &&
133 Acked-by: Peff
135 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
136 test_cmp expected actual &&
137 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
138 test_cmp expected actual &&
139 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
140 test_cmp expected actual
143 test_expect_success 'with config setup and ":=" as separators' '
144 git config trailer.separators ":=" &&
145 git config trailer.ack.key "Acked-by= " &&
146 cat >expected <<-\EOF &&
148 Acked-by= Peff
150 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
151 test_cmp expected actual &&
152 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
153 test_cmp expected actual &&
154 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
155 test_cmp expected actual
158 test_expect_success 'with config setup and "%" as separators' '
159 git config trailer.separators "%" &&
160 cat >expected <<-\EOF &&
162 bug% 42
163 count% 10
164 bug% 422
166 git interpret-trailers --trim-empty --trailer "bug = 42" \
167 --trailer count%10 --trailer "test: stuff" \
168 --trailer "bug % 422" empty >actual &&
169 test_cmp expected actual
172 test_expect_success 'with "%" as separators and a message with trailers' '
173 cat >special_message <<-\EOF &&
174 Special Message
176 bug% 42
177 count% 10
178 bug% 422
180 cat >expected <<-\EOF &&
181 Special Message
183 bug% 42
184 count% 10
185 bug% 422
186 count% 100
188 git interpret-trailers --trailer count%100 \
189 special_message >actual &&
190 test_cmp expected actual
193 test_expect_success 'with config setup and ":=#" as separators' '
194 git config trailer.separators ":=#" &&
195 git config trailer.bug.key "Bug #" &&
196 cat >expected <<-\EOF &&
198 Bug #42
200 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
201 test_cmp expected actual
204 test_expect_success 'with commit basic message' '
205 cat basic_message >expected &&
206 echo >>expected &&
207 git interpret-trailers <basic_message >actual &&
208 test_cmp expected actual
211 test_expect_success 'with basic patch' '
212 cat basic_message >input &&
213 cat basic_patch >>input &&
214 cat basic_message >expected &&
215 echo >>expected &&
216 cat basic_patch >>expected &&
217 git interpret-trailers <input >actual &&
218 test_cmp expected actual
221 test_expect_success 'with commit complex message as argument' '
222 cat complex_message_body complex_message_trailers >complex_message &&
223 cat complex_message_body >expected &&
224 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
225 Fixes: Z
226 Acked-by= Z
227 Reviewed-by: Z
228 Signed-off-by: Z
230 git interpret-trailers complex_message >actual &&
231 test_cmp expected actual
234 test_expect_success 'with 2 files arguments' '
235 cat basic_message >>expected &&
236 echo >>expected &&
237 cat basic_patch >>expected &&
238 git interpret-trailers complex_message input >actual &&
239 test_cmp expected actual
242 test_expect_success 'with message that has comments' '
243 cat basic_message >message_with_comments &&
244 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
245 # comment
247 # other comment
248 Cc: Z
249 # yet another comment
250 Reviewed-by: Johan
251 Reviewed-by: Z
252 # last comment
255 cat basic_patch >>message_with_comments &&
256 cat basic_message >expected &&
257 cat >>expected <<-\EOF &&
258 # comment
260 Reviewed-by: Johan
261 Cc: Peff
262 # last comment
265 cat basic_patch >>expected &&
266 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
267 test_cmp expected actual
270 test_expect_success 'with message that has an old style conflict block' '
271 cat basic_message >message_with_comments &&
272 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
273 # comment
275 # other comment
276 Cc: Z
277 # yet another comment
278 Reviewed-by: Johan
279 Reviewed-by: Z
280 # last comment
282 Conflicts:
285 cat basic_message >expected &&
286 cat >>expected <<-\EOF &&
287 # comment
289 Reviewed-by: Johan
290 Cc: Peff
291 # last comment
293 Conflicts:
296 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
297 test_cmp expected actual
300 test_expect_success 'with commit complex message and trailer args' '
301 cat complex_message_body >expected &&
302 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
303 Fixes: Z
304 Acked-by= Z
305 Reviewed-by: Z
306 Signed-off-by: Z
307 Acked-by= Peff
308 Bug #42
310 git interpret-trailers --trailer "ack: Peff" \
311 --trailer "bug: 42" <complex_message >actual &&
312 test_cmp expected actual
315 test_expect_success 'with complex patch, args and --trim-empty' '
316 cat complex_message >complex_patch &&
317 cat basic_patch >>complex_patch &&
318 cat complex_message_body >expected &&
319 cat >>expected <<-\EOF &&
320 Acked-by= Peff
321 Bug #42
323 cat basic_patch >>expected &&
324 git interpret-trailers --trim-empty --trailer "ack: Peff" \
325 --trailer "bug: 42" <complex_patch >actual &&
326 test_cmp expected actual
329 test_expect_success 'in-place editing with basic patch' '
330 cat basic_message >message &&
331 cat basic_patch >>message &&
332 cat basic_message >expected &&
333 echo >>expected &&
334 cat basic_patch >>expected &&
335 git interpret-trailers --in-place message &&
336 test_cmp expected message
339 test_expect_success 'in-place editing with additional trailer' '
340 cat basic_message >message &&
341 cat basic_patch >>message &&
342 cat basic_message >expected &&
343 echo >>expected &&
344 cat >>expected <<-\EOF &&
345 Reviewed-by: Alice
347 cat basic_patch >>expected &&
348 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
349 test_cmp expected message
352 test_expect_success 'in-place editing on stdin disallowed' '
353 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
356 test_expect_success 'in-place editing on non-existing file' '
357 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
358 test_path_is_missing nonexisting
361 test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" '
362 cat basic_message >message &&
363 chmod -r message &&
364 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
365 chmod +r message &&
366 test_cmp message basic_message
369 test_expect_success 'using "where = before"' '
370 git config trailer.bug.where "before" &&
371 cat complex_message_body >expected &&
372 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
373 Bug #42
374 Fixes: Z
375 Acked-by= Z
376 Reviewed-by: Z
377 Signed-off-by: Z
378 Acked-by= Peff
380 git interpret-trailers --trailer "ack: Peff" \
381 --trailer "bug: 42" complex_message >actual &&
382 test_cmp expected actual
385 test_expect_success 'using "where = after"' '
386 git config trailer.ack.where "after" &&
387 cat complex_message_body >expected &&
388 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
389 Bug #42
390 Fixes: Z
391 Acked-by= Z
392 Acked-by= Peff
393 Reviewed-by: Z
394 Signed-off-by: Z
396 git interpret-trailers --trailer "ack: Peff" \
397 --trailer "bug: 42" complex_message >actual &&
398 test_cmp expected actual
401 test_expect_success 'using "where = end"' '
402 git config trailer.review.key "Reviewed-by" &&
403 git config trailer.review.where "end" &&
404 cat complex_message_body >expected &&
405 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
406 Fixes: Z
407 Acked-by= Z
408 Acked-by= Peff
409 Reviewed-by: Z
410 Signed-off-by: Z
411 Reviewed-by: Junio
412 Reviewed-by: Johannes
414 git interpret-trailers --trailer "ack: Peff" \
415 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
416 complex_message >actual &&
417 test_cmp expected actual
420 test_expect_success 'using "where = start"' '
421 git config trailer.review.key "Reviewed-by" &&
422 git config trailer.review.where "start" &&
423 cat complex_message_body >expected &&
424 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
425 Reviewed-by: Johannes
426 Reviewed-by: Junio
427 Fixes: Z
428 Acked-by= Z
429 Acked-by= Peff
430 Reviewed-by: Z
431 Signed-off-by: Z
433 git interpret-trailers --trailer "ack: Peff" \
434 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
435 complex_message >actual &&
436 test_cmp expected actual
439 test_expect_success 'using "where = before" for a token in the middle of the message' '
440 git config trailer.review.key "Reviewed-by:" &&
441 git config trailer.review.where "before" &&
442 cat complex_message_body >expected &&
443 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
444 Bug #42
445 Fixes: Z
446 Acked-by= Z
447 Acked-by= Peff
448 Reviewed-by:Johan
449 Reviewed-by:
450 Signed-off-by: Z
452 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
453 --trailer "review: Johan" <complex_message >actual &&
454 test_cmp expected actual
457 test_expect_success 'using "where = before" and --trim-empty' '
458 cat complex_message_body >expected &&
459 cat >>expected <<-\EOF &&
460 Bug #46
461 Bug #42
462 Acked-by= Peff
463 Reviewed-by:Johan
465 git interpret-trailers --trim-empty --trailer "ack: Peff" \
466 --trailer "bug: 42" --trailer "review: Johan" \
467 --trailer "Bug: 46" <complex_message >actual &&
468 test_cmp expected actual
471 test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
472 cat complex_message_body >expected &&
473 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
474 Bug #42
475 Fixes: Z
476 Acked-by= Z
477 Acked-by= Peff
478 Acked-by= Junio
479 Acked-by= Peff
480 Reviewed-by:
481 Signed-off-by: Z
483 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
484 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
485 --trailer "ack: Peff" <complex_message >actual &&
486 test_cmp expected actual
489 test_expect_success 'default "ifExists" is now "addIfDifferent"' '
490 git config trailer.ifexists "addIfDifferent" &&
491 cat complex_message_body >expected &&
492 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
493 Bug #42
494 Fixes: Z
495 Acked-by= Z
496 Acked-by= Peff
497 Acked-by= Junio
498 Reviewed-by:
499 Signed-off-by: Z
501 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
502 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
503 --trailer "ack: Peff" <complex_message >actual &&
504 test_cmp expected actual
507 test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
508 git config trailer.ack.ifExists "addIfDifferent" &&
509 git config trailer.ack.where "end" &&
510 cat complex_message_body >expected &&
511 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
512 Bug #42
513 Fixes: Z
514 Acked-by= Z
515 Reviewed-by:
516 Signed-off-by: Z
517 Acked-by= Peff
519 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
520 --trailer "bug: 42" --trailer "ack: Peff" \
521 <complex_message >actual &&
522 test_cmp expected actual
525 test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
526 git config trailer.ack.ifExists "addIfDifferent" &&
527 git config trailer.ack.where "before" &&
528 cat complex_message_body >expected &&
529 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
530 Bug #42
531 Fixes: Z
532 Acked-by= Peff
533 Acked-by= Z
534 Reviewed-by:
535 Signed-off-by: Z
537 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
538 --trailer "bug: 42" --trailer "ack: Peff" \
539 <complex_message >actual &&
540 test_cmp expected actual
543 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
544 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
545 git config trailer.ack.where "end" &&
546 cat complex_message_body >expected &&
547 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
548 Bug #42
549 Fixes: Z
550 Acked-by= Z
551 Reviewed-by:
552 Signed-off-by: Z
553 Acked-by= Peff
554 Acked-by= Junio
555 Tested-by: Jakub
556 Acked-by= Junio
557 Acked-by= Peff
559 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
560 --trailer "ack: Junio" --trailer "bug: 42" \
561 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
562 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
563 test_cmp expected actual
566 test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
567 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
568 git config trailer.ack.where "after" &&
569 cat complex_message_body >expected &&
570 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
571 Bug #42
572 Fixes: Z
573 Acked-by= Z
574 Acked-by= Peff
575 Acked-by= Junio
576 Acked-by= Peff
577 Reviewed-by:
578 Signed-off-by: Z
579 Tested-by: Jakub
581 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
582 --trailer "ack: Junio" --trailer "bug: 42" \
583 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
584 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
585 test_cmp expected actual
588 test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
589 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
590 cat complex_message_body >expected &&
591 cat >>expected <<-\EOF &&
592 Bug #42
593 Acked-by= Peff
594 Acked-by= Junio
595 Acked-by= Peff
597 git interpret-trailers --trim-empty --trailer "ack: Peff" \
598 --trailer "Acked-by= Peff" --trailer "review:" \
599 --trailer "ack: Junio" --trailer "bug: 42" \
600 --trailer "ack: Peff" <complex_message >actual &&
601 test_cmp expected actual
604 test_expect_success 'using "ifExists = add" with "where = end"' '
605 git config trailer.ack.ifExists "add" &&
606 git config trailer.ack.where "end" &&
607 cat complex_message_body >expected &&
608 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
609 Bug #42
610 Fixes: Z
611 Acked-by= Z
612 Reviewed-by:
613 Signed-off-by: Z
614 Acked-by= Peff
615 Acked-by= Peff
616 Tested-by: Jakub
617 Acked-by= Junio
618 Tested-by: Johannes
619 Acked-by= Peff
621 git interpret-trailers --trailer "ack: Peff" \
622 --trailer "Acked-by= Peff" --trailer "review:" \
623 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
624 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
625 --trailer "ack: Peff" <complex_message >actual &&
626 test_cmp expected actual
629 test_expect_success 'using "ifExists = add" with "where = after"' '
630 git config trailer.ack.ifExists "add" &&
631 git config trailer.ack.where "after" &&
632 cat complex_message_body >expected &&
633 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
634 Bug #42
635 Fixes: Z
636 Acked-by= Z
637 Acked-by= Peff
638 Acked-by= Peff
639 Acked-by= Junio
640 Acked-by= Peff
641 Reviewed-by:
642 Signed-off-by: Z
644 git interpret-trailers --trailer "ack: Peff" \
645 --trailer "Acked-by= Peff" --trailer "review:" \
646 --trailer "ack: Junio" --trailer "bug: 42" \
647 --trailer "ack: Peff" <complex_message >actual &&
648 test_cmp expected actual
651 test_expect_success 'using "ifExists = replace"' '
652 git config trailer.fix.key "Fixes: " &&
653 git config trailer.fix.ifExists "replace" &&
654 cat complex_message_body >expected &&
655 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
656 Bug #42
657 Acked-by= Z
658 Acked-by= Junio
659 Acked-by= Peff
660 Reviewed-by:
661 Signed-off-by: Z
662 Fixes: 22
664 git interpret-trailers --trailer "review:" \
665 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
666 --trailer "bug: 42" --trailer "ack: Peff" \
667 <complex_message >actual &&
668 test_cmp expected actual
671 test_expect_success 'using "ifExists = replace" with "where = after"' '
672 git config trailer.fix.where "after" &&
673 cat complex_message_body >expected &&
674 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
675 Bug #42
676 Fixes: 22
677 Acked-by= Z
678 Acked-by= Junio
679 Acked-by= Peff
680 Reviewed-by:
681 Signed-off-by: Z
683 git interpret-trailers --trailer "review:" \
684 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
685 --trailer "bug: 42" --trailer "ack: Peff" \
686 <complex_message >actual &&
687 test_cmp expected actual
690 test_expect_success 'using "ifExists = doNothing"' '
691 git config trailer.fix.ifExists "doNothing" &&
692 cat complex_message_body >expected &&
693 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
694 Bug #42
695 Fixes: Z
696 Acked-by= Z
697 Acked-by= Junio
698 Acked-by= Peff
699 Reviewed-by:
700 Signed-off-by: Z
702 git interpret-trailers --trailer "review:" --trailer "fix=53" \
703 --trailer "ack: Junio" --trailer "fix=22" \
704 --trailer "bug: 42" --trailer "ack: Peff" \
705 <complex_message >actual &&
706 test_cmp expected actual
709 test_expect_success 'the default is "ifMissing = add"' '
710 git config trailer.cc.key "Cc: " &&
711 git config trailer.cc.where "before" &&
712 cat complex_message_body >expected &&
713 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
714 Bug #42
715 Cc: Linus
716 Fixes: Z
717 Acked-by= Z
718 Acked-by= Junio
719 Acked-by= Peff
720 Reviewed-by:
721 Signed-off-by: Z
723 git interpret-trailers --trailer "review:" --trailer "fix=53" \
724 --trailer "cc=Linus" --trailer "ack: Junio" \
725 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
726 <complex_message >actual &&
727 test_cmp expected actual
730 test_expect_success 'when default "ifMissing" is "doNothing"' '
731 git config trailer.ifmissing "doNothing" &&
732 cat complex_message_body >expected &&
733 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
734 Fixes: Z
735 Acked-by= Z
736 Acked-by= Junio
737 Acked-by= Peff
738 Reviewed-by:
739 Signed-off-by: Z
741 git interpret-trailers --trailer "review:" --trailer "fix=53" \
742 --trailer "cc=Linus" --trailer "ack: Junio" \
743 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
744 <complex_message >actual &&
745 test_cmp expected actual &&
746 git config trailer.ifmissing "add"
749 test_expect_success 'using "ifMissing = add" with "where = end"' '
750 git config trailer.cc.key "Cc: " &&
751 git config trailer.cc.where "end" &&
752 git config trailer.cc.ifMissing "add" &&
753 cat complex_message_body >expected &&
754 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
755 Bug #42
756 Fixes: Z
757 Acked-by= Z
758 Acked-by= Junio
759 Acked-by= Peff
760 Reviewed-by:
761 Signed-off-by: Z
762 Cc: Linus
764 git interpret-trailers --trailer "review:" --trailer "fix=53" \
765 --trailer "ack: Junio" --trailer "fix=22" \
766 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
767 <complex_message >actual &&
768 test_cmp expected actual
771 test_expect_success 'using "ifMissing = add" with "where = before"' '
772 git config trailer.cc.key "Cc: " &&
773 git config trailer.cc.where "before" &&
774 git config trailer.cc.ifMissing "add" &&
775 cat complex_message_body >expected &&
776 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
777 Cc: Linus
778 Bug #42
779 Fixes: Z
780 Acked-by= Z
781 Acked-by= Junio
782 Acked-by= Peff
783 Reviewed-by:
784 Signed-off-by: Z
786 git interpret-trailers --trailer "review:" --trailer "fix=53" \
787 --trailer "ack: Junio" --trailer "fix=22" \
788 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
789 <complex_message >actual &&
790 test_cmp expected actual
793 test_expect_success 'using "ifMissing = doNothing"' '
794 git config trailer.cc.ifMissing "doNothing" &&
795 cat complex_message_body >expected &&
796 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
797 Bug #42
798 Fixes: Z
799 Acked-by= Z
800 Acked-by= Junio
801 Acked-by= Peff
802 Reviewed-by:
803 Signed-off-by: Z
805 git interpret-trailers --trailer "review:" --trailer "fix=53" \
806 --trailer "cc=Linus" --trailer "ack: Junio" \
807 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
808 <complex_message >actual &&
809 test_cmp expected actual
812 test_expect_success 'default "where" is now "after"' '
813 git config trailer.where "after" &&
814 git config --unset trailer.ack.where &&
815 cat complex_message_body >expected &&
816 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
817 Bug #42
818 Fixes: Z
819 Acked-by= Z
820 Acked-by= Peff
821 Acked-by= Peff
822 Acked-by= Junio
823 Acked-by= Peff
824 Reviewed-by:
825 Signed-off-by: Z
826 Tested-by: Jakub
827 Tested-by: Johannes
829 git interpret-trailers --trailer "ack: Peff" \
830 --trailer "Acked-by= Peff" --trailer "review:" \
831 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
832 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
833 --trailer "ack: Peff" <complex_message >actual &&
834 test_cmp expected actual
837 test_expect_success 'with simple command' '
838 git config trailer.sign.key "Signed-off-by: " &&
839 git config trailer.sign.where "after" &&
840 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
841 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
842 cat complex_message_body >expected &&
843 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
844 Fixes: Z
845 Acked-by= Z
846 Reviewed-by:
847 Signed-off-by: Z
848 Signed-off-by: A U Thor <author@example.com>
850 git interpret-trailers --trailer "review:" --trailer "fix=22" \
851 <complex_message >actual &&
852 test_cmp expected actual
855 test_expect_success 'with command using commiter information' '
856 git config trailer.sign.ifExists "addIfDifferent" &&
857 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
858 cat complex_message_body >expected &&
859 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
860 Fixes: Z
861 Acked-by= Z
862 Reviewed-by:
863 Signed-off-by: Z
864 Signed-off-by: C O Mitter <committer@example.com>
866 git interpret-trailers --trailer "review:" --trailer "fix=22" \
867 <complex_message >actual &&
868 test_cmp expected actual
871 test_expect_success 'with command using author information' '
872 git config trailer.sign.key "Signed-off-by: " &&
873 git config trailer.sign.where "after" &&
874 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
875 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
876 cat complex_message_body >expected &&
877 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
878 Fixes: Z
879 Acked-by= Z
880 Reviewed-by:
881 Signed-off-by: Z
882 Signed-off-by: A U Thor <author@example.com>
884 git interpret-trailers --trailer "review:" --trailer "fix=22" \
885 <complex_message >actual &&
886 test_cmp expected actual
889 test_expect_success 'setup a commit' '
890 echo "Content of the first commit." > a.txt &&
891 git add a.txt &&
892 git commit -m "Add file a.txt"
895 test_expect_success 'with command using $ARG' '
896 git config trailer.fix.ifExists "replace" &&
897 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
898 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
899 cat complex_message_body >expected &&
900 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
901 Fixes: $FIXED
902 Acked-by= Z
903 Reviewed-by:
904 Signed-off-by: Z
905 Signed-off-by: A U Thor <author@example.com>
907 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
908 <complex_message >actual &&
909 test_cmp expected actual
912 test_expect_success 'with failing command using $ARG' '
913 git config trailer.fix.ifExists "replace" &&
914 git config trailer.fix.command "false \$ARG" &&
915 cat complex_message_body >expected &&
916 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
917 Fixes: Z
918 Acked-by= Z
919 Reviewed-by:
920 Signed-off-by: Z
921 Signed-off-by: A U Thor <author@example.com>
923 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
924 <complex_message >actual &&
925 test_cmp expected actual
928 test_expect_success 'with empty tokens' '
929 git config --unset trailer.fix.command &&
930 cat >expected <<-EOF &&
932 Signed-off-by: A U Thor <author@example.com>
934 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
936 test_cmp expected actual
939 test_expect_success 'with command but no key' '
940 git config --unset trailer.sign.key &&
941 cat >expected <<-EOF &&
943 sign: A U Thor <author@example.com>
945 git interpret-trailers >actual <<-EOF &&
947 test_cmp expected actual
950 test_expect_success 'with no command and no key' '
951 git config --unset trailer.review.key &&
952 cat >expected <<-EOF &&
954 review: Junio
955 sign: A U Thor <author@example.com>
957 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
959 test_cmp expected actual
962 test_done