t / t7513-interpret-trailers.shon commit Merge branch 'jk/graph-padding-fix' into maint (18fd96f)
   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; 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 only a title in the message' '
 103        cat >expected <<-\EOF &&
 104                area: change
 105
 106                Reviewed-by: Peff
 107                Acked-by: Johan
 108        EOF
 109        echo "area: change" |
 110        git interpret-trailers --trailer "Reviewed-by: Peff" \
 111                --trailer "Acked-by: Johan" >actual &&
 112        test_cmp expected actual
 113'
 114
 115test_expect_success 'with multiline title in the message' '
 116        cat >expected <<-\EOF &&
 117                place of
 118                code: change
 119
 120                Reviewed-by: Peff
 121                Acked-by: Johan
 122        EOF
 123        printf "%s\n" "place of" "code: change" |
 124        git interpret-trailers --trailer "Reviewed-by: Peff" \
 125                --trailer "Acked-by: Johan" >actual &&
 126        test_cmp expected actual
 127'
 128
 129test_expect_success 'with config setup' '
 130        git config trailer.ack.key "Acked-by: " &&
 131        cat >expected <<-\EOF &&
 132
 133                Acked-by: Peff
 134        EOF
 135        git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
 136        test_cmp expected actual &&
 137        git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
 138        test_cmp expected actual &&
 139        git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
 140        test_cmp expected actual
 141'
 142
 143test_expect_success 'with config setup and ":=" as separators' '
 144        git config trailer.separators ":=" &&
 145        git config trailer.ack.key "Acked-by= " &&
 146        cat >expected <<-\EOF &&
 147
 148                Acked-by= Peff
 149        EOF
 150        git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
 151        test_cmp expected actual &&
 152        git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
 153        test_cmp expected actual &&
 154        git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
 155        test_cmp expected actual
 156'
 157
 158test_expect_success 'with config setup and "%" as separators' '
 159        git config trailer.separators "%" &&
 160        cat >expected <<-\EOF &&
 161
 162                bug% 42
 163                count% 10
 164                bug% 422
 165        EOF
 166        git interpret-trailers --trim-empty --trailer "bug = 42" \
 167                --trailer count%10 --trailer "test: stuff" \
 168                --trailer "bug % 422" empty >actual &&
 169        test_cmp expected actual
 170'
 171
 172test_expect_success 'with "%" as separators and a message with trailers' '
 173        cat >special_message <<-\EOF &&
 174                Special Message
 175
 176                bug% 42
 177                count% 10
 178                bug% 422
 179        EOF
 180        cat >expected <<-\EOF &&
 181                Special Message
 182
 183                bug% 42
 184                count% 10
 185                bug% 422
 186                count% 100
 187        EOF
 188        git interpret-trailers --trailer count%100 \
 189                special_message >actual &&
 190        test_cmp expected actual
 191'
 192
 193test_expect_success 'with config setup and ":=#" as separators' '
 194        git config trailer.separators ":=#" &&
 195        git config trailer.bug.key "Bug #" &&
 196        cat >expected <<-\EOF &&
 197
 198                Bug #42
 199        EOF
 200        git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
 201        test_cmp expected actual
 202'
 203
 204test_expect_success 'with commit basic message' '
 205        cat basic_message >expected &&
 206        echo >>expected &&
 207        git interpret-trailers <basic_message >actual &&
 208        test_cmp expected actual
 209'
 210
 211test_expect_success 'with basic patch' '
 212        cat basic_message >input &&
 213        cat basic_patch >>input &&
 214        cat basic_message >expected &&
 215        echo >>expected &&
 216        cat basic_patch >>expected &&
 217        git interpret-trailers <input >actual &&
 218        test_cmp expected actual
 219'
 220
 221test_expect_success 'with commit complex message as argument' '
 222        cat complex_message_body complex_message_trailers >complex_message &&
 223        cat complex_message_body >expected &&
 224        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 225                Fixes: Z
 226                Acked-by= Z
 227                Reviewed-by: Z
 228                Signed-off-by: Z
 229        EOF
 230        git interpret-trailers complex_message >actual &&
 231        test_cmp expected actual
 232'
 233
 234test_expect_success 'with 2 files arguments' '
 235        cat basic_message >>expected &&
 236        echo >>expected &&
 237        cat basic_patch >>expected &&
 238        git interpret-trailers complex_message input >actual &&
 239        test_cmp expected actual
 240'
 241
 242test_expect_success 'with message that has comments' '
 243        cat basic_message >message_with_comments &&
 244        sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
 245                # comment
 246
 247                # other comment
 248                Cc: Z
 249                # yet another comment
 250                Reviewed-by: Johan
 251                Reviewed-by: Z
 252                # last comment
 253
 254        EOF
 255        cat basic_patch >>message_with_comments &&
 256        cat basic_message >expected &&
 257        cat >>expected <<-\EOF &&
 258                # comment
 259
 260                Reviewed-by: Johan
 261                Cc: Peff
 262                # last comment
 263
 264        EOF
 265        cat basic_patch >>expected &&
 266        git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
 267        test_cmp expected actual
 268'
 269
 270test_expect_success 'with message that has an old style conflict block' '
 271        cat basic_message >message_with_comments &&
 272        sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
 273                # comment
 274
 275                # other comment
 276                Cc: Z
 277                # yet another comment
 278                Reviewed-by: Johan
 279                Reviewed-by: Z
 280                # last comment
 281
 282                Conflicts:
 283
 284        EOF
 285        cat basic_message >expected &&
 286        cat >>expected <<-\EOF &&
 287                # comment
 288
 289                Reviewed-by: Johan
 290                Cc: Peff
 291                # last comment
 292
 293                Conflicts:
 294
 295        EOF
 296        git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
 297        test_cmp expected actual
 298'
 299
 300test_expect_success 'with commit complex message and trailer args' '
 301        cat complex_message_body >expected &&
 302        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 303                Fixes: Z
 304                Acked-by= Z
 305                Reviewed-by: Z
 306                Signed-off-by: Z
 307                Acked-by= Peff
 308                Bug #42
 309        EOF
 310        git interpret-trailers --trailer "ack: Peff" \
 311                --trailer "bug: 42" <complex_message >actual &&
 312        test_cmp expected actual
 313'
 314
 315test_expect_success 'with complex patch, args and --trim-empty' '
 316        cat complex_message >complex_patch &&
 317        cat basic_patch >>complex_patch &&
 318        cat complex_message_body >expected &&
 319        cat >>expected <<-\EOF &&
 320                Acked-by= Peff
 321                Bug #42
 322        EOF
 323        cat basic_patch >>expected &&
 324        git interpret-trailers --trim-empty --trailer "ack: Peff" \
 325                --trailer "bug: 42" <complex_patch >actual &&
 326        test_cmp expected actual
 327'
 328
 329test_expect_success 'in-place editing with basic patch' '
 330        cat basic_message >message &&
 331        cat basic_patch >>message &&
 332        cat basic_message >expected &&
 333        echo >>expected &&
 334        cat basic_patch >>expected &&
 335        git interpret-trailers --in-place message &&
 336        test_cmp expected message
 337'
 338
 339test_expect_success 'in-place editing with additional trailer' '
 340        cat basic_message >message &&
 341        cat basic_patch >>message &&
 342        cat basic_message >expected &&
 343        echo >>expected &&
 344        cat >>expected <<-\EOF &&
 345                Reviewed-by: Alice
 346        EOF
 347        cat basic_patch >>expected &&
 348        git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
 349        test_cmp expected message
 350'
 351
 352test_expect_success 'in-place editing on stdin disallowed' '
 353        test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place < basic_message
 354'
 355
 356test_expect_success 'in-place editing on non-existing file' '
 357        test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place nonexisting &&
 358        test_path_is_missing nonexisting
 359'
 360
 361test_expect_success POSIXPERM,SANITY "in-place editing doesn't clobber original file on error" '
 362        cat basic_message >message &&
 363        chmod -r message &&
 364        test_must_fail git interpret-trailers --trailer "Reviewed-by: Alice" --in-place message &&
 365        chmod +r message &&
 366        test_cmp message basic_message
 367'
 368
 369test_expect_success 'using "where = before"' '
 370        git config trailer.bug.where "before" &&
 371        cat complex_message_body >expected &&
 372        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 373                Bug #42
 374                Fixes: Z
 375                Acked-by= Z
 376                Reviewed-by: Z
 377                Signed-off-by: Z
 378                Acked-by= Peff
 379        EOF
 380        git interpret-trailers --trailer "ack: Peff" \
 381                --trailer "bug: 42" complex_message >actual &&
 382        test_cmp expected actual
 383'
 384
 385test_expect_success 'using "where = after"' '
 386        git config trailer.ack.where "after" &&
 387        cat complex_message_body >expected &&
 388        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 389                Bug #42
 390                Fixes: Z
 391                Acked-by= Z
 392                Acked-by= Peff
 393                Reviewed-by: Z
 394                Signed-off-by: Z
 395        EOF
 396        git interpret-trailers --trailer "ack: Peff" \
 397                --trailer "bug: 42" complex_message >actual &&
 398        test_cmp expected actual
 399'
 400
 401test_expect_success 'using "where = end"' '
 402        git config trailer.review.key "Reviewed-by" &&
 403        git config trailer.review.where "end" &&
 404        cat complex_message_body >expected &&
 405        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 406                Fixes: Z
 407                Acked-by= Z
 408                Acked-by= Peff
 409                Reviewed-by: Z
 410                Signed-off-by: Z
 411                Reviewed-by: Junio
 412                Reviewed-by: Johannes
 413        EOF
 414        git interpret-trailers --trailer "ack: Peff" \
 415                --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
 416                complex_message >actual &&
 417        test_cmp expected actual
 418'
 419
 420test_expect_success 'using "where = start"' '
 421        git config trailer.review.key "Reviewed-by" &&
 422        git config trailer.review.where "start" &&
 423        cat complex_message_body >expected &&
 424        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 425                Reviewed-by: Johannes
 426                Reviewed-by: Junio
 427                Fixes: Z
 428                Acked-by= Z
 429                Acked-by= Peff
 430                Reviewed-by: Z
 431                Signed-off-by: Z
 432        EOF
 433        git interpret-trailers --trailer "ack: Peff" \
 434                --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
 435                complex_message >actual &&
 436        test_cmp expected actual
 437'
 438
 439test_expect_success 'using "where = before" for a token in the middle of the message' '
 440        git config trailer.review.key "Reviewed-by:" &&
 441        git config trailer.review.where "before" &&
 442        cat complex_message_body >expected &&
 443        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 444                Bug #42
 445                Fixes: Z
 446                Acked-by= Z
 447                Acked-by= Peff
 448                Reviewed-by:Johan
 449                Reviewed-by:
 450                Signed-off-by: Z
 451        EOF
 452        git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
 453                --trailer "review: Johan" <complex_message >actual &&
 454        test_cmp expected actual
 455'
 456
 457test_expect_success 'using "where = before" and --trim-empty' '
 458        cat complex_message_body >expected &&
 459        cat >>expected <<-\EOF &&
 460                Bug #46
 461                Bug #42
 462                Acked-by= Peff
 463                Reviewed-by:Johan
 464        EOF
 465        git interpret-trailers --trim-empty --trailer "ack: Peff" \
 466                --trailer "bug: 42" --trailer "review: Johan" \
 467                --trailer "Bug: 46" <complex_message >actual &&
 468        test_cmp expected actual
 469'
 470
 471test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
 472        cat complex_message_body >expected &&
 473        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 474                Bug #42
 475                Fixes: Z
 476                Acked-by= Z
 477                Acked-by= Peff
 478                Acked-by= Junio
 479                Acked-by= Peff
 480                Reviewed-by:
 481                Signed-off-by: Z
 482        EOF
 483        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 484                --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
 485                --trailer "ack: Peff" <complex_message >actual &&
 486        test_cmp expected actual
 487'
 488
 489test_expect_success 'default "ifExists" is now "addIfDifferent"' '
 490        git config trailer.ifexists "addIfDifferent" &&
 491        cat complex_message_body >expected &&
 492        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 493                Bug #42
 494                Fixes: Z
 495                Acked-by= Z
 496                Acked-by= Peff
 497                Acked-by= Junio
 498                Reviewed-by:
 499                Signed-off-by: Z
 500        EOF
 501        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 502                --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
 503                --trailer "ack: Peff" <complex_message >actual &&
 504        test_cmp expected actual
 505'
 506
 507test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
 508        git config trailer.ack.ifExists "addIfDifferent" &&
 509        git config trailer.ack.where "end" &&
 510        cat complex_message_body >expected &&
 511        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 512                Bug #42
 513                Fixes: Z
 514                Acked-by= Z
 515                Reviewed-by:
 516                Signed-off-by: Z
 517                Acked-by= Peff
 518        EOF
 519        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 520                --trailer "bug: 42" --trailer "ack: Peff" \
 521                <complex_message >actual &&
 522        test_cmp expected actual
 523'
 524
 525test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
 526        git config trailer.ack.ifExists "addIfDifferent" &&
 527        git config trailer.ack.where "before" &&
 528        cat complex_message_body >expected &&
 529        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 530                Bug #42
 531                Fixes: Z
 532                Acked-by= Peff
 533                Acked-by= Z
 534                Reviewed-by:
 535                Signed-off-by: Z
 536        EOF
 537        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 538                --trailer "bug: 42" --trailer "ack: Peff" \
 539                <complex_message >actual &&
 540        test_cmp expected actual
 541'
 542
 543test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
 544        git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
 545        git config trailer.ack.where "end" &&
 546        cat complex_message_body >expected &&
 547        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 548                Bug #42
 549                Fixes: Z
 550                Acked-by= Z
 551                Reviewed-by:
 552                Signed-off-by: Z
 553                Acked-by= Peff
 554                Acked-by= Junio
 555                Tested-by: Jakub
 556                Acked-by= Junio
 557                Acked-by= Peff
 558        EOF
 559        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 560                --trailer "ack: Junio" --trailer "bug: 42" \
 561                --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
 562                --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
 563        test_cmp expected actual
 564'
 565
 566test_expect_success 'using "ifExists = addIfDifferentNeighbor"  with "where = after"' '
 567        git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
 568        git config trailer.ack.where "after" &&
 569        cat complex_message_body >expected &&
 570        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 571                Bug #42
 572                Fixes: Z
 573                Acked-by= Z
 574                Acked-by= Peff
 575                Acked-by= Junio
 576                Acked-by= Peff
 577                Reviewed-by:
 578                Signed-off-by: Z
 579                Tested-by: Jakub
 580        EOF
 581        git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
 582                --trailer "ack: Junio" --trailer "bug: 42" \
 583                --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
 584                --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
 585        test_cmp expected actual
 586'
 587
 588test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
 589        git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
 590        cat complex_message_body >expected &&
 591        cat >>expected <<-\EOF &&
 592                Bug #42
 593                Acked-by= Peff
 594                Acked-by= Junio
 595                Acked-by= Peff
 596        EOF
 597        git interpret-trailers --trim-empty --trailer "ack: Peff" \
 598                --trailer "Acked-by= Peff" --trailer "review:" \
 599                --trailer "ack: Junio" --trailer "bug: 42" \
 600                --trailer "ack: Peff" <complex_message >actual &&
 601        test_cmp expected actual
 602'
 603
 604test_expect_success 'using "ifExists = add" with "where = end"' '
 605        git config trailer.ack.ifExists "add" &&
 606        git config trailer.ack.where "end" &&
 607        cat complex_message_body >expected &&
 608        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 609                Bug #42
 610                Fixes: Z
 611                Acked-by= Z
 612                Reviewed-by:
 613                Signed-off-by: Z
 614                Acked-by= Peff
 615                Acked-by= Peff
 616                Tested-by: Jakub
 617                Acked-by= Junio
 618                Tested-by: Johannes
 619                Acked-by= Peff
 620        EOF
 621        git interpret-trailers --trailer "ack: Peff" \
 622                --trailer "Acked-by= Peff" --trailer "review:" \
 623                --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
 624                --trailer "bug: 42" --trailer "Tested-by: Johannes" \
 625                --trailer "ack: Peff" <complex_message >actual &&
 626        test_cmp expected actual
 627'
 628
 629test_expect_success 'using "ifExists = add" with "where = after"' '
 630        git config trailer.ack.ifExists "add" &&
 631        git config trailer.ack.where "after" &&
 632        cat complex_message_body >expected &&
 633        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 634                Bug #42
 635                Fixes: Z
 636                Acked-by= Z
 637                Acked-by= Peff
 638                Acked-by= Peff
 639                Acked-by= Junio
 640                Acked-by= Peff
 641                Reviewed-by:
 642                Signed-off-by: Z
 643        EOF
 644        git interpret-trailers --trailer "ack: Peff" \
 645                --trailer "Acked-by= Peff" --trailer "review:" \
 646                --trailer "ack: Junio" --trailer "bug: 42" \
 647                --trailer "ack: Peff" <complex_message >actual &&
 648        test_cmp expected actual
 649'
 650
 651test_expect_success 'using "ifExists = replace"' '
 652        git config trailer.fix.key "Fixes: " &&
 653        git config trailer.fix.ifExists "replace" &&
 654        cat complex_message_body >expected &&
 655        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 656                Bug #42
 657                Acked-by= Z
 658                Acked-by= Junio
 659                Acked-by= Peff
 660                Reviewed-by:
 661                Signed-off-by: Z
 662                Fixes: 22
 663        EOF
 664        git interpret-trailers --trailer "review:" \
 665                --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
 666                --trailer "bug: 42" --trailer "ack: Peff" \
 667                <complex_message >actual &&
 668        test_cmp expected actual
 669'
 670
 671test_expect_success 'using "ifExists = replace" with "where = after"' '
 672        git config trailer.fix.where "after" &&
 673        cat complex_message_body >expected &&
 674        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 675                Bug #42
 676                Fixes: 22
 677                Acked-by= Z
 678                Acked-by= Junio
 679                Acked-by= Peff
 680                Reviewed-by:
 681                Signed-off-by: Z
 682        EOF
 683        git interpret-trailers --trailer "review:" \
 684                --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
 685                --trailer "bug: 42" --trailer "ack: Peff" \
 686                <complex_message >actual &&
 687        test_cmp expected actual
 688'
 689
 690test_expect_success 'using "ifExists = doNothing"' '
 691        git config trailer.fix.ifExists "doNothing" &&
 692        cat complex_message_body >expected &&
 693        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 694                Bug #42
 695                Fixes: Z
 696                Acked-by= Z
 697                Acked-by= Junio
 698                Acked-by= Peff
 699                Reviewed-by:
 700                Signed-off-by: Z
 701        EOF
 702        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 703                --trailer "ack: Junio" --trailer "fix=22" \
 704                --trailer "bug: 42" --trailer "ack: Peff" \
 705                <complex_message >actual &&
 706        test_cmp expected actual
 707'
 708
 709test_expect_success 'the default is "ifMissing = add"' '
 710        git config trailer.cc.key "Cc: " &&
 711        git config trailer.cc.where "before" &&
 712        cat complex_message_body >expected &&
 713        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 714                Bug #42
 715                Cc: Linus
 716                Fixes: Z
 717                Acked-by= Z
 718                Acked-by= Junio
 719                Acked-by= Peff
 720                Reviewed-by:
 721                Signed-off-by: Z
 722        EOF
 723        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 724                --trailer "cc=Linus" --trailer "ack: Junio" \
 725                --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
 726                <complex_message >actual &&
 727        test_cmp expected actual
 728'
 729
 730test_expect_success 'when default "ifMissing" is "doNothing"' '
 731        git config trailer.ifmissing "doNothing" &&
 732        cat complex_message_body >expected &&
 733        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 734                Fixes: Z
 735                Acked-by= Z
 736                Acked-by= Junio
 737                Acked-by= Peff
 738                Reviewed-by:
 739                Signed-off-by: Z
 740        EOF
 741        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 742                --trailer "cc=Linus" --trailer "ack: Junio" \
 743                --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
 744                <complex_message >actual &&
 745        test_cmp expected actual &&
 746        git config trailer.ifmissing "add"
 747'
 748
 749test_expect_success 'using "ifMissing = add" with "where = end"' '
 750        git config trailer.cc.key "Cc: " &&
 751        git config trailer.cc.where "end" &&
 752        git config trailer.cc.ifMissing "add" &&
 753        cat complex_message_body >expected &&
 754        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 755                Bug #42
 756                Fixes: Z
 757                Acked-by= Z
 758                Acked-by= Junio
 759                Acked-by= Peff
 760                Reviewed-by:
 761                Signed-off-by: Z
 762                Cc: Linus
 763        EOF
 764        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 765                --trailer "ack: Junio" --trailer "fix=22" \
 766                --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
 767                <complex_message >actual &&
 768        test_cmp expected actual
 769'
 770
 771test_expect_success 'using "ifMissing = add" with "where = before"' '
 772        git config trailer.cc.key "Cc: " &&
 773        git config trailer.cc.where "before" &&
 774        git config trailer.cc.ifMissing "add" &&
 775        cat complex_message_body >expected &&
 776        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 777                Cc: Linus
 778                Bug #42
 779                Fixes: Z
 780                Acked-by= Z
 781                Acked-by= Junio
 782                Acked-by= Peff
 783                Reviewed-by:
 784                Signed-off-by: Z
 785        EOF
 786        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 787                --trailer "ack: Junio" --trailer "fix=22" \
 788                --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
 789                <complex_message >actual &&
 790        test_cmp expected actual
 791'
 792
 793test_expect_success 'using "ifMissing = doNothing"' '
 794        git config trailer.cc.ifMissing "doNothing" &&
 795        cat complex_message_body >expected &&
 796        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 797                Bug #42
 798                Fixes: Z
 799                Acked-by= Z
 800                Acked-by= Junio
 801                Acked-by= Peff
 802                Reviewed-by:
 803                Signed-off-by: Z
 804        EOF
 805        git interpret-trailers --trailer "review:" --trailer "fix=53" \
 806                --trailer "cc=Linus" --trailer "ack: Junio" \
 807                --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
 808                <complex_message >actual &&
 809        test_cmp expected actual
 810'
 811
 812test_expect_success 'default "where" is now "after"' '
 813        git config trailer.where "after" &&
 814        git config --unset trailer.ack.where &&
 815        cat complex_message_body >expected &&
 816        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 817                Bug #42
 818                Fixes: Z
 819                Acked-by= Z
 820                Acked-by= Peff
 821                Acked-by= Peff
 822                Acked-by= Junio
 823                Acked-by= Peff
 824                Reviewed-by:
 825                Signed-off-by: Z
 826                Tested-by: Jakub
 827                Tested-by: Johannes
 828        EOF
 829        git interpret-trailers --trailer "ack: Peff" \
 830                --trailer "Acked-by= Peff" --trailer "review:" \
 831                --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
 832                --trailer "bug: 42" --trailer "Tested-by: Johannes" \
 833                --trailer "ack: Peff" <complex_message >actual &&
 834        test_cmp expected actual
 835'
 836
 837test_expect_success 'with simple command' '
 838        git config trailer.sign.key "Signed-off-by: " &&
 839        git config trailer.sign.where "after" &&
 840        git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
 841        git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
 842        cat complex_message_body >expected &&
 843        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 844                Fixes: Z
 845                Acked-by= Z
 846                Reviewed-by:
 847                Signed-off-by: Z
 848                Signed-off-by: A U Thor <author@example.com>
 849        EOF
 850        git interpret-trailers --trailer "review:" --trailer "fix=22" \
 851                <complex_message >actual &&
 852        test_cmp expected actual
 853'
 854
 855test_expect_success 'with command using commiter information' '
 856        git config trailer.sign.ifExists "addIfDifferent" &&
 857        git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
 858        cat complex_message_body >expected &&
 859        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 860                Fixes: Z
 861                Acked-by= Z
 862                Reviewed-by:
 863                Signed-off-by: Z
 864                Signed-off-by: C O Mitter <committer@example.com>
 865        EOF
 866        git interpret-trailers --trailer "review:" --trailer "fix=22" \
 867                <complex_message >actual &&
 868        test_cmp expected actual
 869'
 870
 871test_expect_success 'with command using author information' '
 872        git config trailer.sign.key "Signed-off-by: " &&
 873        git config trailer.sign.where "after" &&
 874        git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
 875        git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
 876        cat complex_message_body >expected &&
 877        sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
 878                Fixes: Z
 879                Acked-by= Z
 880                Reviewed-by:
 881                Signed-off-by: Z
 882                Signed-off-by: A U Thor <author@example.com>
 883        EOF
 884        git interpret-trailers --trailer "review:" --trailer "fix=22" \
 885                <complex_message >actual &&
 886        test_cmp expected actual
 887'
 888
 889test_expect_success 'setup a commit' '
 890        echo "Content of the first commit." > a.txt &&
 891        git add a.txt &&
 892        git commit -m "Add file a.txt"
 893'
 894
 895test_expect_success 'with command using $ARG' '
 896        git config trailer.fix.ifExists "replace" &&
 897        git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
 898        FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
 899        cat complex_message_body >expected &&
 900        sed -e "s/ Z\$/ /" >>expected <<-EOF &&
 901                Fixes: $FIXED
 902                Acked-by= Z
 903                Reviewed-by:
 904                Signed-off-by: Z
 905                Signed-off-by: A U Thor <author@example.com>
 906        EOF
 907        git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
 908                <complex_message >actual &&
 909        test_cmp expected actual
 910'
 911
 912test_expect_success 'with failing command using $ARG' '
 913        git config trailer.fix.ifExists "replace" &&
 914        git config trailer.fix.command "false \$ARG" &&
 915        cat complex_message_body >expected &&
 916        sed -e "s/ Z\$/ /" >>expected <<-EOF &&
 917                Fixes: Z
 918                Acked-by= Z
 919                Reviewed-by:
 920                Signed-off-by: Z
 921                Signed-off-by: A U Thor <author@example.com>
 922        EOF
 923        git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
 924                <complex_message >actual &&
 925        test_cmp expected actual
 926'
 927
 928test_expect_success 'with empty tokens' '
 929        git config --unset trailer.fix.command &&
 930        cat >expected <<-EOF &&
 931
 932                Signed-off-by: A U Thor <author@example.com>
 933        EOF
 934        git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
 935        EOF
 936        test_cmp expected actual
 937'
 938
 939test_expect_success 'with command but no key' '
 940        git config --unset trailer.sign.key &&
 941        cat >expected <<-EOF &&
 942
 943                sign: A U Thor <author@example.com>
 944        EOF
 945        git interpret-trailers >actual <<-EOF &&
 946        EOF
 947        test_cmp expected actual
 948'
 949
 950test_expect_success 'with no command and no key' '
 951        git config --unset trailer.review.key &&
 952        cat >expected <<-EOF &&
 953
 954                review: Junio
 955                sign: A U Thor <author@example.com>
 956        EOF
 957        git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
 958        EOF
 959        test_cmp expected actual
 960'
 961
 962test_done