Merge branch 'cc/interpret-trailers' into jch
[git/jrn.git] / t / t7513-interpret-trailers.sh
blobd1e4970d43f40c5971a2c362ec66c044a3e9dce4
1 #!/bin/sh
3 # Copyright (c) 2013, 2014 Christian Couder
6 test_description='git interpret-trailers'
8 . ./test-lib.sh
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.
13 test_expect_success 'setup' '
14 cat >basic_message <<-\EOF &&
15 subject
17 body
18 EOF
19 cat >complex_message_body <<-\EOF &&
20 my subject
22 my body which is long
23 and contains some special
24 chars like : = ? !
26 EOF
27 sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF &&
28 Fixes: Z
29 Acked-by: Z
30 Reviewed-by: Z
31 Signed-off-by: Z
32 EOF
33 cat >basic_patch <<-\EOF
34 ---
35 foo.txt | 2 +-
36 1 file changed, 1 insertion(+), 1 deletion(-)
38 diff --git a/foo.txt b/foo.txt
39 index 0353767..1d91aa1 100644
40 --- a/foo.txt
41 +++ b/foo.txt
42 @@ -1,3 +1,3 @@
44 -bar
45 +baz
48 1.9.rc0.11.ga562ddc
50 EOF
53 test_expect_success 'without config' '
54 sed -e "s/ Z\$/ /" >expected <<-\EOF &&
56 ack: Peff
57 Reviewed-by: Z
58 Acked-by: Johan
59 EOF
60 git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \
61 --trailer "Acked-by: Johan" >actual &&
62 test_cmp expected actual
65 test_expect_success '--trim-empty without config' '
66 cat >expected <<-\EOF &&
68 ack: Peff
69 Acked-by: Johan
70 EOF
71 git interpret-trailers --trim-empty --trailer "ack = Peff" \
72 --trailer "Reviewed-by" --trailer "Acked-by: Johan" \
73 --trailer "sob:" >actual &&
74 test_cmp expected actual
77 test_expect_success 'with config setup' '
78 git config trailer.ack.key "Acked-by: " &&
79 cat >expected <<-\EOF &&
81 Acked-by: Peff
82 EOF
83 git interpret-trailers --trim-empty --trailer "ack = Peff" >actual &&
84 test_cmp expected actual &&
85 git interpret-trailers --trim-empty --trailer "Acked-by = Peff" >actual &&
86 test_cmp expected actual &&
87 git interpret-trailers --trim-empty --trailer "Acked-by :Peff" >actual &&
88 test_cmp expected actual
91 test_expect_success 'with config setup and = sign' '
92 git config trailer.ack.key "Acked-by= " &&
93 cat >expected <<-\EOF &&
95 Acked-by= Peff
96 EOF
97 git interpret-trailers --trim-empty --trailer "ack = Peff" >actual &&
98 test_cmp expected actual &&
99 git interpret-trailers --trim-empty --trailer "Acked-by= Peff" >actual &&
100 test_cmp expected actual &&
101 git interpret-trailers --trim-empty --trailer "Acked-by : Peff" >actual &&
102 test_cmp expected actual
105 test_expect_success 'with config setup and # sign' '
106 git config trailer.bug.key "Bug #" &&
107 cat >expected <<-\EOF &&
109 Bug #42
111 git interpret-trailers --trim-empty --trailer "bug = 42" >actual &&
112 test_cmp expected actual
115 test_expect_success 'with commit basic message' '
116 cat basic_message >expected &&
117 echo >>expected &&
118 git interpret-trailers <basic_message >actual &&
119 test_cmp expected actual
122 test_expect_success 'with basic patch' '
123 cat basic_message >input &&
124 cat basic_patch >>input &&
125 cat basic_message >expected &&
126 echo >>expected &&
127 cat basic_patch >>expected &&
128 git interpret-trailers <input >actual &&
129 test_cmp expected actual
132 test_expect_success 'with commit complex message as argument' '
133 cat complex_message_body complex_message_trailers >complex_message &&
134 cat complex_message_body >expected &&
135 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
136 Fixes: Z
137 Acked-by= Z
138 Reviewed-by: Z
139 Signed-off-by: Z
141 git interpret-trailers complex_message >actual &&
142 test_cmp expected actual
145 test_expect_success 'with 2 files arguments' '
146 cat basic_message >>expected &&
147 echo >>expected &&
148 cat basic_patch >>expected &&
149 git interpret-trailers complex_message input >actual &&
150 test_cmp expected actual
153 test_expect_success 'with message that has comments' '
154 cat basic_message >>message_with_comments &&
155 sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
156 # comment
158 # other comment
159 Cc: Z
160 # yet another comment
161 Reviewed-by: Johan
162 Reviewed-by: Z
163 # last comment
166 cat basic_patch >>message_with_comments &&
167 cat basic_message >expected &&
168 cat >>expected <<-\EOF &&
169 # comment
171 Cc: Peff
172 Reviewed-by: Johan
174 cat basic_patch >>expected &&
175 git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
176 test_cmp expected actual
179 test_expect_success 'with commit complex message and trailer args' '
180 cat complex_message_body >expected &&
181 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
182 Fixes: Z
183 Acked-by= Z
184 Acked-by= Peff
185 Reviewed-by: Z
186 Signed-off-by: Z
187 Bug #42
189 git interpret-trailers --trailer "ack: Peff" \
190 --trailer "bug: 42" <complex_message >actual &&
191 test_cmp expected actual
194 test_expect_success 'with complex patch, args and --trim-empty' '
195 cat complex_message >complex_patch &&
196 cat basic_patch >>complex_patch &&
197 cat complex_message_body >expected &&
198 cat >>expected <<-\EOF &&
199 Acked-by= Peff
200 Bug #42
202 cat basic_patch >>expected &&
203 git interpret-trailers --trim-empty --trailer "ack: Peff" \
204 --trailer "bug: 42" <complex_patch >actual &&
205 test_cmp expected actual
208 test_expect_success 'using "where = before"' '
209 git config trailer.bug.where "before" &&
210 cat complex_message_body >expected &&
211 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
212 Bug #42
213 Fixes: Z
214 Acked-by= Z
215 Acked-by= Peff
216 Reviewed-by: Z
217 Signed-off-by: Z
219 git interpret-trailers --trailer "ack: Peff" \
220 --trailer "bug: 42" complex_message >actual &&
221 test_cmp expected actual
224 test_expect_success 'using "where = before" for a token in the middle of the message' '
225 git config trailer.review.key "Reviewed-by:" &&
226 git config trailer.review.where "before" &&
227 cat complex_message_body >expected &&
228 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
229 Bug #42
230 Fixes: Z
231 Acked-by= Z
232 Acked-by= Peff
233 Reviewed-by:Johan
234 Reviewed-by:
235 Signed-off-by: Z
237 git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
238 --trailer "review: Johan" <complex_message >actual &&
239 test_cmp expected actual
242 test_expect_success 'using "where = before" and --trim-empty' '
243 cat complex_message_body >expected &&
244 cat >>expected <<-\EOF &&
245 Bug #46
246 Bug #42
247 Acked-by= Peff
248 Reviewed-by:Johan
250 git interpret-trailers --trim-empty --trailer "ack: Peff" \
251 --trailer "bug: 42" --trailer "review: Johan" \
252 --trailer "Bug: 46" <complex_message >actual &&
253 test_cmp expected actual
256 test_expect_success 'the default is "ifExists = addIfDifferent"' '
257 cat complex_message_body >expected &&
258 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
259 Bug #42
260 Fixes: Z
261 Acked-by= Z
262 Acked-by= Peff
263 Reviewed-by:
264 Signed-off-by: Z
266 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
267 --trailer "bug: 42" --trailer "ack: Peff" \
268 <complex_message >actual &&
269 test_cmp expected actual
272 test_expect_success 'using "ifExists = addIfDifferent"' '
273 git config trailer.review.ifExists "addIfDifferent" &&
274 cat complex_message_body >expected &&
275 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
276 Bug #42
277 Fixes: Z
278 Acked-by= Z
279 Acked-by= Peff
280 Reviewed-by:
281 Signed-off-by: Z
283 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
284 --trailer "bug: 42" --trailer "ack: Peff" \
285 <complex_message >actual &&
286 test_cmp expected actual
289 test_expect_success 'using "ifExists = addIfDifferentNeighbor"' '
290 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
291 cat complex_message_body >expected &&
292 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
293 Bug #42
294 Fixes: Z
295 Acked-by= Z
296 Acked-by= Peff
297 Acked-by= Junio
298 Acked-by= Peff
299 Reviewed-by:
300 Signed-off-by: Z
302 git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
303 --trailer "ack: Junio" --trailer "bug: 42" \
304 --trailer "ack: Peff" <complex_message >actual &&
305 test_cmp expected actual
308 test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
309 git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
310 cat complex_message_body >expected &&
311 cat >>expected <<-\EOF &&
312 Bug #42
313 Acked-by= Peff
314 Acked-by= Junio
315 Acked-by= Peff
317 git interpret-trailers --trim-empty --trailer "ack: Peff" \
318 --trailer "Acked-by= Peff" --trailer "review:" \
319 --trailer "ack: Junio" --trailer "bug: 42" \
320 --trailer "ack: Peff" <complex_message >actual &&
321 test_cmp expected actual
324 test_expect_success 'using "ifExists = add"' '
325 git config trailer.ack.ifExists "add" &&
326 cat complex_message_body >expected &&
327 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
328 Bug #42
329 Fixes: Z
330 Acked-by= Z
331 Acked-by= Peff
332 Acked-by= Peff
333 Acked-by= Junio
334 Acked-by= Peff
335 Reviewed-by:
336 Signed-off-by: Z
338 git interpret-trailers --trailer "ack: Peff" \
339 --trailer "Acked-by= Peff" --trailer "review:" \
340 --trailer "ack: Junio" --trailer "bug: 42" \
341 --trailer "ack: Peff" <complex_message >actual &&
342 test_cmp expected actual
345 test_expect_success 'using "ifExists = overwrite"' '
346 git config trailer.fix.key "Fixes: " &&
347 git config trailer.fix.ifExists "overwrite" &&
348 cat complex_message_body >expected &&
349 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
350 Bug #42
351 Fixes: 22
352 Acked-by= Z
353 Acked-by= Junio
354 Acked-by= Peff
355 Reviewed-by:
356 Signed-off-by: Z
358 git interpret-trailers --trailer "review:" \
359 --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
360 --trailer "bug: 42" --trailer "ack: Peff" \
361 <complex_message >actual &&
362 test_cmp expected actual
365 test_expect_success 'using "ifExists = doNothing"' '
366 git config trailer.fix.ifExists "doNothing" &&
367 cat complex_message_body >expected &&
368 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
369 Bug #42
370 Fixes: Z
371 Acked-by= Z
372 Acked-by= Junio
373 Acked-by= Peff
374 Reviewed-by:
375 Signed-off-by: Z
377 git interpret-trailers --trailer "review:" --trailer "fix=53" \
378 --trailer "ack: Junio" --trailer "fix=22" \
379 --trailer "bug: 42" --trailer "ack: Peff" \
380 <complex_message >actual &&
381 test_cmp expected actual
384 test_expect_success 'the default is "ifMissing = add"' '
385 git config trailer.cc.key "Cc: " &&
386 git config trailer.cc.where "before" &&
387 cat complex_message_body >expected &&
388 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
389 Bug #42
390 Cc: Linus
391 Fixes: Z
392 Acked-by= Z
393 Acked-by= Junio
394 Acked-by= Peff
395 Reviewed-by:
396 Signed-off-by: Z
398 git interpret-trailers --trailer "review:" --trailer "fix=53" \
399 --trailer "cc=Linus" --trailer "ack: Junio" \
400 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
401 <complex_message >actual &&
402 test_cmp expected actual
405 test_expect_success 'using "ifMissing = add"' '
406 git config trailer.cc.ifMissing "add" &&
407 cat complex_message_body >expected &&
408 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
409 Cc: Linus
410 Bug #42
411 Fixes: Z
412 Acked-by= Z
413 Acked-by= Junio
414 Acked-by= Peff
415 Reviewed-by:
416 Signed-off-by: Z
418 git interpret-trailers --trailer "review:" --trailer "fix=53" \
419 --trailer "ack: Junio" --trailer "fix=22" \
420 --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
421 <complex_message >actual &&
422 test_cmp expected actual
425 test_expect_success 'using "ifMissing = doNothing"' '
426 git config trailer.cc.ifMissing "doNothing" &&
427 cat complex_message_body >expected &&
428 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
429 Bug #42
430 Fixes: Z
431 Acked-by= Z
432 Acked-by= Junio
433 Acked-by= Peff
434 Reviewed-by:
435 Signed-off-by: Z
437 git interpret-trailers --trailer "review:" --trailer "fix=53" \
438 --trailer "cc=Linus" --trailer "ack: Junio" \
439 --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
440 <complex_message >actual &&
441 test_cmp expected actual
444 test_expect_success 'with simple command' '
445 git config trailer.sign.key "Signed-off-by: " &&
446 git config trailer.sign.where "after" &&
447 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
448 git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
449 cat complex_message_body >expected &&
450 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
451 Fixes: Z
452 Acked-by= Z
453 Reviewed-by:
454 Signed-off-by: Z
455 Signed-off-by: A U Thor <author@example.com>
457 git interpret-trailers --trailer "review:" --trailer "fix=22" \
458 <complex_message >actual &&
459 test_cmp expected actual
462 test_expect_success 'with command using commiter information' '
463 git config trailer.sign.ifExists "addIfDifferent" &&
464 git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
465 cat complex_message_body >expected &&
466 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
467 Fixes: Z
468 Acked-by= Z
469 Reviewed-by:
470 Signed-off-by: Z
471 Signed-off-by: C O Mitter <committer@example.com>
473 git interpret-trailers --trailer "review:" --trailer "fix=22" \
474 <complex_message >actual &&
475 test_cmp expected actual
478 test_expect_success 'with command using author information' '
479 git config trailer.sign.key "Signed-off-by: " &&
480 git config trailer.sign.where "after" &&
481 git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
482 git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
483 cat complex_message_body >expected &&
484 sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
485 Fixes: Z
486 Acked-by= Z
487 Reviewed-by:
488 Signed-off-by: Z
489 Signed-off-by: A U Thor <author@example.com>
491 git interpret-trailers --trailer "review:" --trailer "fix=22" \
492 <complex_message >actual &&
493 test_cmp expected actual
496 test_expect_success 'setup a commit' '
497 echo "Content of the first commit." > a.txt &&
498 git add a.txt &&
499 git commit -m "Add file a.txt"
502 test_expect_success 'with command using $ARG' '
503 git config trailer.fix.ifExists "overwrite" &&
504 git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
505 FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
506 cat complex_message_body >expected &&
507 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
508 Fixes: $FIXED
509 Acked-by= Z
510 Reviewed-by:
511 Signed-off-by: Z
512 Signed-off-by: A U Thor <author@example.com>
514 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
515 <complex_message >actual &&
516 test_cmp expected actual
519 test_expect_success 'with failing command using $ARG' '
520 git config trailer.fix.ifExists "overwrite" &&
521 git config trailer.fix.command "false \$ARG" &&
522 cat complex_message_body >expected &&
523 sed -e "s/ Z\$/ /" >>expected <<-EOF &&
524 Fixes: Z
525 Acked-by= Z
526 Reviewed-by:
527 Signed-off-by: Z
528 Signed-off-by: A U Thor <author@example.com>
530 git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
531 <complex_message >actual &&
532 test_cmp expected actual
535 test_expect_success 'with empty tokens' '
536 cat >expected <<-EOF &&
538 Signed-off-by: A U Thor <author@example.com>
540 git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
542 test_cmp expected actual
545 test_expect_success 'with command but no key' '
546 git config --unset trailer.sign.key &&
547 cat >expected <<-EOF &&
549 sign: A U Thor <author@example.com>
551 git interpret-trailers >actual <<-EOF &&
553 test_cmp expected actual
556 test_expect_success 'with no command and no key' '
557 git config --unset trailer.review.key &&
558 cat >expected <<-EOF &&
560 review: Junio
561 sign: A U Thor <author@example.com>
563 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
565 test_cmp expected actual
568 test_done