t / t9001-send-email.shon commit Merge branch 'ne/pack-local-doc' into maint (162b464)
   1#!/bin/sh
   2
   3test_description='git send-email'
   4. ./test-lib.sh
   5
   6if ! test_have_prereq PERL; then
   7        say 'skipping git send-email tests, perl not available'
   8        test_done
   9fi
  10
  11PROG='git send-email'
  12test_expect_success \
  13    'prepare reference tree' \
  14    'echo "1A quick brown fox jumps over the" >file &&
  15     echo "lazy dog" >>file &&
  16     git add file &&
  17     GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
  18
  19test_expect_success \
  20    'Setup helper tool' \
  21    '(echo "#!$SHELL_PATH"
  22      echo shift
  23      echo output=1
  24      echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
  25      echo for a
  26      echo do
  27      echo "  echo \"!\$a!\""
  28      echo "done >commandline\$output"
  29      echo "cat > msgtxt\$output"
  30      ) >fake.sendmail &&
  31     chmod +x ./fake.sendmail &&
  32     git add fake.sendmail &&
  33     GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
  34
  35clean_fake_sendmail() {
  36        rm -f commandline* msgtxt*
  37}
  38
  39test_expect_success 'Extract patches' '
  40    patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
  41'
  42
  43# Test no confirm early to ensure remaining tests will not hang
  44test_no_confirm () {
  45        rm -f no_confirm_okay
  46        echo n | \
  47                GIT_SEND_EMAIL_NOTTY=1 \
  48                git send-email \
  49                --from="Example <from@example.com>" \
  50                --to=nobody@example.com \
  51                --smtp-server="$(pwd)/fake.sendmail" \
  52                $@ \
  53                $patches > stdout &&
  54                test_must_fail grep "Send this email" stdout &&
  55                > no_confirm_okay
  56}
  57
  58# Exit immediately to prevent hang if a no-confirm test fails
  59check_no_confirm () {
  60        test -f no_confirm_okay || {
  61                say 'No confirm test failed; skipping remaining tests to prevent hanging'
  62                test_done
  63        }
  64}
  65
  66test_expect_success 'No confirm with --suppress-cc' '
  67        test_no_confirm --suppress-cc=sob
  68'
  69check_no_confirm
  70
  71test_expect_success 'No confirm with --confirm=never' '
  72        test_no_confirm --confirm=never
  73'
  74check_no_confirm
  75
  76# leave sendemail.confirm set to never after this so that none of the
  77# remaining tests prompt unintentionally.
  78test_expect_success 'No confirm with sendemail.confirm=never' '
  79        git config sendemail.confirm never &&
  80        test_no_confirm --compose --subject=foo
  81'
  82check_no_confirm
  83
  84test_expect_success 'Send patches' '
  85     git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
  86'
  87
  88cat >expected <<\EOF
  89!nobody@example.com!
  90!author@example.com!
  91!one@example.com!
  92!two@example.com!
  93EOF
  94test_expect_success \
  95    'Verify commandline' \
  96    'test_cmp expected commandline1'
  97
  98test_expect_success 'Send patches with --envelope-sender' '
  99    clean_fake_sendmail &&
 100     git send-email --envelope-sender="Patch Contributer <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
 101'
 102
 103cat >expected <<\EOF
 104!patch@example.com!
 105!-i!
 106!nobody@example.com!
 107!author@example.com!
 108!one@example.com!
 109!two@example.com!
 110EOF
 111test_expect_success \
 112    'Verify commandline' \
 113    'test_cmp expected commandline1'
 114
 115test_expect_success 'Send patches with --envelope-sender=auto' '
 116    clean_fake_sendmail &&
 117     git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
 118'
 119
 120cat >expected <<\EOF
 121!nobody@example.com!
 122!-i!
 123!nobody@example.com!
 124!author@example.com!
 125!one@example.com!
 126!two@example.com!
 127EOF
 128test_expect_success \
 129    'Verify commandline' \
 130    'test_cmp expected commandline1'
 131
 132cat >expected-show-all-headers <<\EOF
 1330001-Second.patch
 134(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 135(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 136(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 137Dry-OK. Log says:
 138Server: relay.example.com
 139MAIL FROM:<from@example.com>
 140RCPT TO:<to@example.com>
 141RCPT TO:<cc@example.com>
 142RCPT TO:<author@example.com>
 143RCPT TO:<one@example.com>
 144RCPT TO:<two@example.com>
 145RCPT TO:<bcc@example.com>
 146From: Example <from@example.com>
 147To: to@example.com
 148Cc: cc@example.com,
 149        A <author@example.com>,
 150        One <one@example.com>,
 151        two@example.com
 152Subject: [PATCH 1/1] Second.
 153Date: DATE-STRING
 154Message-Id: MESSAGE-ID-STRING
 155X-Mailer: X-MAILER-STRING
 156In-Reply-To: <unique-message-id@example.com>
 157References: <unique-message-id@example.com>
 158
 159Result: OK
 160EOF
 161
 162test_expect_success 'Show all headers' '
 163        git send-email \
 164                --dry-run \
 165                --suppress-cc=sob \
 166                --from="Example <from@example.com>" \
 167                --to=to@example.com \
 168                --cc=cc@example.com \
 169                --bcc=bcc@example.com \
 170                --in-reply-to="<unique-message-id@example.com>" \
 171                --smtp-server relay.example.com \
 172                $patches |
 173        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 174                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 175                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 176                >actual-show-all-headers &&
 177        test_cmp expected-show-all-headers actual-show-all-headers
 178'
 179
 180test_expect_success 'Prompting works' '
 181        clean_fake_sendmail &&
 182        (echo "Example <from@example.com>"
 183         echo "to@example.com"
 184         echo ""
 185        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 186                --smtp-server="$(pwd)/fake.sendmail" \
 187                $patches \
 188                2>errors &&
 189                grep "^From: Example <from@example.com>\$" msgtxt1 &&
 190                grep "^To: to@example.com\$" msgtxt1
 191'
 192
 193test_expect_success 'cccmd works' '
 194        clean_fake_sendmail &&
 195        cp $patches cccmd.patch &&
 196        echo cccmd--cccmd@example.com >>cccmd.patch &&
 197        {
 198          echo "#!$SHELL_PATH"
 199          echo sed -n -e s/^cccmd--//p \"\$1\"
 200        } > cccmd-sed &&
 201        chmod +x cccmd-sed &&
 202        git send-email \
 203                --from="Example <nobody@example.com>" \
 204                --to=nobody@example.com \
 205                --cc-cmd=./cccmd-sed \
 206                --smtp-server="$(pwd)/fake.sendmail" \
 207                cccmd.patch \
 208                &&
 209        grep "^ cccmd@example.com" msgtxt1
 210'
 211
 212z8=zzzzzzzz
 213z64=$z8$z8$z8$z8$z8$z8$z8$z8
 214z512=$z64$z64$z64$z64$z64$z64$z64$z64
 215test_expect_success 'reject long lines' '
 216        clean_fake_sendmail &&
 217        cp $patches longline.patch &&
 218        echo $z512$z512 >>longline.patch &&
 219        test_must_fail git send-email \
 220                --from="Example <nobody@example.com>" \
 221                --to=nobody@example.com \
 222                --smtp-server="$(pwd)/fake.sendmail" \
 223                $patches longline.patch \
 224                2>errors &&
 225        grep longline.patch errors
 226'
 227
 228test_expect_success 'no patch was sent' '
 229        ! test -e commandline1
 230'
 231
 232test_expect_success 'Author From: in message body' '
 233        clean_fake_sendmail &&
 234        git send-email \
 235                --from="Example <nobody@example.com>" \
 236                --to=nobody@example.com \
 237                --smtp-server="$(pwd)/fake.sendmail" \
 238                $patches &&
 239        sed "1,/^\$/d" < msgtxt1 > msgbody1
 240        grep "From: A <author@example.com>" msgbody1
 241'
 242
 243test_expect_success 'Author From: not in message body' '
 244        clean_fake_sendmail &&
 245        git send-email \
 246                --from="A <author@example.com>" \
 247                --to=nobody@example.com \
 248                --smtp-server="$(pwd)/fake.sendmail" \
 249                $patches &&
 250        sed "1,/^\$/d" < msgtxt1 > msgbody1
 251        ! grep "From: A <author@example.com>" msgbody1
 252'
 253
 254test_expect_success 'allow long lines with --no-validate' '
 255        git send-email \
 256                --from="Example <nobody@example.com>" \
 257                --to=nobody@example.com \
 258                --smtp-server="$(pwd)/fake.sendmail" \
 259                --novalidate \
 260                $patches longline.patch \
 261                2>errors
 262'
 263
 264test_expect_success 'Invalid In-Reply-To' '
 265        clean_fake_sendmail &&
 266        git send-email \
 267                --from="Example <nobody@example.com>" \
 268                --to=nobody@example.com \
 269                --in-reply-to=" " \
 270                --smtp-server="$(pwd)/fake.sendmail" \
 271                $patches
 272                2>errors
 273        ! grep "^In-Reply-To: < *>" msgtxt1
 274'
 275
 276test_expect_success 'Valid In-Reply-To when prompting' '
 277        clean_fake_sendmail &&
 278        (echo "From Example <from@example.com>"
 279         echo "To Example <to@example.com>"
 280         echo ""
 281        ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
 282                --smtp-server="$(pwd)/fake.sendmail" \
 283                $patches 2>errors &&
 284        ! grep "^In-Reply-To: < *>" msgtxt1
 285'
 286
 287test_expect_success 'setup fake editor' '
 288        (echo "#!$SHELL_PATH" &&
 289         echo "echo fake edit >>\"\$1\""
 290        ) >fake-editor &&
 291        chmod +x fake-editor
 292'
 293
 294test_set_editor "$(pwd)/fake-editor"
 295
 296test_expect_success '--compose works' '
 297        clean_fake_sendmail &&
 298        git send-email \
 299        --compose --subject foo \
 300        --from="Example <nobody@example.com>" \
 301        --to=nobody@example.com \
 302        --smtp-server="$(pwd)/fake.sendmail" \
 303        $patches \
 304        2>errors
 305'
 306
 307test_expect_success 'first message is compose text' '
 308        grep "^fake edit" msgtxt1
 309'
 310
 311test_expect_success 'second message is patch' '
 312        grep "Subject:.*Second" msgtxt2
 313'
 314
 315cat >expected-suppress-sob <<\EOF
 3160001-Second.patch
 317(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 318(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 319(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 320Dry-OK. Log says:
 321Server: relay.example.com
 322MAIL FROM:<from@example.com>
 323RCPT TO:<to@example.com>
 324RCPT TO:<cc@example.com>
 325RCPT TO:<author@example.com>
 326RCPT TO:<one@example.com>
 327RCPT TO:<two@example.com>
 328From: Example <from@example.com>
 329To: to@example.com
 330Cc: cc@example.com,
 331        A <author@example.com>,
 332        One <one@example.com>,
 333        two@example.com
 334Subject: [PATCH 1/1] Second.
 335Date: DATE-STRING
 336Message-Id: MESSAGE-ID-STRING
 337X-Mailer: X-MAILER-STRING
 338
 339Result: OK
 340EOF
 341
 342test_suppression () {
 343        git send-email \
 344                --dry-run \
 345                --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
 346                --from="Example <from@example.com>" \
 347                --to=to@example.com \
 348                --smtp-server relay.example.com \
 349                $patches |
 350        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 351                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 352                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 353                >actual-suppress-$1${2+"-$2"} &&
 354        test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
 355}
 356
 357test_expect_success 'sendemail.cc set' '
 358        git config sendemail.cc cc@example.com &&
 359        test_suppression sob
 360'
 361
 362cat >expected-suppress-sob <<\EOF
 3630001-Second.patch
 364(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 365(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 366(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 367Dry-OK. Log says:
 368Server: relay.example.com
 369MAIL FROM:<from@example.com>
 370RCPT TO:<to@example.com>
 371RCPT TO:<author@example.com>
 372RCPT TO:<one@example.com>
 373RCPT TO:<two@example.com>
 374From: Example <from@example.com>
 375To: to@example.com
 376Cc: A <author@example.com>,
 377        One <one@example.com>,
 378        two@example.com
 379Subject: [PATCH 1/1] Second.
 380Date: DATE-STRING
 381Message-Id: MESSAGE-ID-STRING
 382X-Mailer: X-MAILER-STRING
 383
 384Result: OK
 385EOF
 386
 387test_expect_success 'sendemail.cc unset' '
 388        git config --unset sendemail.cc &&
 389        test_suppression sob
 390'
 391
 392cat >expected-suppress-cccmd <<\EOF
 3930001-Second.patch
 394(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 395(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 396(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 397(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 398Dry-OK. Log says:
 399Server: relay.example.com
 400MAIL FROM:<from@example.com>
 401RCPT TO:<to@example.com>
 402RCPT TO:<author@example.com>
 403RCPT TO:<one@example.com>
 404RCPT TO:<two@example.com>
 405RCPT TO:<committer@example.com>
 406From: Example <from@example.com>
 407To: to@example.com
 408Cc: A <author@example.com>,
 409        One <one@example.com>,
 410        two@example.com,
 411        C O Mitter <committer@example.com>
 412Subject: [PATCH 1/1] Second.
 413Date: DATE-STRING
 414Message-Id: MESSAGE-ID-STRING
 415X-Mailer: X-MAILER-STRING
 416
 417Result: OK
 418EOF
 419
 420test_expect_success 'sendemail.cccmd' '
 421        echo echo cc-cmd@example.com > cccmd &&
 422        chmod +x cccmd &&
 423        git config sendemail.cccmd ./cccmd &&
 424        test_suppression cccmd
 425'
 426
 427cat >expected-suppress-all <<\EOF
 4280001-Second.patch
 429Dry-OK. Log says:
 430Server: relay.example.com
 431MAIL FROM:<from@example.com>
 432RCPT TO:<to@example.com>
 433From: Example <from@example.com>
 434To: to@example.com
 435Subject: [PATCH 1/1] Second.
 436Date: DATE-STRING
 437Message-Id: MESSAGE-ID-STRING
 438X-Mailer: X-MAILER-STRING
 439
 440Result: OK
 441EOF
 442
 443test_expect_success '--suppress-cc=all' '
 444        test_suppression all
 445'
 446
 447cat >expected-suppress-body <<\EOF
 4480001-Second.patch
 449(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 450(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 451(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 452(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
 453Dry-OK. Log says:
 454Server: relay.example.com
 455MAIL FROM:<from@example.com>
 456RCPT TO:<to@example.com>
 457RCPT TO:<author@example.com>
 458RCPT TO:<one@example.com>
 459RCPT TO:<two@example.com>
 460RCPT TO:<cc-cmd@example.com>
 461From: Example <from@example.com>
 462To: to@example.com
 463Cc: A <author@example.com>,
 464        One <one@example.com>,
 465        two@example.com,
 466        cc-cmd@example.com
 467Subject: [PATCH 1/1] Second.
 468Date: DATE-STRING
 469Message-Id: MESSAGE-ID-STRING
 470X-Mailer: X-MAILER-STRING
 471
 472Result: OK
 473EOF
 474
 475test_expect_success '--suppress-cc=body' '
 476        test_suppression body
 477'
 478
 479cat >expected-suppress-body-cccmd <<\EOF
 4800001-Second.patch
 481(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 482(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 483(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 484Dry-OK. Log says:
 485Server: relay.example.com
 486MAIL FROM:<from@example.com>
 487RCPT TO:<to@example.com>
 488RCPT TO:<author@example.com>
 489RCPT TO:<one@example.com>
 490RCPT TO:<two@example.com>
 491From: Example <from@example.com>
 492To: to@example.com
 493Cc: A <author@example.com>,
 494        One <one@example.com>,
 495        two@example.com
 496Subject: [PATCH 1/1] Second.
 497Date: DATE-STRING
 498Message-Id: MESSAGE-ID-STRING
 499X-Mailer: X-MAILER-STRING
 500
 501Result: OK
 502EOF
 503
 504test_expect_success '--suppress-cc=body --suppress-cc=cccmd' '
 505        test_suppression body cccmd
 506'
 507
 508cat >expected-suppress-sob <<\EOF
 5090001-Second.patch
 510(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 511(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 512(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 513Dry-OK. Log says:
 514Server: relay.example.com
 515MAIL FROM:<from@example.com>
 516RCPT TO:<to@example.com>
 517RCPT TO:<author@example.com>
 518RCPT TO:<one@example.com>
 519RCPT TO:<two@example.com>
 520From: Example <from@example.com>
 521To: to@example.com
 522Cc: A <author@example.com>,
 523        One <one@example.com>,
 524        two@example.com
 525Subject: [PATCH 1/1] Second.
 526Date: DATE-STRING
 527Message-Id: MESSAGE-ID-STRING
 528X-Mailer: X-MAILER-STRING
 529
 530Result: OK
 531EOF
 532
 533test_expect_success '--suppress-cc=sob' '
 534        git config --unset sendemail.cccmd
 535        test_suppression sob
 536'
 537
 538cat >expected-suppress-bodycc <<\EOF
 5390001-Second.patch
 540(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 541(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 542(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 543(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 544Dry-OK. Log says:
 545Server: relay.example.com
 546MAIL FROM:<from@example.com>
 547RCPT TO:<to@example.com>
 548RCPT TO:<author@example.com>
 549RCPT TO:<one@example.com>
 550RCPT TO:<two@example.com>
 551RCPT TO:<committer@example.com>
 552From: Example <from@example.com>
 553To: to@example.com
 554Cc: A <author@example.com>,
 555        One <one@example.com>,
 556        two@example.com,
 557        C O Mitter <committer@example.com>
 558Subject: [PATCH 1/1] Second.
 559Date: DATE-STRING
 560Message-Id: MESSAGE-ID-STRING
 561X-Mailer: X-MAILER-STRING
 562
 563Result: OK
 564EOF
 565
 566test_expect_success '--suppress-cc=bodycc' '
 567        test_suppression bodycc
 568'
 569
 570cat >expected-suppress-cc <<\EOF
 5710001-Second.patch
 572(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 573(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 574Dry-OK. Log says:
 575Server: relay.example.com
 576MAIL FROM:<from@example.com>
 577RCPT TO:<to@example.com>
 578RCPT TO:<author@example.com>
 579RCPT TO:<committer@example.com>
 580From: Example <from@example.com>
 581To: to@example.com
 582Cc: A <author@example.com>,
 583        C O Mitter <committer@example.com>
 584Subject: [PATCH 1/1] Second.
 585Date: DATE-STRING
 586Message-Id: MESSAGE-ID-STRING
 587X-Mailer: X-MAILER-STRING
 588
 589Result: OK
 590EOF
 591
 592test_expect_success '--suppress-cc=cc' '
 593        test_suppression cc
 594'
 595
 596test_confirm () {
 597        echo y | \
 598                GIT_SEND_EMAIL_NOTTY=1 \
 599                git send-email \
 600                --from="Example <nobody@example.com>" \
 601                --to=nobody@example.com \
 602                --smtp-server="$(pwd)/fake.sendmail" \
 603                $@ $patches > stdout &&
 604        grep "Send this email" stdout
 605}
 606
 607test_expect_success '--confirm=always' '
 608        test_confirm --confirm=always --suppress-cc=all
 609'
 610
 611test_expect_success '--confirm=auto' '
 612        test_confirm --confirm=auto
 613'
 614
 615test_expect_success '--confirm=cc' '
 616        test_confirm --confirm=cc
 617'
 618
 619test_expect_success '--confirm=compose' '
 620        test_confirm --confirm=compose --compose
 621'
 622
 623test_expect_success 'confirm by default (due to cc)' '
 624        CONFIRM=$(git config --get sendemail.confirm) &&
 625        git config --unset sendemail.confirm &&
 626        test_confirm
 627        ret="$?"
 628        git config sendemail.confirm ${CONFIRM:-never}
 629        test $ret = "0"
 630'
 631
 632test_expect_success 'confirm by default (due to --compose)' '
 633        CONFIRM=$(git config --get sendemail.confirm) &&
 634        git config --unset sendemail.confirm &&
 635        test_confirm --suppress-cc=all --compose
 636        ret="$?"
 637        git config sendemail.confirm ${CONFIRM:-never}
 638        test $ret = "0"
 639'
 640
 641test_expect_success 'confirm detects EOF (inform assumes y)' '
 642        CONFIRM=$(git config --get sendemail.confirm) &&
 643        git config --unset sendemail.confirm &&
 644        rm -fr outdir &&
 645        git format-patch -2 -o outdir &&
 646        GIT_SEND_EMAIL_NOTTY=1 \
 647                git send-email \
 648                        --from="Example <nobody@example.com>" \
 649                        --to=nobody@example.com \
 650                        --smtp-server="$(pwd)/fake.sendmail" \
 651                        outdir/*.patch < /dev/null
 652        ret="$?"
 653        git config sendemail.confirm ${CONFIRM:-never}
 654        test $ret = "0"
 655'
 656
 657test_expect_success 'confirm detects EOF (auto causes failure)' '
 658        CONFIRM=$(git config --get sendemail.confirm) &&
 659        git config sendemail.confirm auto &&
 660        GIT_SEND_EMAIL_NOTTY=1 &&
 661        export GIT_SEND_EMAIL_NOTTY &&
 662                test_must_fail git send-email \
 663                        --from="Example <nobody@example.com>" \
 664                        --to=nobody@example.com \
 665                        --smtp-server="$(pwd)/fake.sendmail" \
 666                        $patches < /dev/null
 667        ret="$?"
 668        git config sendemail.confirm ${CONFIRM:-never}
 669        test $ret = "0"
 670'
 671
 672test_expect_success 'confirm doesnt loop forever' '
 673        CONFIRM=$(git config --get sendemail.confirm) &&
 674        git config sendemail.confirm auto &&
 675        GIT_SEND_EMAIL_NOTTY=1 &&
 676        export GIT_SEND_EMAIL_NOTTY &&
 677                yes "bogus" | test_must_fail git send-email \
 678                        --from="Example <nobody@example.com>" \
 679                        --to=nobody@example.com \
 680                        --smtp-server="$(pwd)/fake.sendmail" \
 681                        $patches
 682        ret="$?"
 683        git config sendemail.confirm ${CONFIRM:-never}
 684        test $ret = "0"
 685'
 686
 687test_expect_success 'utf8 Cc is rfc2047 encoded' '
 688        clean_fake_sendmail &&
 689        rm -fr outdir &&
 690        git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
 691        git send-email \
 692        --from="Example <nobody@example.com>" \
 693        --to=nobody@example.com \
 694        --smtp-server="$(pwd)/fake.sendmail" \
 695        outdir/*.patch &&
 696        grep "^ " msgtxt1 |
 697        grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
 698'
 699
 700test_expect_success '--compose adds MIME for utf8 body' '
 701        clean_fake_sendmail &&
 702        (echo "#!$SHELL_PATH" &&
 703         echo "echo utf8 body: àéìöú >>\"\$1\""
 704        ) >fake-editor-utf8 &&
 705        chmod +x fake-editor-utf8 &&
 706          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 707          git send-email \
 708          --compose --subject foo \
 709          --from="Example <nobody@example.com>" \
 710          --to=nobody@example.com \
 711          --smtp-server="$(pwd)/fake.sendmail" \
 712          $patches &&
 713        grep "^utf8 body" msgtxt1 &&
 714        grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 715'
 716
 717test_expect_success '--compose respects user mime type' '
 718        clean_fake_sendmail &&
 719        (echo "#!$SHELL_PATH" &&
 720         echo "(echo MIME-Version: 1.0"
 721         echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
 722         echo " echo Content-Transfer-Encoding: 8bit"
 723         echo " echo Subject: foo"
 724         echo " echo "
 725         echo " echo utf8 body: àéìöú) >\"\$1\""
 726        ) >fake-editor-utf8-mime &&
 727        chmod +x fake-editor-utf8-mime &&
 728          GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
 729          git send-email \
 730          --compose --subject foo \
 731          --from="Example <nobody@example.com>" \
 732          --to=nobody@example.com \
 733          --smtp-server="$(pwd)/fake.sendmail" \
 734          $patches &&
 735        grep "^utf8 body" msgtxt1 &&
 736        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
 737        ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 738'
 739
 740test_expect_success '--compose adds MIME for utf8 subject' '
 741        clean_fake_sendmail &&
 742          GIT_EDITOR="\"$(pwd)/fake-editor\"" \
 743          git send-email \
 744          --compose --subject utf8-sübjëct \
 745          --from="Example <nobody@example.com>" \
 746          --to=nobody@example.com \
 747          --smtp-server="$(pwd)/fake.sendmail" \
 748          $patches &&
 749        grep "^fake edit" msgtxt1 &&
 750        grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
 751'
 752
 753test_expect_success 'detects ambiguous reference/file conflict' '
 754        echo master > master &&
 755        git add master &&
 756        git commit -m"add master" &&
 757        test_must_fail git send-email --dry-run master 2>errors &&
 758        grep disambiguate errors
 759'
 760
 761test_expect_success 'feed two files' '
 762        rm -fr outdir &&
 763        git format-patch -2 -o outdir &&
 764        git send-email \
 765        --dry-run \
 766        --from="Example <nobody@example.com>" \
 767        --to=nobody@example.com \
 768        outdir/000?-*.patch 2>errors >out &&
 769        grep "^Subject: " out >subjects &&
 770        test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
 771        test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
 772'
 773
 774test_expect_success 'in-reply-to but no threading' '
 775        git send-email \
 776                --dry-run \
 777                --from="Example <nobody@example.com>" \
 778                --to=nobody@example.com \
 779                --in-reply-to="<in-reply-id@example.com>" \
 780                --nothread \
 781                $patches |
 782        grep "In-Reply-To: <in-reply-id@example.com>"
 783'
 784
 785test_expect_success 'no in-reply-to and no threading' '
 786        git send-email \
 787                --dry-run \
 788                --from="Example <nobody@example.com>" \
 789                --to=nobody@example.com \
 790                --nothread \
 791                $patches $patches >stdout &&
 792        ! grep "In-Reply-To: " stdout
 793'
 794
 795test_expect_success 'threading but no chain-reply-to' '
 796        git send-email \
 797                --dry-run \
 798                --from="Example <nobody@example.com>" \
 799                --to=nobody@example.com \
 800                --thread \
 801                --nochain-reply-to \
 802                $patches $patches >stdout &&
 803        grep "In-Reply-To: " stdout
 804'
 805
 806test_expect_success 'warning with an implicit --chain-reply-to' '
 807        git send-email \
 808        --dry-run \
 809        --from="Example <nobody@example.com>" \
 810        --to=nobody@example.com \
 811        outdir/000?-*.patch 2>errors >out &&
 812        grep "no-chain-reply-to" errors
 813'
 814
 815test_expect_success 'no warning with an explicit --chain-reply-to' '
 816        git send-email \
 817        --dry-run \
 818        --from="Example <nobody@example.com>" \
 819        --to=nobody@example.com \
 820        --chain-reply-to \
 821        outdir/000?-*.patch 2>errors >out &&
 822        ! grep "no-chain-reply-to" errors
 823'
 824
 825test_expect_success 'no warning with an explicit --no-chain-reply-to' '
 826        git send-email \
 827        --dry-run \
 828        --from="Example <nobody@example.com>" \
 829        --to=nobody@example.com \
 830        --nochain-reply-to \
 831        outdir/000?-*.patch 2>errors >out &&
 832        ! grep "no-chain-reply-to" errors
 833'
 834
 835test_expect_success 'no warning with sendemail.chainreplyto = false' '
 836        git config sendemail.chainreplyto false &&
 837        git send-email \
 838        --dry-run \
 839        --from="Example <nobody@example.com>" \
 840        --to=nobody@example.com \
 841        outdir/000?-*.patch 2>errors >out &&
 842        ! grep "no-chain-reply-to" errors
 843'
 844
 845test_expect_success 'no warning with sendemail.chainreplyto = true' '
 846        git config sendemail.chainreplyto true &&
 847        git send-email \
 848        --dry-run \
 849        --from="Example <nobody@example.com>" \
 850        --to=nobody@example.com \
 851        outdir/000?-*.patch 2>errors >out &&
 852        ! grep "no-chain-reply-to" errors
 853'
 854
 855test_done