t / t7513-interpret-trailers.shon commit Merge branch 'po/everyday-doc' into maint (ebae81e)
   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        EOF
 236        cat basic_patch >>expected &&
 237        git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
 238        test_cmp expected actual
 239'
 240
 241test_expect_success 'with commit complex message and trailer args' '
 242        cat complex_message_body >expected &&
 243        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 244                Fixes: Z
 245                Acked-by= Z
 246                Reviewed-by: Z
 247                Signed-off-by: Z
 248                Acked-by= Peff
 249                Bug #42
 250        EOF
 251        git interpret-trailers --trailer "ack: Peff" \
 252                --trailer "bug: 42" <complex_message >actual &&
 253        test_cmp expected actual
 254'
 255
 256test_expect_success 'with complex patch, args and --trim-empty' '
 257        cat complex_message >complex_patch &&
 258        cat basic_patch >>complex_patch &&
 259        cat complex_message_body >expected &&
 260        cat >>expected <<-\EOF &&
 261                Acked-by= Peff
 262                Bug #42
 263        EOF
 264        cat basic_patch >>expected &&
 265        git interpret-trailers --trim-empty --trailer "ack: Peff" \
 266                --trailer "bug: 42" <complex_patch >actual &&
 267        test_cmp expected actual
 268'
 269
 270test_expect_success 'using "where = before"' '
 271        git config trailer.bug.where "before" &&
 272        cat complex_message_body >expected &&
 273        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 274                Bug #42
 275                Fixes: Z
 276                Acked-by= Z
 277                Reviewed-by: Z
 278                Signed-off-by: Z
 279                Acked-by= Peff
 280        EOF
 281        git interpret-trailers --trailer "ack: Peff" \
 282                --trailer "bug: 42" complex_message >actual &&
 283        test_cmp expected actual
 284'
 285
 286test_expect_success 'using "where = after"' '
 287        git config trailer.ack.where "after" &&
 288        cat complex_message_body >expected &&
 289        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 290                Bug #42
 291                Fixes: Z
 292                Acked-by= Z
 293                Acked-by= Peff
 294                Reviewed-by: Z
 295                Signed-off-by: Z
 296        EOF
 297        git interpret-trailers --trailer "ack: Peff" \
 298                --trailer "bug: 42" complex_message >actual &&
 299        test_cmp expected actual
 300'
 301
 302test_expect_success 'using "where = end"' '
 303        git config trailer.review.key "Reviewed-by" &&
 304        git config trailer.review.where "end" &&
 305        cat complex_message_body >expected &&
 306        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 307                Fixes: Z
 308                Acked-by= Z
 309                Acked-by= Peff
 310                Reviewed-by: Z
 311                Signed-off-by: Z
 312                Reviewed-by: Junio
 313                Reviewed-by: Johannes
 314        EOF
 315        git interpret-trailers --trailer "ack: Peff" \
 316                --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
 317                complex_message >actual &&
 318        test_cmp expected actual
 319'
 320
 321test_expect_success 'using "where = start"' '
 322        git config trailer.review.key "Reviewed-by" &&
 323        git config trailer.review.where "start" &&
 324        cat complex_message_body >expected &&
 325        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 326                Reviewed-by: Johannes
 327                Reviewed-by: Junio
 328                Fixes: Z
 329                Acked-by= Z
 330                Acked-by= Peff
 331                Reviewed-by: Z
 332                Signed-off-by: Z
 333        EOF
 334        git interpret-trailers --trailer "ack: Peff" \
 335                --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
 336                complex_message >actual &&
 337        test_cmp expected actual
 338'
 339
 340test_expect_success 'using "where = before" for a token in the middle of the message' '
 341        git config trailer.review.key "Reviewed-by:" &&
 342        git config trailer.review.where "before" &&
 343        cat complex_message_body >expected &&
 344        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 345                Bug #42
 346                Fixes: Z
 347                Acked-by= Z
 348                Acked-by= Peff
 349                Reviewed-by:Johan
 350                Reviewed-by:
 351                Signed-off-by: Z
 352        EOF
 353        git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
 354                --trailer "review: Johan" <complex_message >actual &&
 355        test_cmp expected actual
 356'
 357
 358test_expect_success 'using "where = before" and --trim-empty' '
 359        cat complex_message_body >expected &&
 360        cat >>expected <<-\EOF &&
 361                Bug #46
 362                Bug #42
 363                Acked-by= Peff
 364                Reviewed-by:Johan
 365        EOF
 366        git interpret-trailers --trim-empty --trailer "ack: Peff" \
 367                --trailer "bug: 42" --trailer "review: Johan" \
 368                --trailer "Bug: 46" <complex_message >actual &&
 369        test_cmp expected actual
 370'
 371
 372test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
 373        cat complex_message_body >expected &&
 374        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 375                Bug #42
 376                Fixes: Z
 377                Acked-by= Z
 378                Acked-by= Peff
 379                Acked-by= Junio
 380                Acked-by= Peff
 381                Reviewed-by:
 382                Signed-off-by: Z
 383        EOF
 384        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 385                --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
 386                --trailer "ack: Peff" <complex_message >actual &&
 387        test_cmp expected actual
 388'
 389
 390test_expect_success 'default "ifExists" is now "addIfDifferent"' '
 391        git config trailer.ifexists "addIfDifferent" &&
 392        cat complex_message_body >expected &&
 393        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 394                Bug #42
 395                Fixes: Z
 396                Acked-by= Z
 397                Acked-by= Peff
 398                Acked-by= Junio
 399                Reviewed-by:
 400                Signed-off-by: Z
 401        EOF
 402        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 403                --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
 404                --trailer "ack: Peff" <complex_message >actual &&
 405        test_cmp expected actual
 406'
 407
 408test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
 409        git config trailer.ack.ifExists "addIfDifferent" &&
 410        git config trailer.ack.where "end" &&
 411        cat complex_message_body >expected &&
 412        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 413                Bug #42
 414                Fixes: Z
 415                Acked-by= Z
 416                Reviewed-by:
 417                Signed-off-by: Z
 418                Acked-by= Peff
 419        EOF
 420        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 421                --trailer "bug: 42" --trailer "ack: Peff" \
 422                <complex_message >actual &&
 423        test_cmp expected actual
 424'
 425
 426test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
 427        git config trailer.ack.ifExists "addIfDifferent" &&
 428        git config trailer.ack.where "before" &&
 429        cat complex_message_body >expected &&
 430        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 431                Bug #42
 432                Fixes: Z
 433                Acked-by= Peff
 434                Acked-by= Z
 435                Reviewed-by:
 436                Signed-off-by: Z
 437        EOF
 438        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 439                --trailer "bug: 42" --trailer "ack: Peff" \
 440                <complex_message >actual &&
 441        test_cmp expected actual
 442'
 443
 444test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
 445        git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
 446        git config trailer.ack.where "end" &&
 447        cat complex_message_body >expected &&
 448        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 449                Bug #42
 450                Fixes: Z
 451                Acked-by= Z
 452                Reviewed-by:
 453                Signed-off-by: Z
 454                Acked-by= Peff
 455                Acked-by= Junio
 456                Tested-by: Jakub
 457                Acked-by= Junio
 458                Acked-by= Peff
 459        EOF
 460        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 461                --trailer "ack: Junio" --trailer "bug: 42" \
 462                --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
 463                --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
 464        test_cmp expected actual
 465'
 466
 467test_expect_success 'using "ifExists = addIfDifferentNeighbor"  with "where = after"' '
 468        git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
 469        git config trailer.ack.where "after" &&
 470        cat complex_message_body >expected &&
 471        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 472                Bug #42
 473                Fixes: Z
 474                Acked-by= Z
 475                Acked-by= Peff
 476                Acked-by= Junio
 477                Acked-by= Peff
 478                Reviewed-by:
 479                Signed-off-by: Z
 480                Tested-by: Jakub
 481        EOF
 482        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 483                --trailer "ack: Junio" --trailer "bug: 42" \
 484                --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
 485                --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
 486        test_cmp expected actual
 487'
 488
 489test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
 490        git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
 491        cat complex_message_body >expected &&
 492        cat >>expected <<-\EOF &&
 493                Bug #42
 494                Acked-by= Peff
 495                Acked-by= Junio
 496                Acked-by= Peff
 497        EOF
 498        git interpret-trailers --trim-empty --trailer "ack: Peff" \
 499                --trailer "Acked-by= Peff" --trailer "review:" \
 500                --trailer "ack: Junio" --trailer "bug: 42" \
 501                --trailer "ack: Peff" <complex_message >actual &&
 502        test_cmp expected actual
 503'
 504
 505test_expect_success 'using "ifExists = add" with "where = end"' '
 506        git config trailer.ack.ifExists "add" &&
 507        git config trailer.ack.where "end" &&
 508        cat complex_message_body >expected &&
 509        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 510                Bug #42
 511                Fixes: Z
 512                Acked-by= Z
 513                Reviewed-by:
 514                Signed-off-by: Z
 515                Acked-by= Peff
 516                Acked-by= Peff
 517                Tested-by: Jakub
 518                Acked-by= Junio
 519                Tested-by: Johannes
 520                Acked-by= Peff
 521        EOF
 522        git interpret-trailers --trailer "ack: Peff" \
 523                --trailer "Acked-by= Peff" --trailer "review:" \
 524                --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
 525                --trailer "bug: 42" --trailer "Tested-by: Johannes" \
 526                --trailer "ack: Peff" <complex_message >actual &&
 527        test_cmp expected actual
 528'
 529
 530test_expect_success 'using "ifExists = add" with "where = after"' '
 531        git config trailer.ack.ifExists "add" &&
 532        git config trailer.ack.where "after" &&
 533        cat complex_message_body >expected &&
 534        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 535                Bug #42
 536                Fixes: Z
 537                Acked-by= Z
 538                Acked-by= Peff
 539                Acked-by= Peff
 540                Acked-by= Junio
 541                Acked-by= Peff
 542                Reviewed-by:
 543                Signed-off-by: Z
 544        EOF
 545        git interpret-trailers --trailer "ack: Peff" \
 546                --trailer "Acked-by= Peff" --trailer "review:" \
 547                --trailer "ack: Junio" --trailer "bug: 42" \
 548                --trailer "ack: Peff" <complex_message >actual &&
 549        test_cmp expected actual
 550'
 551
 552test_expect_success 'using "ifExists = replace"' '
 553        git config trailer.fix.key "Fixes: " &&
 554        git config trailer.fix.ifExists "replace" &&
 555        cat complex_message_body >expected &&
 556        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 557                Bug #42
 558                Acked-by= Z
 559                Acked-by= Junio
 560                Acked-by= Peff
 561                Reviewed-by:
 562                Signed-off-by: Z
 563                Fixes: 22
 564        EOF
 565        git interpret-trailers --trailer "review:" \
 566                --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
 567                --trailer "bug: 42" --trailer "ack: Peff" \
 568                <complex_message >actual &&
 569        test_cmp expected actual
 570'
 571
 572test_expect_success 'using "ifExists = replace" with "where = after"' '
 573        git config trailer.fix.where "after" &&
 574        cat complex_message_body >expected &&
 575        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 576                Bug #42
 577                Fixes: 22
 578                Acked-by= Z
 579                Acked-by= Junio
 580                Acked-by= Peff
 581                Reviewed-by:
 582                Signed-off-by: Z
 583        EOF
 584        git interpret-trailers --trailer "review:" \
 585                --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
 586                --trailer "bug: 42" --trailer "ack: Peff" \
 587                <complex_message >actual &&
 588        test_cmp expected actual
 589'
 590
 591test_expect_success 'using "ifExists = doNothing"' '
 592        git config trailer.fix.ifExists "doNothing" &&
 593        cat complex_message_body >expected &&
 594        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 595                Bug #42
 596                Fixes: Z
 597                Acked-by= Z
 598                Acked-by= Junio
 599                Acked-by= Peff
 600                Reviewed-by:
 601                Signed-off-by: Z
 602        EOF
 603        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 604                --trailer "ack: Junio" --trailer "fix=22" \
 605                --trailer "bug: 42" --trailer "ack: Peff" \
 606                <complex_message >actual &&
 607        test_cmp expected actual
 608'
 609
 610test_expect_success 'the default is "ifMissing = add"' '
 611        git config trailer.cc.key "Cc: " &&
 612        git config trailer.cc.where "before" &&
 613        cat complex_message_body >expected &&
 614        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 615                Bug #42
 616                Cc: Linus
 617                Fixes: Z
 618                Acked-by= Z
 619                Acked-by= Junio
 620                Acked-by= Peff
 621                Reviewed-by:
 622                Signed-off-by: Z
 623        EOF
 624        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 625                --trailer "cc=Linus" --trailer "ack: Junio" \
 626                --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
 627                <complex_message >actual &&
 628        test_cmp expected actual
 629'
 630
 631test_expect_success 'when default "ifMissing" is "doNothing"' '
 632        git config trailer.ifmissing "doNothing" &&
 633        cat complex_message_body >expected &&
 634        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 635                Fixes: Z
 636                Acked-by= Z
 637                Acked-by= Junio
 638                Acked-by= Peff
 639                Reviewed-by:
 640                Signed-off-by: Z
 641        EOF
 642        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 643                --trailer "cc=Linus" --trailer "ack: Junio" \
 644                --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
 645                <complex_message >actual &&
 646        test_cmp expected actual &&
 647        git config trailer.ifmissing "add"
 648'
 649
 650test_expect_success 'using "ifMissing = add" with "where = end"' '
 651        git config trailer.cc.key "Cc: " &&
 652        git config trailer.cc.where "end" &&
 653        git config trailer.cc.ifMissing "add" &&
 654        cat complex_message_body >expected &&
 655        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 656                Bug #42
 657                Fixes: Z
 658                Acked-by= Z
 659                Acked-by= Junio
 660                Acked-by= Peff
 661                Reviewed-by:
 662                Signed-off-by: Z
 663                Cc: Linus
 664        EOF
 665        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 666                --trailer "ack: Junio" --trailer "fix=22" \
 667                --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
 668                <complex_message >actual &&
 669        test_cmp expected actual
 670'
 671
 672test_expect_success 'using "ifMissing = add" with "where = before"' '
 673        git config trailer.cc.key "Cc: " &&
 674        git config trailer.cc.where "before" &&
 675        git config trailer.cc.ifMissing "add" &&
 676        cat complex_message_body >expected &&
 677        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 678                Cc: Linus
 679                Bug #42
 680                Fixes: Z
 681                Acked-by= Z
 682                Acked-by= Junio
 683                Acked-by= Peff
 684                Reviewed-by:
 685                Signed-off-by: Z
 686        EOF
 687        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 688                --trailer "ack: Junio" --trailer "fix=22" \
 689                --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
 690                <complex_message >actual &&
 691        test_cmp expected actual
 692'
 693
 694test_expect_success 'using "ifMissing = doNothing"' '
 695        git config trailer.cc.ifMissing "doNothing" &&
 696        cat complex_message_body >expected &&
 697        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 698                Bug #42
 699                Fixes: Z
 700                Acked-by= Z
 701                Acked-by= Junio
 702                Acked-by= Peff
 703                Reviewed-by:
 704                Signed-off-by: Z
 705        EOF
 706        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 707                --trailer "cc=Linus" --trailer "ack: Junio" \
 708                --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
 709                <complex_message >actual &&
 710        test_cmp expected actual
 711'
 712
 713test_expect_success 'default "where" is now "after"' '
 714        git config trailer.where "after" &&
 715        git config --unset trailer.ack.where &&
 716        cat complex_message_body >expected &&
 717        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 718                Bug #42
 719                Fixes: Z
 720                Acked-by= Z
 721                Acked-by= Peff
 722                Acked-by= Peff
 723                Acked-by= Junio
 724                Acked-by= Peff
 725                Reviewed-by:
 726                Signed-off-by: Z
 727                Tested-by: Jakub
 728                Tested-by: Johannes
 729        EOF
 730        git interpret-trailers --trailer "ack: Peff" \
 731                --trailer "Acked-by= Peff" --trailer "review:" \
 732                --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
 733                --trailer "bug: 42" --trailer "Tested-by: Johannes" \
 734                --trailer "ack: Peff" <complex_message >actual &&
 735        test_cmp expected actual
 736'
 737
 738test_expect_success 'with simple command' '
 739        git config trailer.sign.key "Signed-off-by: " &&
 740        git config trailer.sign.where "after" &&
 741        git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
 742        git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
 743        cat complex_message_body >expected &&
 744        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 745                Fixes: Z
 746                Acked-by= Z
 747                Reviewed-by:
 748                Signed-off-by: Z
 749                Signed-off-by: A U Thor <author@example.com>
 750        EOF
 751        git interpret-trailers --trailer "review:" --trailer "fix=22" \
 752                <complex_message >actual &&
 753        test_cmp expected actual
 754'
 755
 756test_expect_success 'with command using commiter information' '
 757        git config trailer.sign.ifExists "addIfDifferent" &&
 758        git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
 759        cat complex_message_body >expected &&
 760        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 761                Fixes: Z
 762                Acked-by= Z
 763                Reviewed-by:
 764                Signed-off-by: Z
 765                Signed-off-by: C O Mitter <committer@example.com>
 766        EOF
 767        git interpret-trailers --trailer "review:" --trailer "fix=22" \
 768                <complex_message >actual &&
 769        test_cmp expected actual
 770'
 771
 772test_expect_success 'with command using author information' '
 773        git config trailer.sign.key "Signed-off-by: " &&
 774        git config trailer.sign.where "after" &&
 775        git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
 776        git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
 777        cat complex_message_body >expected &&
 778        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 779                Fixes: Z
 780                Acked-by= Z
 781                Reviewed-by:
 782                Signed-off-by: Z
 783                Signed-off-by: A U Thor <author@example.com>
 784        EOF
 785        git interpret-trailers --trailer "review:" --trailer "fix=22" \
 786                <complex_message >actual &&
 787        test_cmp expected actual
 788'
 789
 790test_expect_success 'setup a commit' '
 791        echo "Content of the first commit." > a.txt &&
 792        git add a.txt &&
 793        git commit -m "Add file a.txt"
 794'
 795
 796test_expect_success 'with command using $ARG' '
 797        git config trailer.fix.ifExists "replace" &&
 798        git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
 799        FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
 800        cat complex_message_body >expected &&
 801        sed -e "s/ Z\$/ /" >>expected <<-EOF &&
 802                Fixes: $FIXED
 803                Acked-by= Z
 804                Reviewed-by:
 805                Signed-off-by: Z
 806                Signed-off-by: A U Thor <author@example.com>
 807        EOF
 808        git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
 809                <complex_message >actual &&
 810        test_cmp expected actual
 811'
 812
 813test_expect_success 'with failing command using $ARG' '
 814        git config trailer.fix.ifExists "replace" &&
 815        git config trailer.fix.command "false \$ARG" &&
 816        cat complex_message_body >expected &&
 817        sed -e "s/ Z\$/ /" >>expected <<-EOF &&
 818                Fixes: Z
 819                Acked-by= Z
 820                Reviewed-by:
 821                Signed-off-by: Z
 822                Signed-off-by: A U Thor <author@example.com>
 823        EOF
 824        git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
 825                <complex_message >actual &&
 826        test_cmp expected actual
 827'
 828
 829test_expect_success 'with empty tokens' '
 830        git config --unset trailer.fix.command &&
 831        cat >expected <<-EOF &&
 832
 833                Signed-off-by: A U Thor <author@example.com>
 834        EOF
 835        git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
 836        EOF
 837        test_cmp expected actual
 838'
 839
 840test_expect_success 'with command but no key' '
 841        git config --unset trailer.sign.key &&
 842        cat >expected <<-EOF &&
 843
 844                sign: A U Thor <author@example.com>
 845        EOF
 846        git interpret-trailers >actual <<-EOF &&
 847        EOF
 848        test_cmp expected actual
 849'
 850
 851test_expect_success 'with no command and no key' '
 852        git config --unset trailer.review.key &&
 853        cat >expected <<-EOF &&
 854
 855                review: Junio
 856                sign: A U Thor <author@example.com>
 857        EOF
 858        git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
 859        EOF
 860        test_cmp expected actual
 861'
 862
 863test_done