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