3 # Copyright (c) 2013, 2014 Christian Couder
6 test_description
='git interpret-trailers'
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 &&
19 cat >complex_message_body <<-\EOF &&
23 and contains some special
27 sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF &&
33 cat >basic_patch <<-\EOF
36 1 file changed, 1 insertion(+), 1 deletion(-)
38 diff --git a/foo.txt b/foo.txt
39 index 0353767..1d91aa1 100644
53 test_expect_success
'without config' '
54 sed -e "s/ Z\$/ /" >expected <<-\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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
160 # yet another comment
166 cat basic_patch >>message_with_comments &&
167 cat basic_message >expected &&
168 cat >>expected <<-\EOF &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
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 &&
561 sign: A U Thor <author@example.com>
563 git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
565 test_cmp expected actual