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 config setup' '
116 git config trailer.ack.key "Acked-by: " &&
117 cat >expected <<-\EOF &&
118
119 Acked-by: Peff
120 EOF
121 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
122 test_cmp expected actual &&
123 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
124 test_cmp expected actual &&
125 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
126 test_cmp expected actual
127'
128
129test_expect_success 'with config setup and ":=" as separators' '
130 git config trailer.separators ":=" &&
131 git config trailer.ack.key "Acked-by= " &&
132 cat >expected <<-\EOF &&
133
134 Acked-by= Peff
135 EOF
136 git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
137 test_cmp expected actual &&
138 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
139 test_cmp expected actual &&
140 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
141 test_cmp expected actual
142'
143
144test_expect_success 'with config setup and "%" as separators' '
145 git config trailer.separators "%" &&
146 cat >expected <<-\EOF &&
147
148 bug% 42
149 count% 10
150 bug% 422
151 EOF
152 git interpret-trailers --trim-empty --trailer "bug = 42" \
153 --trailer count%10 --trailer "test: stuff" \
154 --trailer "bug % 422" empty >actual &&
155 test_cmp expected actual
156'
157
158test_expect_success 'with "%" as separators and a message with trailers' '
159 cat >special_message <<-\EOF &&
160 Special Message
161
162 bug% 42
163 count% 10
164 bug% 422
165 EOF
166 cat >expected <<-\EOF &&
167 Special Message
168
169 bug% 42
170 count% 10
171 bug% 422
172 count% 100
173 EOF
174 git interpret-trailers --trailer count%100 \
175 special_message >actual &&
176 test_cmp expected actual
177'
178
179test_expect_success 'with config setup and ":=#" as separators' '
180 git config trailer.separators ":=#" &&
181 git config trailer.bug.key "Bug #" &&
182 cat >expected <<-\EOF &&
183
184 Bug #42
185 EOF
186 git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
187 test_cmp expected actual
188'
189
190test_expect_success 'with commit basic message' '
191 cat basic_message >expected &&
192 echo >>expected &&
193 git interpret-trailers <basic_message >actual &&
194 test_cmp expected actual
195'
196
197test_expect_success 'with basic patch' '
198 cat basic_message >input &&
199 cat basic_patch >>input &&
200 cat basic_message >expected &&
201 echo >>expected &&
202 cat basic_patch >>expected &&
203 git interpret-trailers <input >actual &&
204 test_cmp expected actual
205'
206
207test_expect_success 'with commit complex message as argument' '
208 cat complex_message_body complex_message_trailers >complex_message &&
209 cat complex_message_body >expected &&
210 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
211 Fixes: Z
212 Acked-by= Z
213 Reviewed-by: Z
214 Signed-off-by: Z
215 EOF
216 git interpret-trailers complex_message >actual &&
217 test_cmp expected actual
218'
219
220test_expect_success 'with 2 files arguments' '
221 cat basic_message >>expected &&
222 echo >>expected &&
223 cat basic_patch >>expected &&
224 git interpret-trailers complex_message input >actual &&
225 test_cmp expected actual
226'
227
228test_expect_success 'with message that has comments' '
229 cat basic_message >message_with_comments &&
230 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
231 # comment
232
233 # other comment
234 Cc: Z
235 # yet another comment
236 Reviewed-by: Johan
237 Reviewed-by: Z
238 # last comment
239
240 EOF
241 cat basic_patch >>message_with_comments &&
242 cat basic_message >expected &&
243 cat >>expected <<-\EOF &&
244 # comment
245
246 Reviewed-by: Johan
247 Cc: Peff
248 # last comment
249
250 EOF
251 cat basic_patch >>expected &&
252 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
253 test_cmp expected actual
254'
255
256test_expect_success 'with message that has an old style conflict block' '
257 cat basic_message >message_with_comments &&
258 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
259 # comment
260
261 # other comment
262 Cc: Z
263 # yet another comment
264 Reviewed-by: Johan
265 Reviewed-by: Z
266 # last comment
267
268 Conflicts:
269
270 EOF
271 cat basic_message >expected &&
272 cat >>expected <<-\EOF &&
273 # comment
274
275 Reviewed-by: Johan
276 Cc: Peff
277 # last comment
278
279 Conflicts:
280
281 EOF
282 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
283 test_cmp expected actual
284'
285
286test_expect_success 'with commit complex message and trailer args' '
287 cat complex_message_body >expected &&
288 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
289 Fixes: Z
290 Acked-by= Z
291 Reviewed-by: Z
292 Signed-off-by: Z
293 Acked-by= Peff
294 Bug #42
295 EOF
296 git interpret-trailers --trailer "ack: Peff" \
297 --trailer "bug: 42" <complex_message >actual &&
298 test_cmp expected actual
299'
300
301test_expect_success 'with complex patch, args and --trim-empty' '
302 cat complex_message >complex_patch &&
303 cat basic_patch >>complex_patch &&
304 cat complex_message_body >expected &&
305 cat >>expected <<-\EOF &&
306 Acked-by= Peff
307 Bug #42
308 EOF
309 cat basic_patch >>expected &&
310 git interpret-trailers --trim-empty --trailer "ack: Peff" \
311 --trailer "bug: 42" <complex_patch >actual &&
312 test_cmp expected actual
313'
314
315test_expect_success 'using "where = before"' '
316 git config trailer.bug.where "before" &&
317 cat complex_message_body >expected &&
318 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
319 Bug #42
320 Fixes: Z
321 Acked-by= Z
322 Reviewed-by: Z
323 Signed-off-by: Z
324 Acked-by= Peff
325 EOF
326 git interpret-trailers --trailer "ack: Peff" \
327 --trailer "bug: 42" complex_message >actual &&
328 test_cmp expected actual
329'
330
331test_expect_success 'using "where = after"' '
332 git config trailer.ack.where "after" &&
333 cat complex_message_body >expected &&
334 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
335 Bug #42
336 Fixes: Z
337 Acked-by= Z
338 Acked-by= Peff
339 Reviewed-by: Z
340 Signed-off-by: Z
341 EOF
342 git interpret-trailers --trailer "ack: Peff" \
343 --trailer "bug: 42" complex_message >actual &&
344 test_cmp expected actual
345'
346
347test_expect_success 'using "where = end"' '
348 git config trailer.review.key "Reviewed-by" &&
349 git config trailer.review.where "end" &&
350 cat complex_message_body >expected &&
351 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
352 Fixes: Z
353 Acked-by= Z
354 Acked-by= Peff
355 Reviewed-by: Z
356 Signed-off-by: Z
357 Reviewed-by: Junio
358 Reviewed-by: Johannes
359 EOF
360 git interpret-trailers --trailer "ack: Peff" \
361 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
362 complex_message >actual &&
363 test_cmp expected actual
364'
365
366test_expect_success 'using "where = start"' '
367 git config trailer.review.key "Reviewed-by" &&
368 git config trailer.review.where "start" &&
369 cat complex_message_body >expected &&
370 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
371 Reviewed-by: Johannes
372 Reviewed-by: Junio
373 Fixes: Z
374 Acked-by= Z
375 Acked-by= Peff
376 Reviewed-by: Z
377 Signed-off-by: Z
378 EOF
379 git interpret-trailers --trailer "ack: Peff" \
380 --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
381 complex_message >actual &&
382 test_cmp expected actual
383'
384
385test_expect_success 'using "where = before" for a token in the middle of the message' '
386 git config trailer.review.key "Reviewed-by:" &&
387 git config trailer.review.where "before" &&
388 cat complex_message_body >expected &&
389 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
390 Bug #42
391 Fixes: Z
392 Acked-by= Z
393 Acked-by= Peff
394 Reviewed-by:Johan
395 Reviewed-by:
396 Signed-off-by: Z
397 EOF
398 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
399 --trailer "review: Johan" <complex_message >actual &&
400 test_cmp expected actual
401'
402
403test_expect_success 'using "where = before" and --trim-empty' '
404 cat complex_message_body >expected &&
405 cat >>expected <<-\EOF &&
406 Bug #46
407 Bug #42
408 Acked-by= Peff
409 Reviewed-by:Johan
410 EOF
411 git interpret-trailers --trim-empty --trailer "ack: Peff" \
412 --trailer "bug: 42" --trailer "review: Johan" \
413 --trailer "Bug: 46" <complex_message >actual &&
414 test_cmp expected actual
415'
416
417test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
418 cat complex_message_body >expected &&
419 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
420 Bug #42
421 Fixes: Z
422 Acked-by= Z
423 Acked-by= Peff
424 Acked-by= Junio
425 Acked-by= Peff
426 Reviewed-by:
427 Signed-off-by: Z
428 EOF
429 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
430 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
431 --trailer "ack: Peff" <complex_message >actual &&
432 test_cmp expected actual
433'
434
435test_expect_success 'default "ifExists" is now "addIfDifferent"' '
436 git config trailer.ifexists "addIfDifferent" &&
437 cat complex_message_body >expected &&
438 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
439 Bug #42
440 Fixes: Z
441 Acked-by= Z
442 Acked-by= Peff
443 Acked-by= Junio
444 Reviewed-by:
445 Signed-off-by: Z
446 EOF
447 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
448 --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
449 --trailer "ack: Peff" <complex_message >actual &&
450 test_cmp expected actual
451'
452
453test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
454 git config trailer.ack.ifExists "addIfDifferent" &&
455 git config trailer.ack.where "end" &&
456 cat complex_message_body >expected &&
457 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
458 Bug #42
459 Fixes: Z
460 Acked-by= Z
461 Reviewed-by:
462 Signed-off-by: Z
463 Acked-by= Peff
464 EOF
465 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
466 --trailer "bug: 42" --trailer "ack: Peff" \
467 <complex_message >actual &&
468 test_cmp expected actual
469'
470
471test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
472 git config trailer.ack.ifExists "addIfDifferent" &&
473 git config trailer.ack.where "before" &&
474 cat complex_message_body >expected &&
475 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
476 Bug #42
477 Fixes: Z
478 Acked-by= Peff
479 Acked-by= Z
480 Reviewed-by:
481 Signed-off-by: Z
482 EOF
483 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
484 --trailer "bug: 42" --trailer "ack: Peff" \
485 <complex_message >actual &&
486 test_cmp expected actual
487'
488
489test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
490 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
491 git config trailer.ack.where "end" &&
492 cat complex_message_body >expected &&
493 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
494 Bug #42
495 Fixes: Z
496 Acked-by= Z
497 Reviewed-by:
498 Signed-off-by: Z
499 Acked-by= Peff
500 Acked-by= Junio
501 Tested-by: Jakub
502 Acked-by= Junio
503 Acked-by= Peff
504 EOF
505 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
506 --trailer "ack: Junio" --trailer "bug: 42" \
507 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
508 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
509 test_cmp expected actual
510'
511
512test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' '
513 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
514 git config trailer.ack.where "after" &&
515 cat complex_message_body >expected &&
516 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
517 Bug #42
518 Fixes: Z
519 Acked-by= Z
520 Acked-by= Peff
521 Acked-by= Junio
522 Acked-by= Peff
523 Reviewed-by:
524 Signed-off-by: Z
525 Tested-by: Jakub
526 EOF
527 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
528 --trailer "ack: Junio" --trailer "bug: 42" \
529 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
530 --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
531 test_cmp expected actual
532'
533
534test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
535 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
536 cat complex_message_body >expected &&
537 cat >>expected <<-\EOF &&
538 Bug #42
539 Acked-by= Peff
540 Acked-by= Junio
541 Acked-by= Peff
542 EOF
543 git interpret-trailers --trim-empty --trailer "ack: Peff" \
544 --trailer "Acked-by= Peff" --trailer "review:" \
545 --trailer "ack: Junio" --trailer "bug: 42" \
546 --trailer "ack: Peff" <complex_message >actual &&
547 test_cmp expected actual
548'
549
550test_expect_success 'using "ifExists = add" with "where = end"' '
551 git config trailer.ack.ifExists "add" &&
552 git config trailer.ack.where "end" &&
553 cat complex_message_body >expected &&
554 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
555 Bug #42
556 Fixes: Z
557 Acked-by= Z
558 Reviewed-by:
559 Signed-off-by: Z
560 Acked-by= Peff
561 Acked-by= Peff
562 Tested-by: Jakub
563 Acked-by= Junio
564 Tested-by: Johannes
565 Acked-by= Peff
566 EOF
567 git interpret-trailers --trailer "ack: Peff" \
568 --trailer "Acked-by= Peff" --trailer "review:" \
569 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
570 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
571 --trailer "ack: Peff" <complex_message >actual &&
572 test_cmp expected actual
573'
574
575test_expect_success 'using "ifExists = add" with "where = after"' '
576 git config trailer.ack.ifExists "add" &&
577 git config trailer.ack.where "after" &&
578 cat complex_message_body >expected &&
579 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
580 Bug #42
581 Fixes: Z
582 Acked-by= Z
583 Acked-by= Peff
584 Acked-by= Peff
585 Acked-by= Junio
586 Acked-by= Peff
587 Reviewed-by:
588 Signed-off-by: Z
589 EOF
590 git interpret-trailers --trailer "ack: Peff" \
591 --trailer "Acked-by= Peff" --trailer "review:" \
592 --trailer "ack: Junio" --trailer "bug: 42" \
593 --trailer "ack: Peff" <complex_message >actual &&
594 test_cmp expected actual
595'
596
597test_expect_success 'using "ifExists = replace"' '
598 git config trailer.fix.key "Fixes: " &&
599 git config trailer.fix.ifExists "replace" &&
600 cat complex_message_body >expected &&
601 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
602 Bug #42
603 Acked-by= Z
604 Acked-by= Junio
605 Acked-by= Peff
606 Reviewed-by:
607 Signed-off-by: Z
608 Fixes: 22
609 EOF
610 git interpret-trailers --trailer "review:" \
611 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
612 --trailer "bug: 42" --trailer "ack: Peff" \
613 <complex_message >actual &&
614 test_cmp expected actual
615'
616
617test_expect_success 'using "ifExists = replace" with "where = after"' '
618 git config trailer.fix.where "after" &&
619 cat complex_message_body >expected &&
620 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
621 Bug #42
622 Fixes: 22
623 Acked-by= Z
624 Acked-by= Junio
625 Acked-by= Peff
626 Reviewed-by:
627 Signed-off-by: Z
628 EOF
629 git interpret-trailers --trailer "review:" \
630 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
631 --trailer "bug: 42" --trailer "ack: Peff" \
632 <complex_message >actual &&
633 test_cmp expected actual
634'
635
636test_expect_success 'using "ifExists = doNothing"' '
637 git config trailer.fix.ifExists "doNothing" &&
638 cat complex_message_body >expected &&
639 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
640 Bug #42
641 Fixes: Z
642 Acked-by= Z
643 Acked-by= Junio
644 Acked-by= Peff
645 Reviewed-by:
646 Signed-off-by: Z
647 EOF
648 git interpret-trailers --trailer "review:" --trailer "fix=53" \
649 --trailer "ack: Junio" --trailer "fix=22" \
650 --trailer "bug: 42" --trailer "ack: Peff" \
651 <complex_message >actual &&
652 test_cmp expected actual
653'
654
655test_expect_success 'the default is "ifMissing = add"' '
656 git config trailer.cc.key "Cc: " &&
657 git config trailer.cc.where "before" &&
658 cat complex_message_body >expected &&
659 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
660 Bug #42
661 Cc: Linus
662 Fixes: Z
663 Acked-by= Z
664 Acked-by= Junio
665 Acked-by= Peff
666 Reviewed-by:
667 Signed-off-by: Z
668 EOF
669 git interpret-trailers --trailer "review:" --trailer "fix=53" \
670 --trailer "cc=Linus" --trailer "ack: Junio" \
671 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
672 <complex_message >actual &&
673 test_cmp expected actual
674'
675
676test_expect_success 'when default "ifMissing" is "doNothing"' '
677 git config trailer.ifmissing "doNothing" &&
678 cat complex_message_body >expected &&
679 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
680 Fixes: Z
681 Acked-by= Z
682 Acked-by= Junio
683 Acked-by= Peff
684 Reviewed-by:
685 Signed-off-by: Z
686 EOF
687 git interpret-trailers --trailer "review:" --trailer "fix=53" \
688 --trailer "cc=Linus" --trailer "ack: Junio" \
689 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
690 <complex_message >actual &&
691 test_cmp expected actual &&
692 git config trailer.ifmissing "add"
693'
694
695test_expect_success 'using "ifMissing = add" with "where = end"' '
696 git config trailer.cc.key "Cc: " &&
697 git config trailer.cc.where "end" &&
698 git config trailer.cc.ifMissing "add" &&
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= Junio
705 Acked-by= Peff
706 Reviewed-by:
707 Signed-off-by: Z
708 Cc: Linus
709 EOF
710 git interpret-trailers --trailer "review:" --trailer "fix=53" \
711 --trailer "ack: Junio" --trailer "fix=22" \
712 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
713 <complex_message >actual &&
714 test_cmp expected actual
715'
716
717test_expect_success 'using "ifMissing = add" with "where = before"' '
718 git config trailer.cc.key "Cc: " &&
719 git config trailer.cc.where "before" &&
720 git config trailer.cc.ifMissing "add" &&
721 cat complex_message_body >expected &&
722 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
723 Cc: Linus
724 Bug #42
725 Fixes: Z
726 Acked-by= Z
727 Acked-by= Junio
728 Acked-by= Peff
729 Reviewed-by:
730 Signed-off-by: Z
731 EOF
732 git interpret-trailers --trailer "review:" --trailer "fix=53" \
733 --trailer "ack: Junio" --trailer "fix=22" \
734 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
735 <complex_message >actual &&
736 test_cmp expected actual
737'
738
739test_expect_success 'using "ifMissing = doNothing"' '
740 git config trailer.cc.ifMissing "doNothing" &&
741 cat complex_message_body >expected &&
742 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
743 Bug #42
744 Fixes: Z
745 Acked-by= Z
746 Acked-by= Junio
747 Acked-by= Peff
748 Reviewed-by:
749 Signed-off-by: Z
750 EOF
751 git interpret-trailers --trailer "review:" --trailer "fix=53" \
752 --trailer "cc=Linus" --trailer "ack: Junio" \
753 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
754 <complex_message >actual &&
755 test_cmp expected actual
756'
757
758test_expect_success 'default "where" is now "after"' '
759 git config trailer.where "after" &&
760 git config --unset trailer.ack.where &&
761 cat complex_message_body >expected &&
762 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
763 Bug #42
764 Fixes: Z
765 Acked-by= Z
766 Acked-by= Peff
767 Acked-by= Peff
768 Acked-by= Junio
769 Acked-by= Peff
770 Reviewed-by:
771 Signed-off-by: Z
772 Tested-by: Jakub
773 Tested-by: Johannes
774 EOF
775 git interpret-trailers --trailer "ack: Peff" \
776 --trailer "Acked-by= Peff" --trailer "review:" \
777 --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
778 --trailer "bug: 42" --trailer "Tested-by: Johannes" \
779 --trailer "ack: Peff" <complex_message >actual &&
780 test_cmp expected actual
781'
782
783test_expect_success 'with simple command' '
784 git config trailer.sign.key "Signed-off-by: " &&
785 git config trailer.sign.where "after" &&
786 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
787 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
788 cat complex_message_body >expected &&
789 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
790 Fixes: Z
791 Acked-by= Z
792 Reviewed-by:
793 Signed-off-by: Z
794 Signed-off-by: A U Thor <author@example.com>
795 EOF
796 git interpret-trailers --trailer "review:" --trailer "fix=22" \
797 <complex_message >actual &&
798 test_cmp expected actual
799'
800
801test_expect_success 'with command using commiter information' '
802 git config trailer.sign.ifExists "addIfDifferent" &&
803 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
804 cat complex_message_body >expected &&
805 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
806 Fixes: Z
807 Acked-by= Z
808 Reviewed-by:
809 Signed-off-by: Z
810 Signed-off-by: C O Mitter <committer@example.com>
811 EOF
812 git interpret-trailers --trailer "review:" --trailer "fix=22" \
813 <complex_message >actual &&
814 test_cmp expected actual
815'
816
817test_expect_success 'with command using author information' '
818 git config trailer.sign.key "Signed-off-by: " &&
819 git config trailer.sign.where "after" &&
820 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
821 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
822 cat complex_message_body >expected &&
823 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
824 Fixes: Z
825 Acked-by= Z
826 Reviewed-by:
827 Signed-off-by: Z
828 Signed-off-by: A U Thor <author@example.com>
829 EOF
830 git interpret-trailers --trailer "review:" --trailer "fix=22" \
831 <complex_message >actual &&
832 test_cmp expected actual
833'
834
835test_expect_success 'setup a commit' '
836 echo "Content of the first commit." > a.txt &&
837 git add a.txt &&
838 git commit -m "Add file a.txt"
839'
840
841test_expect_success 'with command using $ARG' '
842 git config trailer.fix.ifExists "replace" &&
843 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
844 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
845 cat complex_message_body >expected &&
846 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
847 Fixes: $FIXED
848 Acked-by= Z
849 Reviewed-by:
850 Signed-off-by: Z
851 Signed-off-by: A U Thor <author@example.com>
852 EOF
853 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
854 <complex_message >actual &&
855 test_cmp expected actual
856'
857
858test_expect_success 'with failing command using $ARG' '
859 git config trailer.fix.ifExists "replace" &&
860 git config trailer.fix.command "false \$ARG" &&
861 cat complex_message_body >expected &&
862 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
863 Fixes: Z
864 Acked-by= Z
865 Reviewed-by:
866 Signed-off-by: Z
867 Signed-off-by: A U Thor <author@example.com>
868 EOF
869 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
870 <complex_message >actual &&
871 test_cmp expected actual
872'
873
874test_expect_success 'with empty tokens' '
875 git config --unset trailer.fix.command &&
876 cat >expected <<-EOF &&
877
878 Signed-off-by: A U Thor <author@example.com>
879 EOF
880 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
881 EOF
882 test_cmp expected actual
883'
884
885test_expect_success 'with command but no key' '
886 git config --unset trailer.sign.key &&
887 cat >expected <<-EOF &&
888
889 sign: A U Thor <author@example.com>
890 EOF
891 git interpret-trailers >actual <<-EOF &&
892 EOF
893 test_cmp expected actual
894'
895
896test_expect_success 'with no command and no key' '
897 git config --unset trailer.review.key &&
898 cat >expected <<-EOF &&
899
900 review: Junio
901 sign: A U Thor <author@example.com>
902 EOF
903 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
904 EOF
905 test_cmp expected actual
906'
907
908test_done