003e90f8cf94f0bb2e70b47f59b54bf20c50c777
1#!/bin/sh
2#
3# Copyright (c) 2013, 2014 Christian Couder
4#
5
6test_description='git interpret-trailers'
7
8. ./test-lib.sh
9
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.
12
13test_expect_success 'setup' '
14 : >empty &&
15 cat >basic_message <<-\EOF &&
16 subject
17
18 body
19 EOF
20 cat >complex_message_body <<-\EOF &&
21 my subject
22
23 my body which is long
24 and contains some special
25 chars like : = ? !
26
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(-)
38
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 @@
44
45 -bar
46 +baz
47
48 --
49 1.9.rc0.11.ga562ddc
50
51 EOF
52'
53
54test_expect_success 'without config' '
55 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
56
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
64'
65
66test_expect_success 'without config in another order' '
67 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
68
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
76'
77
78test_expect_success '--trim-empty without config' '
79 cat >expected <<-\EOF &&
80
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
88'
89
90test_expect_success 'with config option on the command line' '
91 cat >expected <<-\EOF &&
92
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
100'
101
102test_expect_success 'with only a title in the message' '
103 cat >expected <<-\EOF &&
104 area: change
105
106 Reviewed-by: Peff
107 Acked-by: Johan
108 EOF
109 echo "area: change" |
110 git interpret-trailers --trailer "Reviewed-by: Peff" \
111 --trailer "Acked-by: Johan" >actual &&
112 test_cmp expected actual
113'
114
115test_expect_success 'with multiline title in the message' '
116 cat >expected <<-\EOF &&
117 place of
118 code: change
119
120 Reviewed-by: Peff
121 Acked-by: Johan
122 EOF
123 printf "%s\n" "place of" "code: change" |
124 git interpret-trailers --trailer "Reviewed-by: Peff" \
125 --trailer "Acked-by: Johan" >actual &&
126 test_cmp expected actual
127'
128
129test_expect_success 'with non-trailer lines mixed with Signed-off-by' '
130 cat >patch <<-\EOF &&
131
132 this is not a trailer
133 this is not a trailer
134 Signed-off-by: a <a@example.com>
135 this is not a trailer
136 EOF
137 cat >expected <<-\EOF &&
138
139 this is not a trailer
140 this is not a trailer
141 Signed-off-by: a <a@example.com>
142 this is not a trailer
143 token: value
144 EOF
145 git interpret-trailers --trailer "token: value" patch >actual &&
146 test_cmp expected actual
147'
148
149test_expect_success 'with non-trailer lines mixed with cherry picked from' '
150 cat >patch <<-\EOF &&
151
152 this is not a trailer
153 this is not a trailer
154 (cherry picked from commit x)
155 this is not a trailer
156 EOF
157 cat >expected <<-\EOF &&
158
159 this is not a trailer
160 this is not a trailer
161 (cherry picked from commit x)
162 this is not a trailer
163 token: value
164 EOF
165 git interpret-trailers --trailer "token: value" patch >actual &&
166 test_cmp expected actual
167'
168
169test_expect_success 'with non-trailer lines mixed with a configured trailer' '
170 cat >patch <<-\EOF &&
171
172 this is not a trailer
173 this is not a trailer
174 My-trailer: x
175 this is not a trailer
176 EOF
177 cat >expected <<-\EOF &&
178
179 this is not a trailer
180 this is not a trailer
181 My-trailer: x
182 this is not a trailer
183 token: value
184 EOF
185 test_config trailer.my.key "My-trailer: " &&
186 git interpret-trailers --trailer "token: value" patch >actual &&
187 test_cmp expected actual
188'
189
190test_expect_success 'with non-trailer lines mixed with a non-configured trailer' '
191 cat >patch <<-\EOF &&
192
193 this is not a trailer
194 this is not a trailer
195 I-am-not-configured: x
196 this is not a trailer
197 EOF
198 cat >expected <<-\EOF &&
199
200 this is not a trailer
201 this is not a trailer
202 I-am-not-configured: x
203 this is not a trailer
204
205 token: value
206 EOF
207 test_config trailer.my.key "My-trailer: " &&
208 git interpret-trailers --trailer "token: value" patch >actual &&
209 test_cmp expected actual
210'
211
212test_expect_success 'with all non-configured trailers' '
213 cat >patch <<-\EOF &&
214
215 I-am-not-configured: x
216 I-am-also-not-configured: x
217 EOF
218 cat >expected <<-\EOF &&
219
220 I-am-not-configured: x
221 I-am-also-not-configured: x
222 token: value
223 EOF
224 test_config trailer.my.key "My-trailer: " &&
225 git interpret-trailers --trailer "token: value" patch >actual &&
226 test_cmp expected actual
227'
228
229test_expect_success 'with non-trailer lines only' '
230 cat >patch <<-\EOF &&
231
232 this is not a trailer
233 EOF
234 cat >expected <<-\EOF &&
235
236 this is not a trailer
237
238 token: value
239 EOF
240 git interpret-trailers --trailer "token: value" patch >actual &&
241 test_cmp expected actual
242'
243
244test_expect_success 'with config setup' '
245 git config trailer.ack.key "Acked-by: " &&
246 cat >expected <<-\EOF &&
247
248 Acked-by: Peff
249 EOF
250 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
251 test_cmp expected actual &&
252 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
253 test_cmp expected actual &&
254 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
255 test_cmp expected actual
256'
257
258test_expect_success 'with config setup and ":=" as separators' '
259 git config trailer.separators ":=" &&
260 git config trailer.ack.key "Acked-by= " &&
261 cat >expected <<-\EOF &&
262
263 Acked-by= Peff
264 EOF
265 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
266 test_cmp expected actual &&
267 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
268 test_cmp expected actual &&
269 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
270 test_cmp expected actual
271'
272
273test_expect_success 'with config setup and "%" as separators' '
274 git config trailer.separators "%" &&
275 cat >expected <<-\EOF &&
276
277 bug% 42
278 count% 10
279 bug% 422
280 EOF
281 git interpret-trailers --trim-empty --trailer "bug = 42" \
282 --trailer count%10 --trailer "test: stuff" \
283 --trailer "bug % 422" empty >actual &&
284 test_cmp expected actual
285'
286
287test_expect_success 'with "%" as separators and a message with trailers' '
288 cat >special_message <<-\EOF &&
289 Special Message
290
291 bug% 42
292 count% 10
293 bug% 422
294 EOF
295 cat >expected <<-\EOF &&
296 Special Message
297
298 bug% 42
299 count% 10
300 bug% 422
301 count% 100
302 EOF
303 git interpret-trailers --trailer count%100 \
304 special_message >actual &&
305 test_cmp expected actual
306'
307
308test_expect_success 'with config setup and ":=#" as separators' '
309 git config trailer.separators ":=#" &&
310 git config trailer.bug.key "Bug #" &&
311 cat >expected <<-\EOF &&
312
313 Bug #42
314 EOF
315 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
316 test_cmp expected actual
317'
318
319test_expect_success 'with commit basic message' '
320 cat basic_message >expected &&
321 echo >>expected &&
322 git interpret-trailers <basic_message >actual &&
323 test_cmp expected actual
324'
325
326test_expect_success 'with basic patch' '
327 cat basic_message >input &&
328 cat basic_patch >>input &&
329 cat basic_message >expected &&
330 echo >>expected &&
331 cat basic_patch >>expected &&
332 git interpret-trailers <input >actual &&
333 test_cmp expected actual
334'
335
336test_expect_success 'with commit complex message as argument' '
337 cat complex_message_body complex_message_trailers >complex_message &&
338 cat complex_message_body >expected &&
339 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
340 Fixes: Z
341 Acked-by= Z
342 Reviewed-by: Z
343 Signed-off-by: Z
344 EOF
345 git interpret-trailers complex_message >actual &&
346 test_cmp expected actual
347'
348
349test_expect_success 'with 2 files arguments' '
350 cat basic_message >>expected &&
351 echo >>expected &&
352 cat basic_patch >>expected &&
353 git interpret-trailers complex_message input >actual &&
354 test_cmp expected actual
355'
356
357test_expect_success 'with message that has comments' '
358 cat basic_message >message_with_comments &&
359 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
360 # comment
361
362 # other comment
363 Cc: Z
364 # yet another comment
365 Reviewed-by: Johan
366 Reviewed-by: Z
367 # last comment
368
369 EOF
370 cat basic_patch >>message_with_comments &&
371 cat basic_message >expected &&
372 cat >>expected <<-\EOF &&
373 # comment
374
375 Reviewed-by: Johan
376 Cc: Peff
377 # last comment
378
379 EOF
380 cat basic_patch >>expected &&
381 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
382 test_cmp expected actual
383'
384
385test_expect_success 'with message that has an old style conflict block' '
386 cat basic_message >message_with_comments &&
387 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
388 # comment
389
390 # other comment
391 Cc: Z
392 # yet another comment
393 Reviewed-by: Johan
394 Reviewed-by: Z
395 # last comment
396
397 Conflicts:
398
399 EOF
400 cat basic_message >expected &&
401 cat >>expected <<-\EOF &&
402 # comment
403
404 Reviewed-by: Johan
405 Cc: Peff
406 # last comment
407
408 Conflicts:
409
410 EOF
411 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
412 test_cmp expected actual
413'
414
415test_expect_success 'with commit complex message and trailer args' '
416 cat complex_message_body >expected &&
417 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
418 Fixes: Z
419 Acked-by= Z
420 Reviewed-by: Z
421 Signed-off-by: Z
422 Acked-by= Peff
423 Bug #42
424 EOF
425 git interpret-trailers --trailer "ack: Peff" \
426 --trailer "bug: 42" <complex_message >actual &&
427 test_cmp expected actual
428'
429
430test_expect_success 'with complex patch, args and --trim-empty' '
431 cat complex_message >complex_patch &&
432 cat basic_patch >>complex_patch &&
433 cat complex_message_body >expected &&
434 cat >>expected <<-\EOF &&
435 Acked-by= Peff
436 Bug #42
437 EOF
438 cat basic_patch >>expected &&
439 git interpret-trailers --trim-empty --trailer "ack: Peff" \
440 --trailer "bug: 42" <complex_patch >actual &&
441 test_cmp expected actual
442'
443
444test_expect_success 'in-place editing with basic patch' '
445 cat basic_message >message &&
446 cat basic_patch >>message &&
447 cat basic_message >expected &&
448 echo >>expected &&
449 cat basic_patch >>expected &&
450 git interpret-trailers --in-place message &&
451 test_cmp expected message
452'
453
454test_expect_success 'in-place editing with additional trailer' '
455 cat basic_message >message &&
456 cat basic_patch >>message &&
457 cat basic_message >expected &&
458 echo >>expected &&
459 cat >>expected <<-\EOF &&
460 Reviewed-by: Alice
461 EOF
462 cat basic_patch >>expected &&
463 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
464 test_cmp expected message
465'
466
467test_expect_success 'in-place editing on stdin disallowed' '
468 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
469'
470
471test_expect_success 'in-place editing on non-existing file' '
472 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
473 test_path_is_missing nonexisting
474'
475
476test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" '
477 cat basic_message >message &&
478 chmod -r message &&
479 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
480 chmod +r message &&
481 test_cmp message basic_message
482'
483
484test_expect_success 'using "where = before"' '
485 git config trailer.bug.where "before" &&
486 cat complex_message_body >expected &&
487 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
488 Bug #42
489 Fixes: Z
490 Acked-by= Z
491 Reviewed-by: Z
492 Signed-off-by: Z
493 Acked-by= Peff
494 EOF
495 git interpret-trailers --trailer "ack: Peff" \
496 --trailer "bug: 42" complex_message >actual &&
497 test_cmp expected actual
498'
499
500test_expect_success 'using "where = after"' '
501 git config trailer.ack.where "after" &&
502 cat complex_message_body >expected &&
503 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
504 Bug #42
505 Fixes: Z
506 Acked-by= Z
507 Acked-by= Peff
508 Reviewed-by: Z
509 Signed-off-by: Z
510 EOF
511 git interpret-trailers --trailer "ack: Peff" \
512 --trailer "bug: 42" complex_message >actual &&
513 test_cmp expected actual
514'
515
516test_expect_success 'using "where = end"' '
517 git config trailer.review.key "Reviewed-by" &&
518 git config trailer.review.where "end" &&
519 cat complex_message_body >expected &&
520 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
521 Fixes: Z
522 Acked-by= Z
523 Acked-by= Peff
524 Reviewed-by: Z
525 Signed-off-by: Z
526 Reviewed-by: Junio
527 Reviewed-by: Johannes
528 EOF
529 git interpret-trailers --trailer "ack: Peff" \
530 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
531 complex_message >actual &&
532 test_cmp expected actual
533'
534
535test_expect_success 'using "where = start"' '
536 git config trailer.review.key "Reviewed-by" &&
537 git config trailer.review.where "start" &&
538 cat complex_message_body >expected &&
539 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
540 Reviewed-by: Johannes
541 Reviewed-by: Junio
542 Fixes: Z
543 Acked-by= Z
544 Acked-by= Peff
545 Reviewed-by: Z
546 Signed-off-by: Z
547 EOF
548 git interpret-trailers --trailer "ack: Peff" \
549 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
550 complex_message >actual &&
551 test_cmp expected actual
552'
553
554test_expect_success 'using "where = before" for a token in the middle of the message' '
555 git config trailer.review.key "Reviewed-by:" &&
556 git config trailer.review.where "before" &&
557 cat complex_message_body >expected &&
558 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
559 Bug #42
560 Fixes: Z
561 Acked-by= Z
562 Acked-by= Peff
563 Reviewed-by:Johan
564 Reviewed-by:
565 Signed-off-by: Z
566 EOF
567 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
568 --trailer "review: Johan" <complex_message >actual &&
569 test_cmp expected actual
570'
571
572test_expect_success 'using "where = before" and --trim-empty' '
573 cat complex_message_body >expected &&
574 cat >>expected <<-\EOF &&
575 Bug #46
576 Bug #42
577 Acked-by= Peff
578 Reviewed-by:Johan
579 EOF
580 git interpret-trailers --trim-empty --trailer "ack: Peff" \
581 --trailer "bug: 42" --trailer "review: Johan" \
582 --trailer "Bug: 46" <complex_message >actual &&
583 test_cmp expected actual
584'
585
586test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
587 cat complex_message_body >expected &&
588 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
589 Bug #42
590 Fixes: Z
591 Acked-by= Z
592 Acked-by= Peff
593 Acked-by= Junio
594 Acked-by= Peff
595 Reviewed-by:
596 Signed-off-by: Z
597 EOF
598 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
599 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
600 --trailer "ack: Peff" <complex_message >actual &&
601 test_cmp expected actual
602'
603
604test_expect_success 'default "ifExists" is now "addIfDifferent"' '
605 git config trailer.ifexists "addIfDifferent" &&
606 cat complex_message_body >expected &&
607 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
608 Bug #42
609 Fixes: Z
610 Acked-by= Z
611 Acked-by= Peff
612 Acked-by= Junio
613 Reviewed-by:
614 Signed-off-by: Z
615 EOF
616 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
617 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
618 --trailer "ack: Peff" <complex_message >actual &&
619 test_cmp expected actual
620'
621
622test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
623 git config trailer.ack.ifExists "addIfDifferent" &&
624 git config trailer.ack.where "end" &&
625 cat complex_message_body >expected &&
626 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
627 Bug #42
628 Fixes: Z
629 Acked-by= Z
630 Reviewed-by:
631 Signed-off-by: Z
632 Acked-by= Peff
633 EOF
634 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
635 --trailer "bug: 42" --trailer "ack: Peff" \
636 <complex_message >actual &&
637 test_cmp expected actual
638'
639
640test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
641 git config trailer.ack.ifExists "addIfDifferent" &&
642 git config trailer.ack.where "before" &&
643 cat complex_message_body >expected &&
644 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
645 Bug #42
646 Fixes: Z
647 Acked-by= Peff
648 Acked-by= Z
649 Reviewed-by:
650 Signed-off-by: Z
651 EOF
652 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
653 --trailer "bug: 42" --trailer "ack: Peff" \
654 <complex_message >actual &&
655 test_cmp expected actual
656'
657
658test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
659 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
660 git config trailer.ack.where "end" &&
661 cat complex_message_body >expected &&
662 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
663 Bug #42
664 Fixes: Z
665 Acked-by= Z
666 Reviewed-by:
667 Signed-off-by: Z
668 Acked-by= Peff
669 Acked-by= Junio
670 Tested-by: Jakub
671 Acked-by= Junio
672 Acked-by= Peff
673 EOF
674 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
675 --trailer "ack: Junio" --trailer "bug: 42" \
676 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
677 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
678 test_cmp expected actual
679'
680
681test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
682 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
683 git config trailer.ack.where "after" &&
684 cat complex_message_body >expected &&
685 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
686 Bug #42
687 Fixes: Z
688 Acked-by= Z
689 Acked-by= Peff
690 Acked-by= Junio
691 Acked-by= Peff
692 Reviewed-by:
693 Signed-off-by: Z
694 Tested-by: Jakub
695 EOF
696 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
697 --trailer "ack: Junio" --trailer "bug: 42" \
698 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
699 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
700 test_cmp expected actual
701'
702
703test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
704 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
705 cat complex_message_body >expected &&
706 cat >>expected <<-\EOF &&
707 Bug #42
708 Acked-by= Peff
709 Acked-by= Junio
710 Acked-by= Peff
711 EOF
712 git interpret-trailers --trim-empty --trailer "ack: Peff" \
713 --trailer "Acked-by= Peff" --trailer "review:" \
714 --trailer "ack: Junio" --trailer "bug: 42" \
715 --trailer "ack: Peff" <complex_message >actual &&
716 test_cmp expected actual
717'
718
719test_expect_success 'using "ifExists = add" with "where = end"' '
720 git config trailer.ack.ifExists "add" &&
721 git config trailer.ack.where "end" &&
722 cat complex_message_body >expected &&
723 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
724 Bug #42
725 Fixes: Z
726 Acked-by= Z
727 Reviewed-by:
728 Signed-off-by: Z
729 Acked-by= Peff
730 Acked-by= Peff
731 Tested-by: Jakub
732 Acked-by= Junio
733 Tested-by: Johannes
734 Acked-by= Peff
735 EOF
736 git interpret-trailers --trailer "ack: Peff" \
737 --trailer "Acked-by= Peff" --trailer "review:" \
738 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
739 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
740 --trailer "ack: Peff" <complex_message >actual &&
741 test_cmp expected actual
742'
743
744test_expect_success 'using "ifExists = add" with "where = after"' '
745 git config trailer.ack.ifExists "add" &&
746 git config trailer.ack.where "after" &&
747 cat complex_message_body >expected &&
748 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
749 Bug #42
750 Fixes: Z
751 Acked-by= Z
752 Acked-by= Peff
753 Acked-by= Peff
754 Acked-by= Junio
755 Acked-by= Peff
756 Reviewed-by:
757 Signed-off-by: Z
758 EOF
759 git interpret-trailers --trailer "ack: Peff" \
760 --trailer "Acked-by= Peff" --trailer "review:" \
761 --trailer "ack: Junio" --trailer "bug: 42" \
762 --trailer "ack: Peff" <complex_message >actual &&
763 test_cmp expected actual
764'
765
766test_expect_success 'using "ifExists = replace"' '
767 git config trailer.fix.key "Fixes: " &&
768 git config trailer.fix.ifExists "replace" &&
769 cat complex_message_body >expected &&
770 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
771 Bug #42
772 Acked-by= Z
773 Acked-by= Junio
774 Acked-by= Peff
775 Reviewed-by:
776 Signed-off-by: Z
777 Fixes: 22
778 EOF
779 git interpret-trailers --trailer "review:" \
780 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
781 --trailer "bug: 42" --trailer "ack: Peff" \
782 <complex_message >actual &&
783 test_cmp expected actual
784'
785
786test_expect_success 'using "ifExists = replace" with "where = after"' '
787 git config trailer.fix.where "after" &&
788 cat complex_message_body >expected &&
789 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
790 Bug #42
791 Fixes: 22
792 Acked-by= Z
793 Acked-by= Junio
794 Acked-by= Peff
795 Reviewed-by:
796 Signed-off-by: Z
797 EOF
798 git interpret-trailers --trailer "review:" \
799 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
800 --trailer "bug: 42" --trailer "ack: Peff" \
801 <complex_message >actual &&
802 test_cmp expected actual
803'
804
805test_expect_success 'using "ifExists = doNothing"' '
806 git config trailer.fix.ifExists "doNothing" &&
807 cat complex_message_body >expected &&
808 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
809 Bug #42
810 Fixes: Z
811 Acked-by= Z
812 Acked-by= Junio
813 Acked-by= Peff
814 Reviewed-by:
815 Signed-off-by: Z
816 EOF
817 git interpret-trailers --trailer "review:" --trailer "fix=53" \
818 --trailer "ack: Junio" --trailer "fix=22" \
819 --trailer "bug: 42" --trailer "ack: Peff" \
820 <complex_message >actual &&
821 test_cmp expected actual
822'
823
824test_expect_success 'the default is "ifMissing = add"' '
825 git config trailer.cc.key "Cc: " &&
826 git config trailer.cc.where "before" &&
827 cat complex_message_body >expected &&
828 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
829 Bug #42
830 Cc: Linus
831 Fixes: Z
832 Acked-by= Z
833 Acked-by= Junio
834 Acked-by= Peff
835 Reviewed-by:
836 Signed-off-by: Z
837 EOF
838 git interpret-trailers --trailer "review:" --trailer "fix=53" \
839 --trailer "cc=Linus" --trailer "ack: Junio" \
840 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
841 <complex_message >actual &&
842 test_cmp expected actual
843'
844
845test_expect_success 'when default "ifMissing" is "doNothing"' '
846 git config trailer.ifmissing "doNothing" &&
847 cat complex_message_body >expected &&
848 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
849 Fixes: Z
850 Acked-by= Z
851 Acked-by= Junio
852 Acked-by= Peff
853 Reviewed-by:
854 Signed-off-by: Z
855 EOF
856 git interpret-trailers --trailer "review:" --trailer "fix=53" \
857 --trailer "cc=Linus" --trailer "ack: Junio" \
858 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
859 <complex_message >actual &&
860 test_cmp expected actual &&
861 git config trailer.ifmissing "add"
862'
863
864test_expect_success 'using "ifMissing = add" with "where = end"' '
865 git config trailer.cc.key "Cc: " &&
866 git config trailer.cc.where "end" &&
867 git config trailer.cc.ifMissing "add" &&
868 cat complex_message_body >expected &&
869 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
870 Bug #42
871 Fixes: Z
872 Acked-by= Z
873 Acked-by= Junio
874 Acked-by= Peff
875 Reviewed-by:
876 Signed-off-by: Z
877 Cc: Linus
878 EOF
879 git interpret-trailers --trailer "review:" --trailer "fix=53" \
880 --trailer "ack: Junio" --trailer "fix=22" \
881 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
882 <complex_message >actual &&
883 test_cmp expected actual
884'
885
886test_expect_success 'using "ifMissing = add" with "where = before"' '
887 git config trailer.cc.key "Cc: " &&
888 git config trailer.cc.where "before" &&
889 git config trailer.cc.ifMissing "add" &&
890 cat complex_message_body >expected &&
891 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
892 Cc: Linus
893 Bug #42
894 Fixes: Z
895 Acked-by= Z
896 Acked-by= Junio
897 Acked-by= Peff
898 Reviewed-by:
899 Signed-off-by: Z
900 EOF
901 git interpret-trailers --trailer "review:" --trailer "fix=53" \
902 --trailer "ack: Junio" --trailer "fix=22" \
903 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
904 <complex_message >actual &&
905 test_cmp expected actual
906'
907
908test_expect_success 'using "ifMissing = doNothing"' '
909 git config trailer.cc.ifMissing "doNothing" &&
910 cat complex_message_body >expected &&
911 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
912 Bug #42
913 Fixes: Z
914 Acked-by= Z
915 Acked-by= Junio
916 Acked-by= Peff
917 Reviewed-by:
918 Signed-off-by: Z
919 EOF
920 git interpret-trailers --trailer "review:" --trailer "fix=53" \
921 --trailer "cc=Linus" --trailer "ack: Junio" \
922 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
923 <complex_message >actual &&
924 test_cmp expected actual
925'
926
927test_expect_success 'default "where" is now "after"' '
928 git config trailer.where "after" &&
929 git config --unset trailer.ack.where &&
930 cat complex_message_body >expected &&
931 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
932 Bug #42
933 Fixes: Z
934 Acked-by= Z
935 Acked-by= Peff
936 Acked-by= Peff
937 Acked-by= Junio
938 Acked-by= Peff
939 Reviewed-by:
940 Signed-off-by: Z
941 Tested-by: Jakub
942 Tested-by: Johannes
943 EOF
944 git interpret-trailers --trailer "ack: Peff" \
945 --trailer "Acked-by= Peff" --trailer "review:" \
946 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
947 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
948 --trailer "ack: Peff" <complex_message >actual &&
949 test_cmp expected actual
950'
951
952test_expect_success 'with simple command' '
953 git config trailer.sign.key "Signed-off-by: " &&
954 git config trailer.sign.where "after" &&
955 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
956 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
957 cat complex_message_body >expected &&
958 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
959 Fixes: Z
960 Acked-by= Z
961 Reviewed-by:
962 Signed-off-by: Z
963 Signed-off-by: A U Thor <author@example.com>
964 EOF
965 git interpret-trailers --trailer "review:" --trailer "fix=22" \
966 <complex_message >actual &&
967 test_cmp expected actual
968'
969
970test_expect_success 'with command using commiter information' '
971 git config trailer.sign.ifExists "addIfDifferent" &&
972 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
973 cat complex_message_body >expected &&
974 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
975 Fixes: Z
976 Acked-by= Z
977 Reviewed-by:
978 Signed-off-by: Z
979 Signed-off-by: C O Mitter <committer@example.com>
980 EOF
981 git interpret-trailers --trailer "review:" --trailer "fix=22" \
982 <complex_message >actual &&
983 test_cmp expected actual
984'
985
986test_expect_success 'with command using author information' '
987 git config trailer.sign.key "Signed-off-by: " &&
988 git config trailer.sign.where "after" &&
989 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
990 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
991 cat complex_message_body >expected &&
992 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
993 Fixes: Z
994 Acked-by= Z
995 Reviewed-by:
996 Signed-off-by: Z
997 Signed-off-by: A U Thor <author@example.com>
998 EOF
999 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1000 <complex_message >actual &&
1001 test_cmp expected actual
1002'
1003
1004test_expect_success 'setup a commit' '
1005 echo "Content of the first commit." > a.txt &&
1006 git add a.txt &&
1007 git commit -m "Add file a.txt"
1008'
1009
1010test_expect_success 'with command using $ARG' '
1011 git config trailer.fix.ifExists "replace" &&
1012 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1013 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1014 cat complex_message_body >expected &&
1015 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1016 Fixes: $FIXED
1017 Acked-by= Z
1018 Reviewed-by:
1019 Signed-off-by: Z
1020 Signed-off-by: A U Thor <author@example.com>
1021 EOF
1022 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1023 <complex_message >actual &&
1024 test_cmp expected actual
1025'
1026
1027test_expect_success 'with failing command using $ARG' '
1028 git config trailer.fix.ifExists "replace" &&
1029 git config trailer.fix.command "false \$ARG" &&
1030 cat complex_message_body >expected &&
1031 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1032 Fixes: Z
1033 Acked-by= Z
1034 Reviewed-by:
1035 Signed-off-by: Z
1036 Signed-off-by: A U Thor <author@example.com>
1037 EOF
1038 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1039 <complex_message >actual &&
1040 test_cmp expected actual
1041'
1042
1043test_expect_success 'with empty tokens' '
1044 git config --unset trailer.fix.command &&
1045 cat >expected <<-EOF &&
1046
1047 Signed-off-by: A U Thor <author@example.com>
1048 EOF
1049 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1050 EOF
1051 test_cmp expected actual
1052'
1053
1054test_expect_success 'with command but no key' '
1055 git config --unset trailer.sign.key &&
1056 cat >expected <<-EOF &&
1057
1058 sign: A U Thor <author@example.com>
1059 EOF
1060 git interpret-trailers >actual <<-EOF &&
1061 EOF
1062 test_cmp expected actual
1063'
1064
1065test_expect_success 'with no command and no key' '
1066 git config --unset trailer.review.key &&
1067 cat >expected <<-EOF &&
1068
1069 review: Junio
1070 sign: A U Thor <author@example.com>
1071 EOF
1072 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1073 EOF
1074 test_cmp expected actual
1075'
1076
1077test_done