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