]>
Commit | Line | Data |
---|---|---|
76bed78a CC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2013, 2014 Christian Couder | |
4 | # | |
5 | ||
6 | test_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 | ||
13 | test_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 | ||
c364b7ef ZH |
54 | test_expect_success 'with cmd' ' |
55 | test_when_finished "git config --remove-section trailer.bug" && | |
56 | git config trailer.bug.key "Bug-maker: " && | |
57 | git config trailer.bug.ifExists "add" && | |
58 | git config trailer.bug.cmd "echo \"maybe is\"" && | |
59 | cat >expected2 <<-EOF && | |
60 | ||
61 | Bug-maker: maybe is him | |
62 | Bug-maker: maybe is me | |
63 | EOF | |
64 | git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ | |
65 | >actual2 && | |
66 | test_cmp expected2 actual2 | |
67 | ' | |
68 | ||
69 | test_expect_success 'with cmd and $1' ' | |
70 | test_when_finished "git config --remove-section trailer.bug" && | |
71 | git config trailer.bug.key "Bug-maker: " && | |
72 | git config trailer.bug.ifExists "add" && | |
73 | git config trailer.bug.cmd "echo \"\$1\" is" && | |
74 | cat >expected2 <<-EOF && | |
75 | ||
76 | Bug-maker: him is him | |
77 | Bug-maker: me is me | |
78 | EOF | |
79 | git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ | |
80 | >actual2 && | |
81 | test_cmp expected2 actual2 | |
82 | ' | |
83 | ||
84 | test_expect_success 'with cmd and $1 with sh -c' ' | |
85 | test_when_finished "git config --remove-section trailer.bug" && | |
86 | git config trailer.bug.key "Bug-maker: " && | |
87 | git config trailer.bug.ifExists "replace" && | |
88 | git config trailer.bug.cmd "sh -c \"echo who is \"\$1\"\"" && | |
89 | cat >expected2 <<-EOF && | |
90 | ||
91 | Bug-maker: who is me | |
92 | EOF | |
93 | git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ | |
94 | >actual2 && | |
95 | test_cmp expected2 actual2 | |
96 | ' | |
97 | ||
98 | test_expect_success 'with cmd and $1 with shell script' ' | |
99 | test_when_finished "git config --remove-section trailer.bug" && | |
100 | git config trailer.bug.key "Bug-maker: " && | |
101 | git config trailer.bug.ifExists "replace" && | |
102 | git config trailer.bug.cmd "./echoscript" && | |
103 | cat >expected2 <<-EOF && | |
104 | ||
105 | Bug-maker: who is me | |
106 | EOF | |
107 | cat >echoscript <<-EOF && | |
108 | #!/bin/sh | |
109 | echo who is "\$1" | |
110 | EOF | |
111 | chmod +x echoscript && | |
112 | git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ | |
113 | >actual2 && | |
114 | test_cmp expected2 actual2 | |
115 | ' | |
116 | ||
76bed78a CC |
117 | test_expect_success 'without config' ' |
118 | sed -e "s/ Z\$/ /" >expected <<-\EOF && | |
119 | ||
120 | ack: Peff | |
121 | Reviewed-by: Z | |
122 | Acked-by: Johan | |
123 | EOF | |
124 | git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \ | |
125 | --trailer "Acked-by: Johan" empty >actual && | |
126 | test_cmp expected actual | |
127 | ' | |
128 | ||
129 | test_expect_success 'without config in another order' ' | |
130 | sed -e "s/ Z\$/ /" >expected <<-\EOF && | |
131 | ||
132 | Acked-by: Johan | |
133 | Reviewed-by: Z | |
134 | ack: Peff | |
135 | EOF | |
136 | git interpret-trailers --trailer "Acked-by: Johan" --trailer "Reviewed-by" \ | |
137 | --trailer "ack = Peff" empty >actual && | |
138 | test_cmp expected actual | |
139 | ' | |
140 | ||
141 | test_expect_success '--trim-empty without config' ' | |
142 | cat >expected <<-\EOF && | |
143 | ||
144 | ack: Peff | |
145 | Acked-by: Johan | |
146 | EOF | |
147 | git interpret-trailers --trim-empty --trailer ack=Peff \ | |
148 | --trailer "Reviewed-by" --trailer "Acked-by: Johan" \ | |
149 | --trailer "sob:" empty >actual && | |
150 | test_cmp expected actual | |
151 | ' | |
152 | ||
153 | test_expect_success 'with config option on the command line' ' | |
154 | cat >expected <<-\EOF && | |
155 | ||
156 | Acked-by: Johan | |
157 | Reviewed-by: Peff | |
158 | EOF | |
7abcbcb7 | 159 | { echo && echo "Acked-by: Johan"; } | |
76bed78a CC |
160 | git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \ |
161 | --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual && | |
162 | test_cmp expected actual | |
163 | ' | |
164 | ||
6262fe9c | 165 | test_expect_success 'with only a title in the message' ' |
dc5d553b CC |
166 | cat >expected <<-\EOF && |
167 | area: change | |
168 | ||
169 | Reviewed-by: Peff | |
170 | Acked-by: Johan | |
171 | EOF | |
172 | echo "area: change" | | |
173 | git interpret-trailers --trailer "Reviewed-by: Peff" \ | |
174 | --trailer "Acked-by: Johan" >actual && | |
175 | test_cmp expected actual | |
176 | ' | |
177 | ||
5c99995d CC |
178 | test_expect_success 'with multiline title in the message' ' |
179 | cat >expected <<-\EOF && | |
180 | place of | |
181 | code: change | |
182 | ||
183 | Reviewed-by: Peff | |
184 | Acked-by: Johan | |
185 | EOF | |
186 | printf "%s\n" "place of" "code: change" | | |
187 | git interpret-trailers --trailer "Reviewed-by: Peff" \ | |
188 | --trailer "Acked-by: Johan" >actual && | |
189 | test_cmp expected actual | |
190 | ' | |
191 | ||
14624506 JT |
192 | test_expect_success 'with non-trailer lines mixed with Signed-off-by' ' |
193 | cat >patch <<-\EOF && | |
194 | ||
195 | this is not a trailer | |
196 | this is not a trailer | |
197 | Signed-off-by: a <a@example.com> | |
198 | this is not a trailer | |
199 | EOF | |
200 | cat >expected <<-\EOF && | |
201 | ||
202 | this is not a trailer | |
203 | this is not a trailer | |
204 | Signed-off-by: a <a@example.com> | |
205 | this is not a trailer | |
206 | token: value | |
207 | EOF | |
208 | git interpret-trailers --trailer "token: value" patch >actual && | |
209 | test_cmp expected actual | |
210 | ' | |
211 | ||
212 | test_expect_success 'with non-trailer lines mixed with cherry picked from' ' | |
213 | cat >patch <<-\EOF && | |
214 | ||
215 | this is not a trailer | |
216 | this is not a trailer | |
217 | (cherry picked from commit x) | |
218 | this is not a trailer | |
219 | EOF | |
220 | cat >expected <<-\EOF && | |
221 | ||
222 | this is not a trailer | |
223 | this is not a trailer | |
224 | (cherry picked from commit x) | |
225 | this is not a trailer | |
226 | token: value | |
227 | EOF | |
228 | git interpret-trailers --trailer "token: value" patch >actual && | |
229 | test_cmp expected actual | |
230 | ' | |
231 | ||
232 | test_expect_success 'with non-trailer lines mixed with a configured trailer' ' | |
233 | cat >patch <<-\EOF && | |
234 | ||
235 | this is not a trailer | |
236 | this is not a trailer | |
237 | My-trailer: x | |
238 | this is not a trailer | |
239 | EOF | |
240 | cat >expected <<-\EOF && | |
241 | ||
242 | this is not a trailer | |
243 | this is not a trailer | |
244 | My-trailer: x | |
245 | this is not a trailer | |
246 | token: value | |
247 | EOF | |
248 | test_config trailer.my.key "My-trailer: " && | |
249 | git interpret-trailers --trailer "token: value" patch >actual && | |
250 | test_cmp expected actual | |
251 | ' | |
252 | ||
253 | test_expect_success 'with non-trailer lines mixed with a non-configured trailer' ' | |
254 | cat >patch <<-\EOF && | |
255 | ||
256 | this is not a trailer | |
257 | this is not a trailer | |
258 | I-am-not-configured: x | |
259 | this is not a trailer | |
260 | EOF | |
261 | cat >expected <<-\EOF && | |
262 | ||
263 | this is not a trailer | |
264 | this is not a trailer | |
265 | I-am-not-configured: x | |
266 | this is not a trailer | |
267 | ||
268 | token: value | |
269 | EOF | |
270 | test_config trailer.my.key "My-trailer: " && | |
271 | git interpret-trailers --trailer "token: value" patch >actual && | |
272 | test_cmp expected actual | |
273 | ' | |
274 | ||
275 | test_expect_success 'with all non-configured trailers' ' | |
276 | cat >patch <<-\EOF && | |
277 | ||
278 | I-am-not-configured: x | |
279 | I-am-also-not-configured: x | |
280 | EOF | |
281 | cat >expected <<-\EOF && | |
282 | ||
283 | I-am-not-configured: x | |
284 | I-am-also-not-configured: x | |
285 | token: value | |
286 | EOF | |
287 | test_config trailer.my.key "My-trailer: " && | |
288 | git interpret-trailers --trailer "token: value" patch >actual && | |
289 | test_cmp expected actual | |
290 | ' | |
291 | ||
292 | test_expect_success 'with non-trailer lines only' ' | |
293 | cat >patch <<-\EOF && | |
294 | ||
295 | this is not a trailer | |
296 | EOF | |
297 | cat >expected <<-\EOF && | |
298 | ||
299 | this is not a trailer | |
300 | ||
301 | token: value | |
302 | EOF | |
303 | git interpret-trailers --trailer "token: value" patch >actual && | |
304 | test_cmp expected actual | |
305 | ' | |
306 | ||
c463a6b2 JT |
307 | test_expect_success 'line with leading whitespace is not trailer' ' |
308 | q_to_tab >patch <<-\EOF && | |
309 | ||
310 | Qtoken: value | |
311 | EOF | |
312 | q_to_tab >expected <<-\EOF && | |
313 | ||
314 | Qtoken: value | |
315 | ||
316 | token: value | |
317 | EOF | |
318 | git interpret-trailers --trailer "token: value" patch >actual && | |
319 | test_cmp expected actual | |
320 | ' | |
321 | ||
60ef86a1 JT |
322 | test_expect_success 'multiline field treated as one trailer for 25% check' ' |
323 | q_to_tab >patch <<-\EOF && | |
324 | ||
325 | Signed-off-by: a <a@example.com> | |
326 | name: value on | |
327 | Qmultiple lines | |
328 | this is not a trailer | |
329 | this is not a trailer | |
330 | this is not a trailer | |
331 | this is not a trailer | |
332 | this is not a trailer | |
333 | this is not a trailer | |
334 | EOF | |
335 | q_to_tab >expected <<-\EOF && | |
336 | ||
337 | Signed-off-by: a <a@example.com> | |
338 | name: value on | |
339 | Qmultiple lines | |
340 | this is not a trailer | |
341 | this is not a trailer | |
342 | this is not a trailer | |
343 | this is not a trailer | |
344 | this is not a trailer | |
345 | this is not a trailer | |
346 | name: value | |
347 | EOF | |
348 | git interpret-trailers --trailer "name: value" patch >actual && | |
349 | test_cmp expected actual | |
350 | ' | |
351 | ||
352 | test_expect_success 'multiline field treated as atomic for placement' ' | |
353 | q_to_tab >patch <<-\EOF && | |
354 | ||
355 | another: trailer | |
356 | name: value on | |
357 | Qmultiple lines | |
358 | another: trailer | |
359 | EOF | |
360 | q_to_tab >expected <<-\EOF && | |
361 | ||
362 | another: trailer | |
363 | name: value on | |
364 | Qmultiple lines | |
365 | name: value | |
366 | another: trailer | |
367 | EOF | |
368 | test_config trailer.name.where after && | |
369 | git interpret-trailers --trailer "name: value" patch >actual && | |
370 | test_cmp expected actual | |
371 | ' | |
372 | ||
373 | test_expect_success 'multiline field treated as atomic for replacement' ' | |
374 | q_to_tab >patch <<-\EOF && | |
375 | ||
376 | another: trailer | |
377 | name: value on | |
378 | Qmultiple lines | |
379 | another: trailer | |
380 | EOF | |
381 | q_to_tab >expected <<-\EOF && | |
382 | ||
383 | another: trailer | |
384 | another: trailer | |
385 | name: value | |
386 | EOF | |
387 | test_config trailer.name.ifexists replace && | |
388 | git interpret-trailers --trailer "name: value" patch >actual && | |
389 | test_cmp expected actual | |
390 | ' | |
391 | ||
392 | test_expect_success 'multiline field treated as atomic for difference check' ' | |
393 | q_to_tab >patch <<-\EOF && | |
394 | ||
395 | another: trailer | |
396 | name: first line | |
397 | Qsecond line | |
398 | another: trailer | |
399 | EOF | |
400 | test_config trailer.name.ifexists addIfDifferent && | |
401 | ||
402 | q_to_tab >trailer <<-\EOF && | |
403 | name: first line | |
404 | Qsecond line | |
405 | EOF | |
406 | q_to_tab >expected <<-\EOF && | |
407 | ||
408 | another: trailer | |
409 | name: first line | |
410 | Qsecond line | |
411 | another: trailer | |
412 | EOF | |
413 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
414 | test_cmp expected actual && | |
415 | ||
416 | q_to_tab >trailer <<-\EOF && | |
417 | name: first line | |
418 | QQQQQsecond line | |
419 | EOF | |
420 | q_to_tab >expected <<-\EOF && | |
421 | ||
422 | another: trailer | |
423 | name: first line | |
424 | Qsecond line | |
425 | another: trailer | |
426 | name: first line | |
427 | QQQQQsecond line | |
428 | EOF | |
429 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
430 | test_cmp expected actual && | |
431 | ||
432 | q_to_tab >trailer <<-\EOF && | |
433 | name: first line *DIFFERENT* | |
434 | Qsecond line | |
435 | EOF | |
436 | q_to_tab >expected <<-\EOF && | |
437 | ||
438 | another: trailer | |
439 | name: first line | |
440 | Qsecond line | |
441 | another: trailer | |
442 | name: first line *DIFFERENT* | |
443 | Qsecond line | |
444 | EOF | |
445 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
446 | test_cmp expected actual | |
447 | ' | |
448 | ||
449 | test_expect_success 'multiline field treated as atomic for neighbor check' ' | |
450 | q_to_tab >patch <<-\EOF && | |
451 | ||
452 | another: trailer | |
453 | name: first line | |
454 | Qsecond line | |
455 | another: trailer | |
456 | EOF | |
457 | test_config trailer.name.where after && | |
458 | test_config trailer.name.ifexists addIfDifferentNeighbor && | |
459 | ||
460 | q_to_tab >trailer <<-\EOF && | |
461 | name: first line | |
462 | Qsecond line | |
463 | EOF | |
464 | q_to_tab >expected <<-\EOF && | |
465 | ||
466 | another: trailer | |
467 | name: first line | |
468 | Qsecond line | |
469 | another: trailer | |
470 | EOF | |
471 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
472 | test_cmp expected actual && | |
473 | ||
474 | q_to_tab >trailer <<-\EOF && | |
475 | name: first line | |
476 | QQQQQsecond line | |
477 | EOF | |
478 | q_to_tab >expected <<-\EOF && | |
479 | ||
480 | another: trailer | |
481 | name: first line | |
482 | Qsecond line | |
483 | name: first line | |
484 | QQQQQsecond line | |
485 | another: trailer | |
486 | EOF | |
487 | git interpret-trailers --trailer "$(cat trailer)" patch >actual && | |
488 | test_cmp expected actual | |
489 | ' | |
490 | ||
76bed78a | 491 | test_expect_success 'with config setup' ' |
84e53330 | 492 | test_config trailer.ack.key "Acked-by: " && |
76bed78a CC |
493 | cat >expected <<-\EOF && |
494 | ||
495 | Acked-by: Peff | |
496 | EOF | |
497 | git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual && | |
498 | test_cmp expected actual && | |
499 | git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual && | |
500 | test_cmp expected actual && | |
501 | git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual && | |
502 | test_cmp expected actual | |
503 | ' | |
504 | ||
505 | test_expect_success 'with config setup and ":=" as separators' ' | |
84e53330 LA |
506 | test_config trailer.separators ":=" && |
507 | test_config trailer.ack.key "Acked-by= " && | |
76bed78a CC |
508 | cat >expected <<-\EOF && |
509 | ||
510 | Acked-by= Peff | |
511 | EOF | |
512 | git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual && | |
513 | test_cmp expected actual && | |
514 | git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual && | |
515 | test_cmp expected actual && | |
516 | git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual && | |
517 | test_cmp expected actual | |
518 | ' | |
519 | ||
520 | test_expect_success 'with config setup and "%" as separators' ' | |
84e53330 | 521 | test_config trailer.separators "%" && |
76bed78a CC |
522 | cat >expected <<-\EOF && |
523 | ||
524 | bug% 42 | |
525 | count% 10 | |
526 | bug% 422 | |
527 | EOF | |
528 | git interpret-trailers --trim-empty --trailer "bug = 42" \ | |
529 | --trailer count%10 --trailer "test: stuff" \ | |
530 | --trailer "bug % 422" empty >actual && | |
531 | test_cmp expected actual | |
532 | ' | |
533 | ||
534 | test_expect_success 'with "%" as separators and a message with trailers' ' | |
84e53330 | 535 | test_config trailer.separators "%" && |
76bed78a CC |
536 | cat >special_message <<-\EOF && |
537 | Special Message | |
538 | ||
539 | bug% 42 | |
540 | count% 10 | |
541 | bug% 422 | |
542 | EOF | |
543 | cat >expected <<-\EOF && | |
544 | Special Message | |
545 | ||
546 | bug% 42 | |
547 | count% 10 | |
548 | bug% 422 | |
549 | count% 100 | |
550 | EOF | |
551 | git interpret-trailers --trailer count%100 \ | |
552 | special_message >actual && | |
553 | test_cmp expected actual | |
554 | ' | |
555 | ||
556 | test_expect_success 'with config setup and ":=#" as separators' ' | |
84e53330 LA |
557 | test_config trailer.separators ":=#" && |
558 | test_config trailer.bug.key "Bug #" && | |
76bed78a CC |
559 | cat >expected <<-\EOF && |
560 | ||
561 | Bug #42 | |
562 | EOF | |
563 | git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual && | |
564 | test_cmp expected actual | |
565 | ' | |
566 | ||
567 | test_expect_success 'with commit basic message' ' | |
568 | cat basic_message >expected && | |
569 | echo >>expected && | |
570 | git interpret-trailers <basic_message >actual && | |
571 | test_cmp expected actual | |
572 | ' | |
573 | ||
574 | test_expect_success 'with basic patch' ' | |
575 | cat basic_message >input && | |
576 | cat basic_patch >>input && | |
577 | cat basic_message >expected && | |
578 | echo >>expected && | |
579 | cat basic_patch >>expected && | |
580 | git interpret-trailers <input >actual && | |
581 | test_cmp expected actual | |
582 | ' | |
583 | ||
584 | test_expect_success 'with commit complex message as argument' ' | |
84e53330 LA |
585 | test_config trailer.separators ":=" && |
586 | test_config trailer.ack.key "Acked-by= " && | |
76bed78a CC |
587 | cat complex_message_body complex_message_trailers >complex_message && |
588 | cat complex_message_body >expected && | |
589 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
590 | Fixes: Z | |
591 | Acked-by= Z | |
592 | Reviewed-by: Z | |
593 | Signed-off-by: Z | |
594 | EOF | |
595 | git interpret-trailers complex_message >actual && | |
596 | test_cmp expected actual | |
597 | ' | |
598 | ||
599 | test_expect_success 'with 2 files arguments' ' | |
84e53330 LA |
600 | test_config trailer.separators ":=" && |
601 | test_config trailer.ack.key "Acked-by= " && | |
76bed78a CC |
602 | cat basic_message >>expected && |
603 | echo >>expected && | |
604 | cat basic_patch >>expected && | |
605 | git interpret-trailers complex_message input >actual && | |
606 | test_cmp expected actual | |
607 | ' | |
608 | ||
29c83fc2 JK |
609 | # Cover multiple comment characters with the same test input. |
610 | for char in "#" ";" | |
611 | do | |
612 | case "$char" in | |
613 | "#") | |
614 | # This is the default, so let's explicitly _not_ | |
615 | # set any config to make sure it behaves as we expect. | |
616 | ;; | |
617 | *) | |
618 | config="-c core.commentChar=$char" | |
619 | ;; | |
620 | esac | |
621 | ||
622 | test_expect_success "with message that has comments ($char)" ' | |
623 | cat basic_message >message_with_comments && | |
624 | sed -e "s/ Z\$/ /" \ | |
625 | -e "s/#/$char/g" >>message_with_comments <<-EOF && | |
626 | # comment | |
627 | ||
628 | # other comment | |
629 | Cc: Z | |
630 | # yet another comment | |
631 | Reviewed-by: Johan | |
632 | Reviewed-by: Z | |
633 | # last comment | |
634 | ||
635 | EOF | |
636 | cat basic_patch >>message_with_comments && | |
637 | cat basic_message >expected && | |
638 | sed -e "s/#/$char/g" >>expected <<-\EOF && | |
639 | # comment | |
640 | ||
641 | Reviewed-by: Johan | |
642 | Cc: Peff | |
643 | # last comment | |
644 | ||
645 | EOF | |
646 | cat basic_patch >>expected && | |
647 | git $config interpret-trailers \ | |
648 | --trim-empty --trailer "Cc: Peff" \ | |
649 | message_with_comments >actual && | |
650 | test_cmp expected actual | |
651 | ' | |
652 | done | |
76bed78a | 653 | |
3d24a726 CC |
654 | test_expect_success 'with message that has an old style conflict block' ' |
655 | cat basic_message >message_with_comments && | |
656 | sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF && | |
657 | # comment | |
658 | ||
659 | # other comment | |
660 | Cc: Z | |
661 | # yet another comment | |
662 | Reviewed-by: Johan | |
663 | Reviewed-by: Z | |
664 | # last comment | |
665 | ||
666 | Conflicts: | |
667 | ||
668 | EOF | |
669 | cat basic_message >expected && | |
670 | cat >>expected <<-\EOF && | |
671 | # comment | |
672 | ||
673 | Reviewed-by: Johan | |
674 | Cc: Peff | |
675 | # last comment | |
676 | ||
677 | Conflicts: | |
678 | ||
679 | EOF | |
680 | git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual && | |
681 | test_cmp expected actual | |
682 | ' | |
683 | ||
76bed78a | 684 | test_expect_success 'with commit complex message and trailer args' ' |
84e53330 LA |
685 | test_config trailer.separators ":=#" && |
686 | test_config trailer.ack.key "Acked-by= " && | |
687 | test_config trailer.bug.key "Bug #" && | |
76bed78a CC |
688 | cat complex_message_body >expected && |
689 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
690 | Fixes: Z | |
691 | Acked-by= Z | |
692 | Reviewed-by: Z | |
693 | Signed-off-by: Z | |
694 | Acked-by= Peff | |
695 | Bug #42 | |
696 | EOF | |
697 | git interpret-trailers --trailer "ack: Peff" \ | |
698 | --trailer "bug: 42" <complex_message >actual && | |
699 | test_cmp expected actual | |
700 | ' | |
701 | ||
702 | test_expect_success 'with complex patch, args and --trim-empty' ' | |
84e53330 LA |
703 | test_config trailer.separators ":=#" && |
704 | test_config trailer.ack.key "Acked-by= " && | |
705 | test_config trailer.bug.key "Bug #" && | |
76bed78a CC |
706 | cat complex_message >complex_patch && |
707 | cat basic_patch >>complex_patch && | |
708 | cat complex_message_body >expected && | |
709 | cat >>expected <<-\EOF && | |
710 | Acked-by= Peff | |
711 | Bug #42 | |
712 | EOF | |
713 | cat basic_patch >>expected && | |
714 | git interpret-trailers --trim-empty --trailer "ack: Peff" \ | |
715 | --trailer "bug: 42" <complex_patch >actual && | |
716 | test_cmp expected actual | |
717 | ' | |
718 | ||
e1f89863 TK |
719 | test_expect_success 'in-place editing with basic patch' ' |
720 | cat basic_message >message && | |
721 | cat basic_patch >>message && | |
722 | cat basic_message >expected && | |
723 | echo >>expected && | |
724 | cat basic_patch >>expected && | |
725 | git interpret-trailers --in-place message && | |
726 | test_cmp expected message | |
727 | ' | |
728 | ||
729 | test_expect_success 'in-place editing with additional trailer' ' | |
730 | cat basic_message >message && | |
731 | cat basic_patch >>message && | |
732 | cat basic_message >expected && | |
733 | echo >>expected && | |
734 | cat >>expected <<-\EOF && | |
735 | Reviewed-by: Alice | |
736 | EOF | |
737 | cat basic_patch >>expected && | |
738 | git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message && | |
739 | test_cmp expected message | |
740 | ' | |
741 | ||
742 | test_expect_success 'in-place editing on stdin disallowed' ' | |
743 | test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message | |
744 | ' | |
745 | ||
746 | test_expect_success 'in-place editing on non-existing file' ' | |
747 | test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting && | |
748 | test_path_is_missing nonexisting | |
749 | ' | |
750 | ||
751 | test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" ' | |
752 | cat basic_message >message && | |
753 | chmod -r message && | |
754 | test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message && | |
755 | chmod +r message && | |
756 | test_cmp message basic_message | |
757 | ' | |
758 | ||
76bed78a | 759 | test_expect_success 'using "where = before"' ' |
84e53330 LA |
760 | test_config trailer.separators ":=#" && |
761 | test_config trailer.ack.key "Acked-by= " && | |
762 | test_config trailer.bug.key "Bug #" && | |
763 | test_config trailer.bug.where "before" && | |
76bed78a CC |
764 | cat complex_message_body >expected && |
765 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
766 | Bug #42 | |
767 | Fixes: Z | |
768 | Acked-by= Z | |
769 | Reviewed-by: Z | |
770 | Signed-off-by: Z | |
771 | Acked-by= Peff | |
772 | EOF | |
773 | git interpret-trailers --trailer "ack: Peff" \ | |
774 | --trailer "bug: 42" complex_message >actual && | |
775 | test_cmp expected actual | |
776 | ' | |
777 | ||
0ea5292e | 778 | test_expect_success 'overriding configuration with "--where after"' ' |
84e53330 LA |
779 | test_config trailer.separators ":=" && |
780 | test_config trailer.ack.key "Acked-by= " && | |
781 | test_config trailer.ack.where "before" && | |
0ea5292e PB |
782 | cat complex_message_body >expected && |
783 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
784 | Fixes: Z | |
785 | Acked-by= Z | |
786 | Acked-by= Peff | |
787 | Reviewed-by: Z | |
788 | Signed-off-by: Z | |
789 | EOF | |
790 | git interpret-trailers --where after --trailer "ack: Peff" \ | |
791 | complex_message >actual && | |
792 | test_cmp expected actual | |
793 | ' | |
794 | ||
e670ba25 | 795 | test_expect_success 'using "--where after" with "--no-where"' ' |
84e53330 LA |
796 | test_config trailer.ack.key "Acked-by= " && |
797 | test_config trailer.ack.where "before" && | |
798 | test_config trailer.bug.key "Bug #" && | |
799 | test_config trailer.bug.where "before" && | |
800 | test_config trailer.separators ":=#" && | |
0ea5292e PB |
801 | cat complex_message_body >expected && |
802 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
803 | Bug #42 | |
804 | Fixes: Z | |
805 | Acked-by= Peff | |
806 | Acked-by= Z | |
807 | Reviewed-by: Z | |
808 | Signed-off-by: Z | |
809 | EOF | |
810 | git interpret-trailers --where after --no-where --trailer "ack: Peff" \ | |
811 | --trailer "bug: 42" complex_message >actual && | |
812 | test_cmp expected actual | |
813 | ' | |
814 | ||
73574f21 LA |
815 | # Check whether using "--no-where" clears out only the "--where after", such |
816 | # that we still use the configuration in trailer.where (which is different from | |
817 | # the hardcoded default (in WHERE_END) assuming the absence of .gitconfig). | |
818 | # Here, the "start" setting of trailer.where is respected, so the new "Acked-by" | |
819 | # and "Bug" trailers are placed at the beginning, and not at the end which is | |
820 | # the harcoded default. | |
821 | test_expect_success 'using "--where after" with "--no-where" defaults to configuration' ' | |
822 | test_config trailer.ack.key "Acked-by= " && | |
823 | test_config trailer.bug.key "Bug #" && | |
824 | test_config trailer.separators ":=#" && | |
825 | test_config trailer.where "start" && | |
826 | cat complex_message_body >expected && | |
827 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
828 | Bug #42 | |
829 | Acked-by= Peff | |
830 | Fixes: Z | |
831 | Acked-by= Z | |
832 | Reviewed-by: Z | |
833 | Signed-off-by: Z | |
834 | EOF | |
835 | git interpret-trailers --where after --no-where --trailer "ack: Peff" \ | |
836 | --trailer "bug: 42" complex_message >actual && | |
837 | test_cmp expected actual | |
838 | ' | |
839 | ||
840 | # The "--where after" will only get respected for the trailer that came | |
841 | # immediately after it. For the next trailer (Bug #42), we default to using the | |
842 | # hardcoded WHERE_END because we don't have any "trailer.where" or | |
843 | # "trailer.bug.where" configured. | |
844 | test_expect_success 'using "--no-where" defaults to harcoded default if nothing configured' ' | |
845 | test_config trailer.ack.key "Acked-by= " && | |
846 | test_config trailer.bug.key "Bug #" && | |
847 | test_config trailer.separators ":=#" && | |
848 | cat complex_message_body >expected && | |
849 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
850 | Fixes: Z | |
851 | Acked-by= Z | |
852 | Acked-by= Peff | |
853 | Reviewed-by: Z | |
854 | Signed-off-by: Z | |
855 | Bug #42 | |
856 | EOF | |
857 | git interpret-trailers --where after --trailer "ack: Peff" --no-where \ | |
858 | --trailer "bug: 42" complex_message >actual && | |
859 | test_cmp expected actual | |
860 | ' | |
861 | ||
76bed78a | 862 | test_expect_success 'using "where = after"' ' |
84e53330 LA |
863 | test_config trailer.ack.key "Acked-by= " && |
864 | test_config trailer.ack.where "after" && | |
865 | test_config trailer.bug.key "Bug #" && | |
866 | test_config trailer.bug.where "before" && | |
867 | test_config trailer.separators ":=#" && | |
76bed78a CC |
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= Peff | |
874 | Reviewed-by: Z | |
875 | Signed-off-by: Z | |
876 | EOF | |
877 | git interpret-trailers --trailer "ack: Peff" \ | |
878 | --trailer "bug: 42" complex_message >actual && | |
879 | test_cmp expected actual | |
880 | ' | |
881 | ||
882 | test_expect_success 'using "where = end"' ' | |
84e53330 LA |
883 | test_config trailer.review.key "Reviewed-by" && |
884 | test_config trailer.review.where "end" && | |
885 | test_config trailer.ack.key "Acked-by= " && | |
886 | test_config trailer.ack.where "after" && | |
887 | test_config trailer.separators ":=" && | |
76bed78a CC |
888 | cat complex_message_body >expected && |
889 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
890 | Fixes: Z | |
891 | Acked-by= Z | |
892 | Acked-by= Peff | |
893 | Reviewed-by: Z | |
894 | Signed-off-by: Z | |
895 | Reviewed-by: Junio | |
896 | Reviewed-by: Johannes | |
897 | EOF | |
898 | git interpret-trailers --trailer "ack: Peff" \ | |
899 | --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \ | |
900 | complex_message >actual && | |
901 | test_cmp expected actual | |
902 | ' | |
903 | ||
904 | test_expect_success 'using "where = start"' ' | |
84e53330 LA |
905 | test_config trailer.review.key "Reviewed-by" && |
906 | test_config trailer.review.where "start" && | |
907 | test_config trailer.ack.key "Acked-by= " && | |
908 | test_config trailer.ack.where "after" && | |
909 | test_config trailer.separators ":=" && | |
76bed78a CC |
910 | cat complex_message_body >expected && |
911 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
912 | Reviewed-by: Johannes | |
913 | Reviewed-by: Junio | |
914 | Fixes: Z | |
915 | Acked-by= Z | |
916 | Acked-by= Peff | |
917 | Reviewed-by: Z | |
918 | Signed-off-by: Z | |
919 | EOF | |
920 | git interpret-trailers --trailer "ack: Peff" \ | |
921 | --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \ | |
922 | complex_message >actual && | |
923 | test_cmp expected actual | |
924 | ' | |
925 | ||
926 | test_expect_success 'using "where = before" for a token in the middle of the message' ' | |
84e53330 LA |
927 | test_config trailer.review.key "Reviewed-by:" && |
928 | test_config trailer.review.where "before" && | |
929 | test_config trailer.ack.key "Acked-by= " && | |
930 | test_config trailer.ack.where "after" && | |
931 | test_config trailer.bug.key "Bug #" && | |
932 | test_config trailer.bug.where "before" && | |
933 | test_config trailer.separators ":=#" && | |
76bed78a CC |
934 | cat complex_message_body >expected && |
935 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
936 | Bug #42 | |
937 | Fixes: Z | |
938 | Acked-by= Z | |
939 | Acked-by= Peff | |
940 | Reviewed-by:Johan | |
941 | Reviewed-by: | |
942 | Signed-off-by: Z | |
943 | EOF | |
944 | git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \ | |
945 | --trailer "review: Johan" <complex_message >actual && | |
946 | test_cmp expected actual | |
947 | ' | |
948 | ||
949 | test_expect_success 'using "where = before" and --trim-empty' ' | |
84e53330 LA |
950 | test_config trailer.ack.key "Acked-by= " && |
951 | test_config trailer.ack.where "after" && | |
952 | test_config trailer.bug.key "Bug #" && | |
953 | test_config trailer.bug.where "before" && | |
954 | test_config trailer.review.key "Reviewed-by:" && | |
955 | test_config trailer.separators ":=#" && | |
76bed78a CC |
956 | cat complex_message_body >expected && |
957 | cat >>expected <<-\EOF && | |
958 | Bug #46 | |
959 | Bug #42 | |
960 | Acked-by= Peff | |
961 | Reviewed-by:Johan | |
962 | EOF | |
963 | git interpret-trailers --trim-empty --trailer "ack: Peff" \ | |
964 | --trailer "bug: 42" --trailer "review: Johan" \ | |
965 | --trailer "Bug: 46" <complex_message >actual && | |
966 | test_cmp expected actual | |
967 | ' | |
968 | ||
969 | test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' ' | |
84e53330 LA |
970 | test_config trailer.ack.key "Acked-by= " && |
971 | test_config trailer.ack.where "after" && | |
972 | test_config trailer.bug.key "Bug #" && | |
973 | test_config trailer.bug.where "before" && | |
974 | test_config trailer.review.key "Reviewed-by:" && | |
975 | test_config trailer.review.where "before" && | |
976 | test_config trailer.separators ":=#" && | |
76bed78a CC |
977 | cat complex_message_body >expected && |
978 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
979 | Bug #42 | |
980 | Fixes: Z | |
981 | Acked-by= Z | |
982 | Acked-by= Peff | |
983 | Acked-by= Junio | |
984 | Acked-by= Peff | |
985 | Reviewed-by: | |
986 | Signed-off-by: Z | |
987 | EOF | |
988 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
989 | --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \ | |
990 | --trailer "ack: Peff" <complex_message >actual && | |
991 | test_cmp expected actual | |
992 | ' | |
993 | ||
994 | test_expect_success 'default "ifExists" is now "addIfDifferent"' ' | |
84e53330 LA |
995 | test_config trailer.ifexists "addIfDifferent" && |
996 | test_config trailer.ack.key "Acked-by= " && | |
997 | test_config trailer.ack.where "after" && | |
998 | test_config trailer.bug.key "Bug #" && | |
999 | test_config trailer.bug.where "before" && | |
1000 | test_config trailer.review.key "Reviewed-by:" && | |
1001 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1002 | cat complex_message_body >expected && |
1003 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1004 | Bug #42 | |
1005 | Fixes: Z | |
1006 | Acked-by= Z | |
1007 | Acked-by= Peff | |
1008 | Acked-by= Junio | |
1009 | Reviewed-by: | |
1010 | Signed-off-by: Z | |
1011 | EOF | |
1012 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
1013 | --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1014 | --trailer "ack: Peff" <complex_message >actual && | |
1015 | test_cmp expected actual | |
1016 | ' | |
1017 | ||
1018 | test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' ' | |
84e53330 LA |
1019 | test_config trailer.ack.ifExists "addIfDifferent" && |
1020 | test_config trailer.ack.key "Acked-by= " && | |
1021 | test_config trailer.ack.where "end" && | |
1022 | test_config trailer.bug.key "Bug #" && | |
1023 | test_config trailer.bug.where "before" && | |
1024 | test_config trailer.review.key "Reviewed-by:" && | |
1025 | test_config trailer.ifexists "addIfDifferent" && | |
1026 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1027 | cat complex_message_body >expected && |
1028 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1029 | Bug #42 | |
1030 | Fixes: Z | |
1031 | Acked-by= Z | |
1032 | Reviewed-by: | |
1033 | Signed-off-by: Z | |
1034 | Acked-by= Peff | |
1035 | EOF | |
1036 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
1037 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
1038 | <complex_message >actual && | |
1039 | test_cmp expected actual | |
1040 | ' | |
1041 | ||
1042 | test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' ' | |
84e53330 LA |
1043 | test_config trailer.ack.ifExists "addIfDifferent" && |
1044 | test_config trailer.ack.key "Acked-by= " && | |
1045 | test_config trailer.ack.where "before" && | |
1046 | test_config trailer.bug.key "Bug #" && | |
1047 | test_config trailer.bug.where "before" && | |
1048 | test_config trailer.review.key "Reviewed-by:" && | |
1049 | test_config trailer.ifexists "addIfDifferent" && | |
1050 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1051 | cat complex_message_body >expected && |
1052 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1053 | Bug #42 | |
1054 | Fixes: Z | |
1055 | Acked-by= Peff | |
1056 | Acked-by= Z | |
1057 | Reviewed-by: | |
1058 | Signed-off-by: Z | |
1059 | EOF | |
1060 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
1061 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
1062 | <complex_message >actual && | |
1063 | test_cmp expected actual | |
1064 | ' | |
1065 | ||
1066 | test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' ' | |
84e53330 LA |
1067 | test_config trailer.ack.ifExists "addIfDifferentNeighbor" && |
1068 | test_config trailer.ack.key "Acked-by= " && | |
1069 | test_config trailer.ack.where "end" && | |
1070 | test_config trailer.bug.key "Bug #" && | |
1071 | test_config trailer.bug.where "before" && | |
1072 | test_config trailer.review.key "Reviewed-by:" && | |
1073 | test_config trailer.ifexists "addIfDifferent" && | |
1074 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1075 | cat complex_message_body >expected && |
1076 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1077 | Bug #42 | |
1078 | Fixes: Z | |
1079 | Acked-by= Z | |
1080 | Reviewed-by: | |
1081 | Signed-off-by: Z | |
1082 | Acked-by= Peff | |
1083 | Acked-by= Junio | |
1084 | Tested-by: Jakub | |
1085 | Acked-by= Junio | |
1086 | Acked-by= Peff | |
1087 | EOF | |
1088 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
1089 | --trailer "ack: Junio" --trailer "bug: 42" \ | |
1090 | --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ | |
1091 | --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual && | |
1092 | test_cmp expected actual | |
1093 | ' | |
1094 | ||
1095 | test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' ' | |
84e53330 LA |
1096 | test_config trailer.ack.ifExists "addIfDifferentNeighbor" && |
1097 | test_config trailer.ack.key "Acked-by= " && | |
1098 | test_config trailer.ack.where "after" && | |
1099 | test_config trailer.bug.key "Bug #" && | |
1100 | test_config trailer.bug.where "before" && | |
1101 | test_config trailer.review.key "Reviewed-by:" && | |
1102 | test_config trailer.ifexists "addIfDifferent" && | |
1103 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1104 | cat complex_message_body >expected && |
1105 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1106 | Bug #42 | |
1107 | Fixes: Z | |
1108 | Acked-by= Z | |
1109 | Acked-by= Peff | |
1110 | Acked-by= Junio | |
1111 | Acked-by= Peff | |
1112 | Reviewed-by: | |
1113 | Signed-off-by: Z | |
1114 | Tested-by: Jakub | |
1115 | EOF | |
1116 | git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ | |
1117 | --trailer "ack: Junio" --trailer "bug: 42" \ | |
1118 | --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ | |
1119 | --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual && | |
1120 | test_cmp expected actual | |
1121 | ' | |
1122 | ||
1123 | test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' ' | |
84e53330 LA |
1124 | test_config trailer.ack.ifExists "addIfDifferentNeighbor" && |
1125 | test_config trailer.ack.key "Acked-by= " && | |
1126 | test_config trailer.bug.key "Bug #" && | |
1127 | test_config trailer.bug.where "before" && | |
1128 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1129 | cat complex_message_body >expected && |
1130 | cat >>expected <<-\EOF && | |
1131 | Bug #42 | |
1132 | Acked-by= Peff | |
1133 | Acked-by= Junio | |
1134 | Acked-by= Peff | |
1135 | EOF | |
1136 | git interpret-trailers --trim-empty --trailer "ack: Peff" \ | |
1137 | --trailer "Acked-by= Peff" --trailer "review:" \ | |
1138 | --trailer "ack: Junio" --trailer "bug: 42" \ | |
1139 | --trailer "ack: Peff" <complex_message >actual && | |
1140 | test_cmp expected actual | |
1141 | ' | |
1142 | ||
1143 | test_expect_success 'using "ifExists = add" with "where = end"' ' | |
84e53330 LA |
1144 | test_config trailer.ack.ifExists "add" && |
1145 | test_config trailer.ack.key "Acked-by= " && | |
1146 | test_config trailer.ack.where "end" && | |
1147 | test_config trailer.bug.key "Bug #" && | |
1148 | test_config trailer.bug.where "before" && | |
1149 | test_config trailer.review.key "Reviewed-by:" && | |
1150 | test_config trailer.ifexists "addIfDifferent" && | |
1151 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1152 | cat complex_message_body >expected && |
1153 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1154 | Bug #42 | |
1155 | Fixes: Z | |
1156 | Acked-by= Z | |
1157 | Reviewed-by: | |
1158 | Signed-off-by: Z | |
1159 | Acked-by= Peff | |
1160 | Acked-by= Peff | |
1161 | Tested-by: Jakub | |
1162 | Acked-by= Junio | |
1163 | Tested-by: Johannes | |
1164 | Acked-by= Peff | |
1165 | EOF | |
1166 | git interpret-trailers --trailer "ack: Peff" \ | |
1167 | --trailer "Acked-by= Peff" --trailer "review:" \ | |
1168 | --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ | |
1169 | --trailer "bug: 42" --trailer "Tested-by: Johannes" \ | |
1170 | --trailer "ack: Peff" <complex_message >actual && | |
1171 | test_cmp expected actual | |
1172 | ' | |
1173 | ||
1174 | test_expect_success 'using "ifExists = add" with "where = after"' ' | |
84e53330 LA |
1175 | test_config trailer.ack.ifExists "add" && |
1176 | test_config trailer.ack.key "Acked-by= " && | |
1177 | test_config trailer.ack.where "after" && | |
1178 | test_config trailer.bug.key "Bug #" && | |
1179 | test_config trailer.bug.where "before" && | |
1180 | test_config trailer.review.key "Reviewed-by:" && | |
1181 | test_config trailer.ifexists "addIfDifferent" && | |
1182 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1183 | cat complex_message_body >expected && |
1184 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1185 | Bug #42 | |
1186 | Fixes: Z | |
1187 | Acked-by= Z | |
1188 | Acked-by= Peff | |
1189 | Acked-by= Peff | |
1190 | Acked-by= Junio | |
1191 | Acked-by= Peff | |
1192 | Reviewed-by: | |
1193 | Signed-off-by: Z | |
1194 | EOF | |
1195 | git interpret-trailers --trailer "ack: Peff" \ | |
1196 | --trailer "Acked-by= Peff" --trailer "review:" \ | |
1197 | --trailer "ack: Junio" --trailer "bug: 42" \ | |
1198 | --trailer "ack: Peff" <complex_message >actual && | |
1199 | test_cmp expected actual | |
1200 | ' | |
1201 | ||
0ea5292e | 1202 | test_expect_success 'overriding configuration with "--if-exists replace"' ' |
84e53330 LA |
1203 | test_config trailer.fix.key "Fixes: " && |
1204 | test_config trailer.fix.ifExists "add" && | |
1205 | test_config trailer.ack.key "Acked-by= " && | |
1206 | test_config trailer.ack.where "after" && | |
1207 | test_config trailer.bug.key "Bug #" && | |
1208 | test_config trailer.bug.where "before" && | |
1209 | test_config trailer.review.key "Reviewed-by:" && | |
1210 | test_config trailer.review.where "before" && | |
1211 | test_config trailer.separators ":=#" && | |
0ea5292e PB |
1212 | cat complex_message_body >expected && |
1213 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1214 | Bug #42 | |
1215 | Acked-by= Z | |
1216 | Reviewed-by: | |
1217 | Signed-off-by: Z | |
1218 | Fixes: 22 | |
1219 | EOF | |
1220 | git interpret-trailers --if-exists replace --trailer "review:" \ | |
1221 | --trailer "fix=53" --trailer "fix=22" --trailer "bug: 42" \ | |
1222 | <complex_message >actual && | |
1223 | test_cmp expected actual | |
1224 | ' | |
1225 | ||
73574f21 LA |
1226 | # "trailer.ifexists" is set to "doNothing", so using "--no-if-exists" defaults |
1227 | # to this "doNothing" behavior. So the "Fixes: 53" trailer does not get added. | |
1228 | test_expect_success 'using "--if-exists replace" with "--no-if-exists" defaults to configuration' ' | |
1229 | test_config trailer.ifexists "doNothing" && | |
1230 | cat complex_message_body >expected && | |
1231 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1232 | Fixes: Z | |
1233 | Acked-by: Z | |
1234 | Reviewed-by: Z | |
1235 | Signed-off-by: Z | |
1236 | EOF | |
1237 | git interpret-trailers --if-exists replace --no-if-exists --trailer "Fixes: 53" \ | |
1238 | <complex_message >actual && | |
1239 | test_cmp expected actual | |
1240 | ' | |
1241 | ||
1242 | # No "ifexists" configuration is set, so using "--no-if-exists" makes it default | |
1243 | # to addIfDifferentNeighbor. Because we do have a different neighbor "Fixes: 53" | |
1244 | # (because it got added by overriding with "--if-exists replace" earlier in the | |
1245 | # arguments list), we add "Signed-off-by: addme". | |
1246 | test_expect_success 'using "--no-if-exists" defaults to hardcoded default if nothing configured' ' | |
1247 | cat complex_message_body >expected && | |
1248 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1249 | Acked-by: Z | |
1250 | Reviewed-by: Z | |
1251 | Signed-off-by: Z | |
1252 | Fixes: 53 | |
1253 | Signed-off-by: addme | |
1254 | EOF | |
1255 | git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \ | |
1256 | --trailer "Signed-off-by: addme" <complex_message >actual && | |
1257 | test_cmp expected actual | |
1258 | ' | |
1259 | ||
1260 | # The second "Fixes: 53" trailer is discarded, because the "--no-if-exists" here | |
1261 | # makes us default to addIfDifferentNeighbor, and we already added the "Fixes: | |
1262 | # 53" trailer earlier in the argument list. | |
1263 | test_expect_success 'using "--no-if-exists" defaults to hardcoded default if nothing configured (no addition)' ' | |
1264 | cat complex_message_body >expected && | |
1265 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1266 | Acked-by: Z | |
1267 | Reviewed-by: Z | |
1268 | Signed-off-by: Z | |
1269 | Fixes: 53 | |
1270 | EOF | |
1271 | git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \ | |
1272 | --trailer "Fixes: 53" <complex_message >actual && | |
1273 | test_cmp expected actual | |
1274 | ' | |
1275 | ||
76bed78a | 1276 | test_expect_success 'using "ifExists = replace"' ' |
84e53330 LA |
1277 | test_config trailer.fix.key "Fixes: " && |
1278 | test_config trailer.fix.ifExists "replace" && | |
1279 | test_config trailer.ack.key "Acked-by= " && | |
1280 | test_config trailer.ack.where "after" && | |
1281 | test_config trailer.bug.key "Bug #" && | |
1282 | test_config trailer.bug.where "before" && | |
1283 | test_config trailer.review.key "Reviewed-by:" && | |
1284 | test_config trailer.ifexists "addIfDifferent" && | |
1285 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1286 | cat complex_message_body >expected && |
1287 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1288 | Bug #42 | |
1289 | Acked-by= Z | |
1290 | Acked-by= Junio | |
1291 | Acked-by= Peff | |
1292 | Reviewed-by: | |
1293 | Signed-off-by: Z | |
1294 | Fixes: 22 | |
1295 | EOF | |
1296 | git interpret-trailers --trailer "review:" \ | |
1297 | --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \ | |
1298 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
1299 | <complex_message >actual && | |
1300 | test_cmp expected actual | |
1301 | ' | |
1302 | ||
1303 | test_expect_success 'using "ifExists = replace" with "where = after"' ' | |
84e53330 LA |
1304 | test_config trailer.ack.key "Acked-by= " && |
1305 | test_config trailer.ack.where "after" && | |
1306 | test_config trailer.bug.key "Bug #" && | |
1307 | test_config trailer.bug.where "before" && | |
1308 | test_config trailer.fix.key "Fixes: " && | |
1309 | test_config trailer.fix.ifExists "replace" && | |
1310 | test_config trailer.fix.where "after" && | |
1311 | test_config trailer.review.key "Reviewed-by:" && | |
1312 | test_config trailer.ifexists "addIfDifferent" && | |
1313 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1314 | cat complex_message_body >expected && |
1315 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1316 | Bug #42 | |
1317 | Fixes: 22 | |
1318 | Acked-by= Z | |
1319 | Acked-by= Junio | |
1320 | Acked-by= Peff | |
1321 | Reviewed-by: | |
1322 | Signed-off-by: Z | |
1323 | EOF | |
1324 | git interpret-trailers --trailer "review:" \ | |
1325 | --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \ | |
1326 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
1327 | <complex_message >actual && | |
1328 | test_cmp expected actual | |
1329 | ' | |
1330 | ||
1331 | test_expect_success 'using "ifExists = doNothing"' ' | |
84e53330 LA |
1332 | test_config trailer.fix.ifExists "doNothing" && |
1333 | test_config trailer.ack.key "Acked-by= " && | |
1334 | test_config trailer.ack.where "after" && | |
1335 | test_config trailer.bug.key "Bug #" && | |
1336 | test_config trailer.bug.where "before" && | |
1337 | test_config trailer.fix.key "Fixes: " && | |
1338 | test_config trailer.review.key "Reviewed-by:" && | |
1339 | test_config trailer.ifexists "addIfDifferent" && | |
1340 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1341 | cat complex_message_body >expected && |
1342 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1343 | Bug #42 | |
1344 | Fixes: Z | |
1345 | Acked-by= Z | |
1346 | Acked-by= Junio | |
1347 | Acked-by= Peff | |
1348 | Reviewed-by: | |
1349 | Signed-off-by: Z | |
1350 | EOF | |
1351 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1352 | --trailer "ack: Junio" --trailer "fix=22" \ | |
1353 | --trailer "bug: 42" --trailer "ack: Peff" \ | |
1354 | <complex_message >actual && | |
1355 | test_cmp expected actual | |
1356 | ' | |
1357 | ||
1358 | test_expect_success 'the default is "ifMissing = add"' ' | |
84e53330 LA |
1359 | test_config trailer.ack.key "Acked-by= " && |
1360 | test_config trailer.ack.where "after" && | |
1361 | test_config trailer.bug.key "Bug #" && | |
1362 | test_config trailer.bug.where "before" && | |
1363 | test_config trailer.cc.key "Cc: " && | |
1364 | test_config trailer.cc.where "before" && | |
1365 | test_config trailer.fix.key "Fixes: " && | |
1366 | test_config trailer.fix.ifExists "doNothing" && | |
1367 | test_config trailer.review.key "Reviewed-by:" && | |
1368 | test_config trailer.ifexists "addIfDifferent" && | |
1369 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1370 | cat complex_message_body >expected && |
1371 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1372 | Bug #42 | |
1373 | Cc: Linus | |
1374 | Fixes: Z | |
1375 | Acked-by= Z | |
1376 | Acked-by= Junio | |
1377 | Acked-by= Peff | |
1378 | Reviewed-by: | |
1379 | Signed-off-by: Z | |
1380 | EOF | |
1381 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1382 | --trailer "cc=Linus" --trailer "ack: Junio" \ | |
1383 | --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1384 | <complex_message >actual && | |
1385 | test_cmp expected actual | |
1386 | ' | |
1387 | ||
0ea5292e | 1388 | test_expect_success 'overriding configuration with "--if-missing doNothing"' ' |
84e53330 LA |
1389 | test_config trailer.ack.key "Acked-by= " && |
1390 | test_config trailer.ack.where "after" && | |
1391 | test_config trailer.fix.key "Fixes: " && | |
1392 | test_config trailer.fix.ifExists "doNothing" && | |
1393 | test_config trailer.review.key "Reviewed-by:" && | |
1394 | test_config trailer.ifexists "addIfDifferent" && | |
1395 | test_config trailer.ifmissing "add" && | |
1396 | test_config trailer.separators ":=" && | |
0ea5292e PB |
1397 | cat complex_message_body >expected && |
1398 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1399 | Fixes: Z | |
1400 | Acked-by= Z | |
1401 | Acked-by= Junio | |
1402 | Acked-by= Peff | |
1403 | Reviewed-by: | |
1404 | Signed-off-by: Z | |
1405 | EOF | |
1406 | git interpret-trailers --if-missing doNothing \ | |
1407 | --trailer "review:" --trailer "fix=53" \ | |
1408 | --trailer "cc=Linus" --trailer "ack: Junio" \ | |
1409 | --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1410 | <complex_message >actual && | |
1411 | test_cmp expected actual | |
1412 | ' | |
1413 | ||
76bed78a | 1414 | test_expect_success 'when default "ifMissing" is "doNothing"' ' |
84e53330 LA |
1415 | test_config trailer.ack.key "Acked-by= " && |
1416 | test_config trailer.ack.where "after" && | |
1417 | test_config trailer.fix.ifExists "doNothing" && | |
1418 | test_config trailer.review.key "Reviewed-by:" && | |
1419 | test_config trailer.ifexists "addIfDifferent" && | |
1420 | test_config trailer.ifmissing "doNothing" && | |
1421 | test_config trailer.separators ":=" && | |
76bed78a CC |
1422 | cat complex_message_body >expected && |
1423 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1424 | Fixes: Z | |
1425 | Acked-by= Z | |
1426 | Acked-by= Junio | |
1427 | Acked-by= Peff | |
1428 | Reviewed-by: | |
1429 | Signed-off-by: Z | |
1430 | EOF | |
1431 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1432 | --trailer "cc=Linus" --trailer "ack: Junio" \ | |
1433 | --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1434 | <complex_message >actual && | |
84e53330 | 1435 | test_cmp expected actual |
76bed78a CC |
1436 | ' |
1437 | ||
1438 | test_expect_success 'using "ifMissing = add" with "where = end"' ' | |
84e53330 LA |
1439 | test_config trailer.ack.key "Acked-by= " && |
1440 | test_config trailer.ack.where "after" && | |
1441 | test_config trailer.bug.key "Bug #" && | |
1442 | test_config trailer.bug.where "before" && | |
1443 | test_config trailer.cc.key "Cc: " && | |
1444 | test_config trailer.cc.ifMissing "add" && | |
1445 | test_config trailer.cc.where "end" && | |
1446 | test_config trailer.fix.ifExists "doNothing" && | |
1447 | test_config trailer.review.key "Reviewed-by:" && | |
1448 | test_config trailer.ifexists "addIfDifferent" && | |
1449 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1450 | cat complex_message_body >expected && |
1451 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1452 | Bug #42 | |
1453 | Fixes: Z | |
1454 | Acked-by= Z | |
1455 | Acked-by= Junio | |
1456 | Acked-by= Peff | |
1457 | Reviewed-by: | |
1458 | Signed-off-by: Z | |
1459 | Cc: Linus | |
1460 | EOF | |
1461 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1462 | --trailer "ack: Junio" --trailer "fix=22" \ | |
1463 | --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \ | |
1464 | <complex_message >actual && | |
1465 | test_cmp expected actual | |
1466 | ' | |
1467 | ||
1468 | test_expect_success 'using "ifMissing = add" with "where = before"' ' | |
84e53330 LA |
1469 | test_config trailer.ack.key "Acked-by= " && |
1470 | test_config trailer.ack.where "after" && | |
1471 | test_config trailer.bug.key "Bug #" && | |
1472 | test_config trailer.bug.where "before" && | |
1473 | test_config trailer.cc.key "Cc: " && | |
1474 | test_config trailer.cc.ifMissing "add" && | |
1475 | test_config trailer.cc.where "before" && | |
1476 | test_config trailer.fix.ifExists "doNothing" && | |
1477 | test_config trailer.review.key "Reviewed-by:" && | |
1478 | test_config trailer.ifexists "addIfDifferent" && | |
1479 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1480 | cat complex_message_body >expected && |
1481 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1482 | Cc: Linus | |
1483 | Bug #42 | |
1484 | Fixes: Z | |
1485 | Acked-by= Z | |
1486 | Acked-by= Junio | |
1487 | Acked-by= Peff | |
1488 | Reviewed-by: | |
1489 | Signed-off-by: Z | |
1490 | EOF | |
1491 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1492 | --trailer "ack: Junio" --trailer "fix=22" \ | |
1493 | --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \ | |
1494 | <complex_message >actual && | |
1495 | test_cmp expected actual | |
1496 | ' | |
1497 | ||
1498 | test_expect_success 'using "ifMissing = doNothing"' ' | |
84e53330 LA |
1499 | test_config trailer.ack.key "Acked-by= " && |
1500 | test_config trailer.ack.where "after" && | |
1501 | test_config trailer.bug.key "Bug #" && | |
1502 | test_config trailer.bug.where "before" && | |
1503 | test_config trailer.cc.ifMissing "doNothing" && | |
1504 | test_config trailer.fix.ifExists "doNothing" && | |
1505 | test_config trailer.review.key "Reviewed-by:" && | |
1506 | test_config trailer.ifexists "addIfDifferent" && | |
1507 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1508 | cat complex_message_body >expected && |
1509 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1510 | Bug #42 | |
1511 | Fixes: Z | |
1512 | Acked-by= Z | |
1513 | Acked-by= Junio | |
1514 | Acked-by= Peff | |
1515 | Reviewed-by: | |
1516 | Signed-off-by: Z | |
1517 | EOF | |
1518 | git interpret-trailers --trailer "review:" --trailer "fix=53" \ | |
1519 | --trailer "cc=Linus" --trailer "ack: Junio" \ | |
1520 | --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ | |
1521 | <complex_message >actual && | |
1522 | test_cmp expected actual | |
1523 | ' | |
1524 | ||
73574f21 LA |
1525 | # Ignore the "IgnoredTrailer" because of "--if-missing doNothing", but also |
1526 | # ignore the "StillIgnoredTrailer" because we set "trailer.ifMissing" to | |
1527 | # "doNothing" in configuration. | |
1528 | test_expect_success 'using "--no-if-missing" defaults to configuration' ' | |
1529 | test_config trailer.ifMissing "doNothing" && | |
1530 | cat complex_message_body >expected && | |
1531 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1532 | Fixes: Z | |
1533 | Acked-by: Z | |
1534 | Reviewed-by: Z | |
1535 | Signed-off-by: Z | |
1536 | EOF | |
1537 | git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \ | |
1538 | --trailer "StillIgnoredTrailer: ignoreme" <complex_message >actual && | |
1539 | test_cmp expected actual | |
1540 | ' | |
1541 | ||
1542 | # Add the "AddedTrailer" because the "--no-if-missing" clears the "--if-missing | |
1543 | # doNothing" from earlier in the argument list. | |
1544 | test_expect_success 'using "--no-if-missing" defaults to hardcoded default if nothing configured' ' | |
1545 | cat complex_message_body >expected && | |
1546 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1547 | Fixes: Z | |
1548 | Acked-by: Z | |
1549 | Reviewed-by: Z | |
1550 | Signed-off-by: Z | |
1551 | AddedTrailer: addme | |
1552 | EOF | |
1553 | git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \ | |
1554 | --trailer "AddedTrailer: addme" <complex_message >actual && | |
1555 | test_cmp expected actual | |
1556 | ' | |
1557 | ||
76bed78a CC |
1558 | test_expect_success 'default "where" is now "after"' ' |
1559 | git config trailer.where "after" && | |
84e53330 LA |
1560 | test_config trailer.ack.ifExists "add" && |
1561 | test_config trailer.ack.key "Acked-by= " && | |
1562 | test_config trailer.ack.where "after" && | |
1563 | test_config trailer.bug.key "Bug #" && | |
1564 | test_config trailer.bug.where "before" && | |
1565 | test_config trailer.fix.ifExists "doNothing" && | |
1566 | test_config trailer.review.key "Reviewed-by:" && | |
1567 | test_config trailer.ifexists "addIfDifferent" && | |
1568 | test_config trailer.separators ":=#" && | |
76bed78a CC |
1569 | cat complex_message_body >expected && |
1570 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1571 | Bug #42 | |
1572 | Fixes: Z | |
1573 | Acked-by= Z | |
1574 | Acked-by= Peff | |
1575 | Acked-by= Peff | |
1576 | Acked-by= Junio | |
1577 | Acked-by= Peff | |
1578 | Reviewed-by: | |
1579 | Signed-off-by: Z | |
1580 | Tested-by: Jakub | |
1581 | Tested-by: Johannes | |
1582 | EOF | |
1583 | git interpret-trailers --trailer "ack: Peff" \ | |
1584 | --trailer "Acked-by= Peff" --trailer "review:" \ | |
1585 | --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ | |
1586 | --trailer "bug: 42" --trailer "Tested-by: Johannes" \ | |
1587 | --trailer "ack: Peff" <complex_message >actual && | |
1588 | test_cmp expected actual | |
1589 | ' | |
1590 | ||
b9384ff3 | 1591 | test_expect_success 'with simple command' ' |
84e53330 LA |
1592 | test_config trailer.ack.key "Acked-by= " && |
1593 | test_config trailer.fix.ifExists "doNothing" && | |
1594 | test_config trailer.review.key "Reviewed-by:" && | |
1595 | test_config trailer.sign.command "echo \"A U Thor <author@example.com>\"" && | |
1596 | test_config trailer.sign.key "Signed-off-by: " && | |
1597 | test_config trailer.sign.ifExists "addIfDifferentNeighbor" && | |
1598 | test_config trailer.sign.where "after" && | |
1599 | test_config trailer.ifexists "addIfDifferent" && | |
1600 | test_config trailer.separators ":=" && | |
b9384ff3 CC |
1601 | cat complex_message_body >expected && |
1602 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1603 | Fixes: Z | |
1604 | Acked-by= Z | |
1605 | Reviewed-by: | |
1606 | Signed-off-by: Z | |
1607 | Signed-off-by: A U Thor <author@example.com> | |
1608 | EOF | |
1609 | git interpret-trailers --trailer "review:" --trailer "fix=22" \ | |
1610 | <complex_message >actual && | |
1611 | test_cmp expected actual | |
1612 | ' | |
1613 | ||
4dc8b1c1 | 1614 | test_expect_success 'with command using committer information' ' |
84e53330 LA |
1615 | test_config trailer.ack.key "Acked-by= " && |
1616 | test_config trailer.fix.ifExists "doNothing" && | |
1617 | test_config trailer.review.key "Reviewed-by:" && | |
1618 | test_config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" && | |
1619 | test_config trailer.sign.key "Signed-off-by: " && | |
1620 | test_config trailer.sign.ifExists "addIfDifferent" && | |
1621 | test_config trailer.ifexists "addIfDifferent" && | |
1622 | test_config trailer.separators ":=" && | |
b9384ff3 CC |
1623 | cat complex_message_body >expected && |
1624 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1625 | Fixes: Z | |
1626 | Acked-by= Z | |
1627 | Reviewed-by: | |
1628 | Signed-off-by: Z | |
1629 | Signed-off-by: C O Mitter <committer@example.com> | |
1630 | EOF | |
1631 | git interpret-trailers --trailer "review:" --trailer "fix=22" \ | |
1632 | <complex_message >actual && | |
1633 | test_cmp expected actual | |
1634 | ' | |
1635 | ||
1636 | test_expect_success 'with command using author information' ' | |
84e53330 LA |
1637 | test_config trailer.ack.key "Acked-by= " && |
1638 | test_config trailer.fix.ifExists "doNothing" && | |
1639 | test_config trailer.review.key "Reviewed-by:" && | |
1640 | test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && | |
1641 | test_config trailer.sign.key "Signed-off-by: " && | |
1642 | test_config trailer.sign.ifExists "addIfDifferentNeighbor" && | |
1643 | test_config trailer.sign.where "after" && | |
1644 | test_config trailer.ifexists "addIfDifferent" && | |
1645 | test_config trailer.separators ":=" && | |
b9384ff3 CC |
1646 | cat complex_message_body >expected && |
1647 | sed -e "s/ Z\$/ /" >>expected <<-\EOF && | |
1648 | Fixes: Z | |
1649 | Acked-by= Z | |
1650 | Reviewed-by: | |
1651 | Signed-off-by: Z | |
1652 | Signed-off-by: A U Thor <author@example.com> | |
1653 | EOF | |
1654 | git interpret-trailers --trailer "review:" --trailer "fix=22" \ | |
1655 | <complex_message >actual && | |
1656 | test_cmp expected actual | |
1657 | ' | |
1658 | ||
1659 | test_expect_success 'setup a commit' ' | |
1660 | echo "Content of the first commit." > a.txt && | |
1661 | git add a.txt && | |
1662 | git commit -m "Add file a.txt" | |
1663 | ' | |
1664 | ||
c364b7ef | 1665 | test_expect_success 'cmd takes precedence over command' ' |
84e53330 LA |
1666 | test_config trailer.ack.key "Acked-by= " && |
1667 | test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \ | |
c364b7ef | 1668 | --abbrev-commit --abbrev=14 \$ARG" && |
84e53330 LA |
1669 | test_config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \ |
1670 | --abbrev-commit --abbrev=14 \"\$1\" || true" && | |
1671 | test_config trailer.fix.key "Fixes: " && | |
1672 | test_config trailer.fix.ifExists "replace" && | |
1673 | test_config trailer.fix.where "after" && | |
1674 | test_config trailer.review.key "Reviewed-by:" && | |
1675 | test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && | |
1676 | test_config trailer.sign.key "Signed-off-by: " && | |
1677 | test_config trailer.ifexists "addIfDifferent" && | |
1678 | test_config trailer.separators ":=" && | |
c364b7ef ZH |
1679 | FIXED=$(git log -1 --oneline --format="%h (%aN)" --abbrev-commit --abbrev=14 HEAD) && |
1680 | cat complex_message_body >expected2 && | |
1681 | sed -e "s/ Z\$/ /" >>expected2 <<-EOF && | |
1682 | Fixes: $FIXED | |
1683 | Acked-by= Z | |
1684 | Reviewed-by: | |
1685 | Signed-off-by: Z | |
1686 | Signed-off-by: A U Thor <author@example.com> | |
1687 | EOF | |
1688 | git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ | |
1689 | <complex_message >actual2 && | |
1690 | test_cmp expected2 actual2 | |
1691 | ' | |
1692 | ||
b9384ff3 | 1693 | test_expect_success 'with command using $ARG' ' |
84e53330 LA |
1694 | test_config trailer.ack.key "Acked-by= " && |
1695 | test_config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" && | |
1696 | test_config trailer.fix.key "Fixes: " && | |
1697 | test_config trailer.fix.ifExists "replace" && | |
1698 | test_config trailer.fix.where "after" && | |
1699 | test_config trailer.review.key "Reviewed-by:" && | |
1700 | test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && | |
1701 | test_config trailer.sign.key "Signed-off-by: " && | |
1702 | test_config trailer.ifexists "addIfDifferent" && | |
1703 | test_config trailer.separators ":=" && | |
b9384ff3 CC |
1704 | FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) && |
1705 | cat complex_message_body >expected && | |
1706 | sed -e "s/ Z\$/ /" >>expected <<-EOF && | |
1707 | Fixes: $FIXED | |
1708 | Acked-by= Z | |
1709 | Reviewed-by: | |
1710 | Signed-off-by: Z | |
1711 | Signed-off-by: A U Thor <author@example.com> | |
1712 | EOF | |
1713 | git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ | |
1714 | <complex_message >actual && | |
1715 | test_cmp expected actual | |
1716 | ' | |
1717 | ||
1718 | test_expect_success 'with failing command using $ARG' ' | |
84e53330 LA |
1719 | test_config trailer.ack.key "Acked-by= " && |
1720 | test_config trailer.fix.command "false \$ARG" && | |
1721 | test_config trailer.fix.key "Fixes: " && | |
1722 | test_config trailer.fix.ifExists "replace" && | |
1723 | test_config trailer.fix.where "after" && | |
1724 | test_config trailer.review.key "Reviewed-by:" && | |
1725 | test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && | |
1726 | test_config trailer.sign.key "Signed-off-by: " && | |
1727 | test_config trailer.ifexists "addIfDifferent" && | |
1728 | test_config trailer.separators ":=" && | |
b9384ff3 CC |
1729 | cat complex_message_body >expected && |
1730 | sed -e "s/ Z\$/ /" >>expected <<-EOF && | |
1731 | Fixes: Z | |
1732 | Acked-by= Z | |
1733 | Reviewed-by: | |
1734 | Signed-off-by: Z | |
1735 | Signed-off-by: A U Thor <author@example.com> | |
1736 | EOF | |
1737 | git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ | |
1738 | <complex_message >actual && | |
1739 | test_cmp expected actual | |
1740 | ' | |
1741 | ||
1742 | test_expect_success 'with empty tokens' ' | |
84e53330 LA |
1743 | test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && |
1744 | test_config trailer.sign.key "Signed-off-by: " && | |
1745 | test_config trailer.ifexists "addIfDifferent" && | |
b9384ff3 CC |
1746 | cat >expected <<-EOF && |
1747 | ||
1748 | Signed-off-by: A U Thor <author@example.com> | |
1749 | EOF | |
1750 | git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF && | |
1751 | EOF | |
1752 | test_cmp expected actual | |
1753 | ' | |
1754 | ||
1755 | test_expect_success 'with command but no key' ' | |
84e53330 LA |
1756 | test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && |
1757 | test_config trailer.ifexists "addIfDifferent" && | |
b9384ff3 CC |
1758 | cat >expected <<-EOF && |
1759 | ||
1760 | sign: A U Thor <author@example.com> | |
1761 | EOF | |
1762 | git interpret-trailers >actual <<-EOF && | |
1763 | EOF | |
1764 | test_cmp expected actual | |
1765 | ' | |
1766 | ||
1767 | test_expect_success 'with no command and no key' ' | |
84e53330 LA |
1768 | test_config trailer.review.where "before" && |
1769 | test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && | |
1770 | test_config trailer.ifexists "addIfDifferent" && | |
b9384ff3 CC |
1771 | cat >expected <<-EOF && |
1772 | ||
1773 | review: Junio | |
1774 | sign: A U Thor <author@example.com> | |
1775 | EOF | |
1776 | git interpret-trailers --trailer "review:Junio" >actual <<-EOF && | |
1777 | EOF | |
1778 | test_cmp expected actual | |
1779 | ' | |
1780 | ||
d76650b8 | 1781 | test_expect_success 'with cut line' ' |
84e53330 LA |
1782 | test_config trailer.review.where "before" && |
1783 | test_config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && | |
d76650b8 BM |
1784 | cat >expected <<-\EOF && |
1785 | my subject | |
1786 | ||
1787 | review: Brian | |
1788 | sign: A U Thor <author@example.com> | |
1789 | # ------------------------ >8 ------------------------ | |
1790 | ignore this | |
1791 | EOF | |
1792 | git interpret-trailers --trailer review:Brian >actual <<-\EOF && | |
1793 | my subject | |
1794 | # ------------------------ >8 ------------------------ | |
1795 | ignore this | |
1796 | EOF | |
1797 | test_cmp expected actual | |
1798 | ' | |
1799 | ||
56c493ed | 1800 | test_expect_success 'only trailers' ' |
84e53330 LA |
1801 | test_config trailer.sign.command "echo config-value" && |
1802 | test_config trailer.ifexists "addIfDifferent" && | |
56c493ed JK |
1803 | cat >expected <<-\EOF && |
1804 | existing: existing-value | |
1805 | sign: config-value | |
1806 | added: added-value | |
1807 | EOF | |
1808 | git interpret-trailers \ | |
1809 | --trailer added:added-value \ | |
1810 | --only-trailers >actual <<-\EOF && | |
1811 | my subject | |
1812 | ||
1813 | my body | |
1814 | ||
1815 | existing: existing-value | |
1816 | EOF | |
1817 | test_cmp expected actual | |
1818 | ' | |
1819 | ||
1820 | test_expect_success 'only-trailers omits non-trailer in middle of block' ' | |
84e53330 | 1821 | test_config trailer.sign.command "echo config-value" && |
56c493ed JK |
1822 | cat >expected <<-\EOF && |
1823 | Signed-off-by: nobody <nobody@nowhere> | |
1824 | Signed-off-by: somebody <somebody@somewhere> | |
1825 | sign: config-value | |
1826 | EOF | |
1827 | git interpret-trailers --only-trailers >actual <<-\EOF && | |
1828 | subject | |
1829 | ||
1830 | it is important that the trailers below are signed-off-by | |
1831 | so that they meet the "25% trailers Git knows about" heuristic | |
1832 | ||
1833 | Signed-off-by: nobody <nobody@nowhere> | |
1834 | this is not a trailer | |
1835 | Signed-off-by: somebody <somebody@somewhere> | |
1836 | EOF | |
1837 | test_cmp expected actual | |
1838 | ' | |
1839 | ||
fdbdb64f | 1840 | test_expect_success 'only input' ' |
84e53330 | 1841 | test_config trailer.sign.command "echo config-value" && |
fdbdb64f JK |
1842 | cat >expected <<-\EOF && |
1843 | existing: existing-value | |
1844 | EOF | |
1845 | git interpret-trailers \ | |
1846 | --only-trailers --only-input >actual <<-\EOF && | |
1847 | my subject | |
1848 | ||
1849 | my body | |
1850 | ||
1851 | existing: existing-value | |
1852 | EOF | |
1853 | test_cmp expected actual | |
1854 | ' | |
1855 | ||
00002396 JK |
1856 | test_expect_success 'unfold' ' |
1857 | cat >expected <<-\EOF && | |
1858 | foo: continued across several lines | |
1859 | EOF | |
1860 | # pass through tr to make leading and trailing whitespace more obvious | |
1861 | tr _ " " <<-\EOF | | |
1862 | my subject | |
1863 | ||
1864 | my body | |
1865 | ||
1866 | foo:_ | |
1867 | __continued | |
1868 | ___across | |
1869 | ____several | |
1870 | _____lines | |
1871 | ___ | |
1872 | EOF | |
1873 | git interpret-trailers --only-trailers --only-input --unfold >actual && | |
1874 | test_cmp expected actual | |
1875 | ' | |
1876 | ||
c188668e JK |
1877 | test_expect_success 'handling of --- lines in input' ' |
1878 | echo "real-trailer: just right" >expected && | |
1879 | ||
1880 | git interpret-trailers --parse >actual <<-\EOF && | |
1881 | subject | |
1882 | ||
1883 | body | |
1884 | ||
1885 | not-a-trailer: too soon | |
1886 | ------ this is just a line in the commit message with a bunch of | |
1887 | ------ dashes; it does not have any syntactic meaning. | |
1888 | ||
1889 | real-trailer: just right | |
1890 | --- | |
1891 | below the dashed line may be a patch, etc. | |
1892 | ||
1893 | not-a-trailer: too late | |
1894 | EOF | |
1895 | ||
1896 | test_cmp expected actual | |
1897 | ' | |
1898 | ||
1688c9a4 JK |
1899 | test_expect_success 'suppress --- handling' ' |
1900 | echo "real-trailer: just right" >expected && | |
1901 | ||
1902 | git interpret-trailers --parse --no-divider >actual <<-\EOF && | |
1903 | subject | |
1904 | ||
1905 | This commit message has a "---" in it, but because we tell | |
1906 | interpret-trailers not to respect that, it has no effect. | |
1907 | ||
1908 | not-a-trailer: too soon | |
1909 | --- | |
1910 | ||
1911 | This is still the commit message body. | |
1912 | ||
1913 | real-trailer: just right | |
1914 | EOF | |
1915 | ||
1916 | test_cmp expected actual | |
1917 | ' | |
1918 | ||
bc47139f JK |
1919 | test_expect_success 'suppressing --- does not disable cut-line handling' ' |
1920 | echo "real-trailer: before the cut" >expected && | |
1921 | ||
1922 | git interpret-trailers --parse --no-divider >actual <<-\EOF && | |
1923 | subject | |
1924 | ||
1925 | This input has a cut-line in it; we should stop parsing when we see it | |
1926 | and consider only trailers before that line. | |
1927 | ||
1928 | real-trailer: before the cut | |
1929 | ||
1930 | # ------------------------ >8 ------------------------ | |
1931 | # Nothing below this line counts as part of the commit message. | |
1932 | not-a-trailer: too late | |
1933 | EOF | |
1934 | ||
1935 | test_cmp expected actual | |
1936 | ' | |
1937 | ||
2541cba2 FS |
1938 | test_expect_success 'handling of --- lines in conjunction with cut-lines' ' |
1939 | echo "my-trailer: here" >expected && | |
1940 | ||
1941 | git interpret-trailers --parse >actual <<-\EOF && | |
1942 | subject | |
1943 | ||
1944 | my-trailer: here | |
1945 | --- | |
1946 | # ------------------------ >8 ------------------------ | |
1947 | EOF | |
1948 | ||
1949 | test_cmp expected actual | |
1950 | ' | |
1951 | ||
76bed78a | 1952 | test_done |