3d94b3a2f76c9cd04635733bd852df4495987a0f
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 'line with leading whitespace is not trailer' '
245 q_to_tab >patch <<-\EOF &&
246
247 Qtoken: value
248 EOF
249 q_to_tab >expected <<-\EOF &&
250
251 Qtoken: value
252
253 token: value
254 EOF
255 git interpret-trailers --trailer "token: value" patch >actual &&
256 test_cmp expected actual
257'
258
259test_expect_success 'with config setup' '
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 git config trailer.ack.key "Acked-by= " &&
276 cat >expected <<-\EOF &&
277
278 Acked-by= Peff
279 EOF
280 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
281 test_cmp expected actual &&
282 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
283 test_cmp expected actual &&
284 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
285 test_cmp expected actual
286'
287
288test_expect_success 'with config setup and "%" as separators' '
289 git config trailer.separators "%" &&
290 cat >expected <<-\EOF &&
291
292 bug% 42
293 count% 10
294 bug% 422
295 EOF
296 git interpret-trailers --trim-empty --trailer "bug = 42" \
297 --trailer count%10 --trailer "test: stuff" \
298 --trailer "bug % 422" empty >actual &&
299 test_cmp expected actual
300'
301
302test_expect_success 'with "%" as separators and a message with trailers' '
303 cat >special_message <<-\EOF &&
304 Special Message
305
306 bug% 42
307 count% 10
308 bug% 422
309 EOF
310 cat >expected <<-\EOF &&
311 Special Message
312
313 bug% 42
314 count% 10
315 bug% 422
316 count% 100
317 EOF
318 git interpret-trailers --trailer count%100 \
319 special_message >actual &&
320 test_cmp expected actual
321'
322
323test_expect_success 'with config setup and ":=#" as separators' '
324 git config trailer.separators ":=#" &&
325 git config trailer.bug.key "Bug #" &&
326 cat >expected <<-\EOF &&
327
328 Bug #42
329 EOF
330 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
331 test_cmp expected actual
332'
333
334test_expect_success 'with commit basic message' '
335 cat basic_message >expected &&
336 echo >>expected &&
337 git interpret-trailers <basic_message >actual &&
338 test_cmp expected actual
339'
340
341test_expect_success 'with basic patch' '
342 cat basic_message >input &&
343 cat basic_patch >>input &&
344 cat basic_message >expected &&
345 echo >>expected &&
346 cat basic_patch >>expected &&
347 git interpret-trailers <input >actual &&
348 test_cmp expected actual
349'
350
351test_expect_success 'with commit complex message as argument' '
352 cat complex_message_body complex_message_trailers >complex_message &&
353 cat complex_message_body >expected &&
354 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
355 Fixes: Z
356 Acked-by= Z
357 Reviewed-by: Z
358 Signed-off-by: Z
359 EOF
360 git interpret-trailers complex_message >actual &&
361 test_cmp expected actual
362'
363
364test_expect_success 'with 2 files arguments' '
365 cat basic_message >>expected &&
366 echo >>expected &&
367 cat basic_patch >>expected &&
368 git interpret-trailers complex_message input >actual &&
369 test_cmp expected actual
370'
371
372test_expect_success 'with message that has comments' '
373 cat basic_message >message_with_comments &&
374 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
375 # comment
376
377 # other comment
378 Cc: Z
379 # yet another comment
380 Reviewed-by: Johan
381 Reviewed-by: Z
382 # last comment
383
384 EOF
385 cat basic_patch >>message_with_comments &&
386 cat basic_message >expected &&
387 cat >>expected <<-\EOF &&
388 # comment
389
390 Reviewed-by: Johan
391 Cc: Peff
392 # last comment
393
394 EOF
395 cat basic_patch >>expected &&
396 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
397 test_cmp expected actual
398'
399
400test_expect_success 'with message that has an old style conflict block' '
401 cat basic_message >message_with_comments &&
402 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
403 # comment
404
405 # other comment
406 Cc: Z
407 # yet another comment
408 Reviewed-by: Johan
409 Reviewed-by: Z
410 # last comment
411
412 Conflicts:
413
414 EOF
415 cat basic_message >expected &&
416 cat >>expected <<-\EOF &&
417 # comment
418
419 Reviewed-by: Johan
420 Cc: Peff
421 # last comment
422
423 Conflicts:
424
425 EOF
426 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
427 test_cmp expected actual
428'
429
430test_expect_success 'with commit complex message and trailer args' '
431 cat complex_message_body >expected &&
432 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
433 Fixes: Z
434 Acked-by= Z
435 Reviewed-by: Z
436 Signed-off-by: Z
437 Acked-by= Peff
438 Bug #42
439 EOF
440 git interpret-trailers --trailer "ack: Peff" \
441 --trailer "bug: 42" <complex_message >actual &&
442 test_cmp expected actual
443'
444
445test_expect_success 'with complex patch, args and --trim-empty' '
446 cat complex_message >complex_patch &&
447 cat basic_patch >>complex_patch &&
448 cat complex_message_body >expected &&
449 cat >>expected <<-\EOF &&
450 Acked-by= Peff
451 Bug #42
452 EOF
453 cat basic_patch >>expected &&
454 git interpret-trailers --trim-empty --trailer "ack: Peff" \
455 --trailer "bug: 42" <complex_patch >actual &&
456 test_cmp expected actual
457'
458
459test_expect_success 'in-place editing with basic patch' '
460 cat basic_message >message &&
461 cat basic_patch >>message &&
462 cat basic_message >expected &&
463 echo >>expected &&
464 cat basic_patch >>expected &&
465 git interpret-trailers --in-place message &&
466 test_cmp expected message
467'
468
469test_expect_success 'in-place editing with additional trailer' '
470 cat basic_message >message &&
471 cat basic_patch >>message &&
472 cat basic_message >expected &&
473 echo >>expected &&
474 cat >>expected <<-\EOF &&
475 Reviewed-by: Alice
476 EOF
477 cat basic_patch >>expected &&
478 git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
479 test_cmp expected message
480'
481
482test_expect_success 'in-place editing on stdin disallowed' '
483 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
484'
485
486test_expect_success 'in-place editing on non-existing file' '
487 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
488 test_path_is_missing nonexisting
489'
490
491test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" '
492 cat basic_message >message &&
493 chmod -r message &&
494 test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
495 chmod +r message &&
496 test_cmp message basic_message
497'
498
499test_expect_success 'using "where = before"' '
500 git config trailer.bug.where "before" &&
501 cat complex_message_body >expected &&
502 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
503 Bug #42
504 Fixes: Z
505 Acked-by= Z
506 Reviewed-by: Z
507 Signed-off-by: Z
508 Acked-by= Peff
509 EOF
510 git interpret-trailers --trailer "ack: Peff" \
511 --trailer "bug: 42" complex_message >actual &&
512 test_cmp expected actual
513'
514
515test_expect_success 'using "where = after"' '
516 git config trailer.ack.where "after" &&
517 cat complex_message_body >expected &&
518 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
519 Bug #42
520 Fixes: Z
521 Acked-by= Z
522 Acked-by= Peff
523 Reviewed-by: Z
524 Signed-off-by: Z
525 EOF
526 git interpret-trailers --trailer "ack: Peff" \
527 --trailer "bug: 42" complex_message >actual &&
528 test_cmp expected actual
529'
530
531test_expect_success 'using "where = end"' '
532 git config trailer.review.key "Reviewed-by" &&
533 git config trailer.review.where "end" &&
534 cat complex_message_body >expected &&
535 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
536 Fixes: Z
537 Acked-by= Z
538 Acked-by= Peff
539 Reviewed-by: Z
540 Signed-off-by: Z
541 Reviewed-by: Junio
542 Reviewed-by: Johannes
543 EOF
544 git interpret-trailers --trailer "ack: Peff" \
545 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
546 complex_message >actual &&
547 test_cmp expected actual
548'
549
550test_expect_success 'using "where = start"' '
551 git config trailer.review.key "Reviewed-by" &&
552 git config trailer.review.where "start" &&
553 cat complex_message_body >expected &&
554 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
555 Reviewed-by: Johannes
556 Reviewed-by: Junio
557 Fixes: Z
558 Acked-by= Z
559 Acked-by= Peff
560 Reviewed-by: Z
561 Signed-off-by: Z
562 EOF
563 git interpret-trailers --trailer "ack: Peff" \
564 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
565 complex_message >actual &&
566 test_cmp expected actual
567'
568
569test_expect_success 'using "where = before" for a token in the middle of the message' '
570 git config trailer.review.key "Reviewed-by:" &&
571 git config trailer.review.where "before" &&
572 cat complex_message_body >expected &&
573 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
574 Bug #42
575 Fixes: Z
576 Acked-by= Z
577 Acked-by= Peff
578 Reviewed-by:Johan
579 Reviewed-by:
580 Signed-off-by: Z
581 EOF
582 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
583 --trailer "review: Johan" <complex_message >actual &&
584 test_cmp expected actual
585'
586
587test_expect_success 'using "where = before" and --trim-empty' '
588 cat complex_message_body >expected &&
589 cat >>expected <<-\EOF &&
590 Bug #46
591 Bug #42
592 Acked-by= Peff
593 Reviewed-by:Johan
594 EOF
595 git interpret-trailers --trim-empty --trailer "ack: Peff" \
596 --trailer "bug: 42" --trailer "review: Johan" \
597 --trailer "Bug: 46" <complex_message >actual &&
598 test_cmp expected actual
599'
600
601test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
602 cat complex_message_body >expected &&
603 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
604 Bug #42
605 Fixes: Z
606 Acked-by= Z
607 Acked-by= Peff
608 Acked-by= Junio
609 Acked-by= Peff
610 Reviewed-by:
611 Signed-off-by: Z
612 EOF
613 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
614 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
615 --trailer "ack: Peff" <complex_message >actual &&
616 test_cmp expected actual
617'
618
619test_expect_success 'default "ifExists" is now "addIfDifferent"' '
620 git config trailer.ifexists "addIfDifferent" &&
621 cat complex_message_body >expected &&
622 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
623 Bug #42
624 Fixes: Z
625 Acked-by= Z
626 Acked-by= Peff
627 Acked-by= Junio
628 Reviewed-by:
629 Signed-off-by: Z
630 EOF
631 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
632 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
633 --trailer "ack: Peff" <complex_message >actual &&
634 test_cmp expected actual
635'
636
637test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
638 git config trailer.ack.ifExists "addIfDifferent" &&
639 git config trailer.ack.where "end" &&
640 cat complex_message_body >expected &&
641 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
642 Bug #42
643 Fixes: Z
644 Acked-by= Z
645 Reviewed-by:
646 Signed-off-by: Z
647 Acked-by= Peff
648 EOF
649 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
650 --trailer "bug: 42" --trailer "ack: Peff" \
651 <complex_message >actual &&
652 test_cmp expected actual
653'
654
655test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
656 git config trailer.ack.ifExists "addIfDifferent" &&
657 git config trailer.ack.where "before" &&
658 cat complex_message_body >expected &&
659 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
660 Bug #42
661 Fixes: Z
662 Acked-by= Peff
663 Acked-by= Z
664 Reviewed-by:
665 Signed-off-by: Z
666 EOF
667 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
668 --trailer "bug: 42" --trailer "ack: Peff" \
669 <complex_message >actual &&
670 test_cmp expected actual
671'
672
673test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
674 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
675 git config trailer.ack.where "end" &&
676 cat complex_message_body >expected &&
677 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
678 Bug #42
679 Fixes: Z
680 Acked-by= Z
681 Reviewed-by:
682 Signed-off-by: Z
683 Acked-by= Peff
684 Acked-by= Junio
685 Tested-by: Jakub
686 Acked-by= Junio
687 Acked-by= Peff
688 EOF
689 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
690 --trailer "ack: Junio" --trailer "bug: 42" \
691 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
692 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
693 test_cmp expected actual
694'
695
696test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
697 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
698 git config trailer.ack.where "after" &&
699 cat complex_message_body >expected &&
700 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
701 Bug #42
702 Fixes: Z
703 Acked-by= Z
704 Acked-by= Peff
705 Acked-by= Junio
706 Acked-by= Peff
707 Reviewed-by:
708 Signed-off-by: Z
709 Tested-by: Jakub
710 EOF
711 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
712 --trailer "ack: Junio" --trailer "bug: 42" \
713 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
714 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
715 test_cmp expected actual
716'
717
718test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
719 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
720 cat complex_message_body >expected &&
721 cat >>expected <<-\EOF &&
722 Bug #42
723 Acked-by= Peff
724 Acked-by= Junio
725 Acked-by= Peff
726 EOF
727 git interpret-trailers --trim-empty --trailer "ack: Peff" \
728 --trailer "Acked-by= Peff" --trailer "review:" \
729 --trailer "ack: Junio" --trailer "bug: 42" \
730 --trailer "ack: Peff" <complex_message >actual &&
731 test_cmp expected actual
732'
733
734test_expect_success 'using "ifExists = add" with "where = end"' '
735 git config trailer.ack.ifExists "add" &&
736 git config trailer.ack.where "end" &&
737 cat complex_message_body >expected &&
738 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
739 Bug #42
740 Fixes: Z
741 Acked-by= Z
742 Reviewed-by:
743 Signed-off-by: Z
744 Acked-by= Peff
745 Acked-by= Peff
746 Tested-by: Jakub
747 Acked-by= Junio
748 Tested-by: Johannes
749 Acked-by= Peff
750 EOF
751 git interpret-trailers --trailer "ack: Peff" \
752 --trailer "Acked-by= Peff" --trailer "review:" \
753 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
754 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
755 --trailer "ack: Peff" <complex_message >actual &&
756 test_cmp expected actual
757'
758
759test_expect_success 'using "ifExists = add" with "where = after"' '
760 git config trailer.ack.ifExists "add" &&
761 git config trailer.ack.where "after" &&
762 cat complex_message_body >expected &&
763 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
764 Bug #42
765 Fixes: Z
766 Acked-by= Z
767 Acked-by= Peff
768 Acked-by= Peff
769 Acked-by= Junio
770 Acked-by= Peff
771 Reviewed-by:
772 Signed-off-by: Z
773 EOF
774 git interpret-trailers --trailer "ack: Peff" \
775 --trailer "Acked-by= Peff" --trailer "review:" \
776 --trailer "ack: Junio" --trailer "bug: 42" \
777 --trailer "ack: Peff" <complex_message >actual &&
778 test_cmp expected actual
779'
780
781test_expect_success 'using "ifExists = replace"' '
782 git config trailer.fix.key "Fixes: " &&
783 git config trailer.fix.ifExists "replace" &&
784 cat complex_message_body >expected &&
785 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
786 Bug #42
787 Acked-by= Z
788 Acked-by= Junio
789 Acked-by= Peff
790 Reviewed-by:
791 Signed-off-by: Z
792 Fixes: 22
793 EOF
794 git interpret-trailers --trailer "review:" \
795 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
796 --trailer "bug: 42" --trailer "ack: Peff" \
797 <complex_message >actual &&
798 test_cmp expected actual
799'
800
801test_expect_success 'using "ifExists = replace" with "where = after"' '
802 git config trailer.fix.where "after" &&
803 cat complex_message_body >expected &&
804 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
805 Bug #42
806 Fixes: 22
807 Acked-by= Z
808 Acked-by= Junio
809 Acked-by= Peff
810 Reviewed-by:
811 Signed-off-by: Z
812 EOF
813 git interpret-trailers --trailer "review:" \
814 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
815 --trailer "bug: 42" --trailer "ack: Peff" \
816 <complex_message >actual &&
817 test_cmp expected actual
818'
819
820test_expect_success 'using "ifExists = doNothing"' '
821 git config trailer.fix.ifExists "doNothing" &&
822 cat complex_message_body >expected &&
823 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
824 Bug #42
825 Fixes: Z
826 Acked-by= Z
827 Acked-by= Junio
828 Acked-by= Peff
829 Reviewed-by:
830 Signed-off-by: Z
831 EOF
832 git interpret-trailers --trailer "review:" --trailer "fix=53" \
833 --trailer "ack: Junio" --trailer "fix=22" \
834 --trailer "bug: 42" --trailer "ack: Peff" \
835 <complex_message >actual &&
836 test_cmp expected actual
837'
838
839test_expect_success 'the default is "ifMissing = add"' '
840 git config trailer.cc.key "Cc: " &&
841 git config trailer.cc.where "before" &&
842 cat complex_message_body >expected &&
843 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
844 Bug #42
845 Cc: Linus
846 Fixes: Z
847 Acked-by= Z
848 Acked-by= Junio
849 Acked-by= Peff
850 Reviewed-by:
851 Signed-off-by: Z
852 EOF
853 git interpret-trailers --trailer "review:" --trailer "fix=53" \
854 --trailer "cc=Linus" --trailer "ack: Junio" \
855 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
856 <complex_message >actual &&
857 test_cmp expected actual
858'
859
860test_expect_success 'when default "ifMissing" is "doNothing"' '
861 git config trailer.ifmissing "doNothing" &&
862 cat complex_message_body >expected &&
863 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
864 Fixes: Z
865 Acked-by= Z
866 Acked-by= Junio
867 Acked-by= Peff
868 Reviewed-by:
869 Signed-off-by: Z
870 EOF
871 git interpret-trailers --trailer "review:" --trailer "fix=53" \
872 --trailer "cc=Linus" --trailer "ack: Junio" \
873 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
874 <complex_message >actual &&
875 test_cmp expected actual &&
876 git config trailer.ifmissing "add"
877'
878
879test_expect_success 'using "ifMissing = add" with "where = end"' '
880 git config trailer.cc.key "Cc: " &&
881 git config trailer.cc.where "end" &&
882 git config trailer.cc.ifMissing "add" &&
883 cat complex_message_body >expected &&
884 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
885 Bug #42
886 Fixes: Z
887 Acked-by= Z
888 Acked-by= Junio
889 Acked-by= Peff
890 Reviewed-by:
891 Signed-off-by: Z
892 Cc: Linus
893 EOF
894 git interpret-trailers --trailer "review:" --trailer "fix=53" \
895 --trailer "ack: Junio" --trailer "fix=22" \
896 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
897 <complex_message >actual &&
898 test_cmp expected actual
899'
900
901test_expect_success 'using "ifMissing = add" with "where = before"' '
902 git config trailer.cc.key "Cc: " &&
903 git config trailer.cc.where "before" &&
904 git config trailer.cc.ifMissing "add" &&
905 cat complex_message_body >expected &&
906 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
907 Cc: Linus
908 Bug #42
909 Fixes: Z
910 Acked-by= Z
911 Acked-by= Junio
912 Acked-by= Peff
913 Reviewed-by:
914 Signed-off-by: Z
915 EOF
916 git interpret-trailers --trailer "review:" --trailer "fix=53" \
917 --trailer "ack: Junio" --trailer "fix=22" \
918 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
919 <complex_message >actual &&
920 test_cmp expected actual
921'
922
923test_expect_success 'using "ifMissing = doNothing"' '
924 git config trailer.cc.ifMissing "doNothing" &&
925 cat complex_message_body >expected &&
926 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
927 Bug #42
928 Fixes: Z
929 Acked-by= Z
930 Acked-by= Junio
931 Acked-by= Peff
932 Reviewed-by:
933 Signed-off-by: Z
934 EOF
935 git interpret-trailers --trailer "review:" --trailer "fix=53" \
936 --trailer "cc=Linus" --trailer "ack: Junio" \
937 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
938 <complex_message >actual &&
939 test_cmp expected actual
940'
941
942test_expect_success 'default "where" is now "after"' '
943 git config trailer.where "after" &&
944 git config --unset trailer.ack.where &&
945 cat complex_message_body >expected &&
946 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
947 Bug #42
948 Fixes: Z
949 Acked-by= Z
950 Acked-by= Peff
951 Acked-by= Peff
952 Acked-by= Junio
953 Acked-by= Peff
954 Reviewed-by:
955 Signed-off-by: Z
956 Tested-by: Jakub
957 Tested-by: Johannes
958 EOF
959 git interpret-trailers --trailer "ack: Peff" \
960 --trailer "Acked-by= Peff" --trailer "review:" \
961 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
962 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
963 --trailer "ack: Peff" <complex_message >actual &&
964 test_cmp expected actual
965'
966
967test_expect_success 'with simple command' '
968 git config trailer.sign.key "Signed-off-by: " &&
969 git config trailer.sign.where "after" &&
970 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
971 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
972 cat complex_message_body >expected &&
973 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
974 Fixes: Z
975 Acked-by= Z
976 Reviewed-by:
977 Signed-off-by: Z
978 Signed-off-by: A U Thor <author@example.com>
979 EOF
980 git interpret-trailers --trailer "review:" --trailer "fix=22" \
981 <complex_message >actual &&
982 test_cmp expected actual
983'
984
985test_expect_success 'with command using commiter information' '
986 git config trailer.sign.ifExists "addIfDifferent" &&
987 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
988 cat complex_message_body >expected &&
989 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
990 Fixes: Z
991 Acked-by= Z
992 Reviewed-by:
993 Signed-off-by: Z
994 Signed-off-by: C O Mitter <committer@example.com>
995 EOF
996 git interpret-trailers --trailer "review:" --trailer "fix=22" \
997 <complex_message >actual &&
998 test_cmp expected actual
999'
1000
1001test_expect_success 'with command using author information' '
1002 git config trailer.sign.key "Signed-off-by: " &&
1003 git config trailer.sign.where "after" &&
1004 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
1005 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
1006 cat complex_message_body >expected &&
1007 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
1008 Fixes: Z
1009 Acked-by= Z
1010 Reviewed-by:
1011 Signed-off-by: Z
1012 Signed-off-by: A U Thor <author@example.com>
1013 EOF
1014 git interpret-trailers --trailer "review:" --trailer "fix=22" \
1015 <complex_message >actual &&
1016 test_cmp expected actual
1017'
1018
1019test_expect_success 'setup a commit' '
1020 echo "Content of the first commit." > a.txt &&
1021 git add a.txt &&
1022 git commit -m "Add file a.txt"
1023'
1024
1025test_expect_success 'with command using $ARG' '
1026 git config trailer.fix.ifExists "replace" &&
1027 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
1028 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
1029 cat complex_message_body >expected &&
1030 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1031 Fixes: $FIXED
1032 Acked-by= Z
1033 Reviewed-by:
1034 Signed-off-by: Z
1035 Signed-off-by: A U Thor <author@example.com>
1036 EOF
1037 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1038 <complex_message >actual &&
1039 test_cmp expected actual
1040'
1041
1042test_expect_success 'with failing command using $ARG' '
1043 git config trailer.fix.ifExists "replace" &&
1044 git config trailer.fix.command "false \$ARG" &&
1045 cat complex_message_body >expected &&
1046 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
1047 Fixes: Z
1048 Acked-by= Z
1049 Reviewed-by:
1050 Signed-off-by: Z
1051 Signed-off-by: A U Thor <author@example.com>
1052 EOF
1053 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
1054 <complex_message >actual &&
1055 test_cmp expected actual
1056'
1057
1058test_expect_success 'with empty tokens' '
1059 git config --unset trailer.fix.command &&
1060 cat >expected <<-EOF &&
1061
1062 Signed-off-by: A U Thor <author@example.com>
1063 EOF
1064 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
1065 EOF
1066 test_cmp expected actual
1067'
1068
1069test_expect_success 'with command but no key' '
1070 git config --unset trailer.sign.key &&
1071 cat >expected <<-EOF &&
1072
1073 sign: A U Thor <author@example.com>
1074 EOF
1075 git interpret-trailers >actual <<-EOF &&
1076 EOF
1077 test_cmp expected actual
1078'
1079
1080test_expect_success 'with no command and no key' '
1081 git config --unset trailer.review.key &&
1082 cat >expected <<-EOF &&
1083
1084 review: Junio
1085 sign: A U Thor <author@example.com>
1086 EOF
1087 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
1088 EOF
1089 test_cmp expected actual
1090'
1091
1092test_done