t / t9001-send-email.shon commit t/t9602-cvsimport-branches-tags.sh: Add a PERL prerequisite (06eaaa7)
   1#!/bin/sh
   2
   3test_description='git send-email'
   4. ./test-lib.sh
   5
   6# May be altered later in the test
   7PREREQ="PERL"
   8
   9test_expect_success $PREREQ \
  10    'prepare reference tree' \
  11    'echo "1A quick brown fox jumps over the" >file &&
  12     echo "lazy dog" >>file &&
  13     git add file &&
  14     GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
  15
  16test_expect_success $PREREQ \
  17    'Setup helper tool' \
  18    '(echo "#!$SHELL_PATH"
  19      echo shift
  20      echo output=1
  21      echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
  22      echo for a
  23      echo do
  24      echo "  echo \"!\$a!\""
  25      echo "done >commandline\$output"
  26      echo "cat > msgtxt\$output"
  27      ) >fake.sendmail &&
  28     chmod +x ./fake.sendmail &&
  29     git add fake.sendmail &&
  30     GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
  31
  32clean_fake_sendmail() {
  33        rm -f commandline* msgtxt*
  34}
  35
  36test_expect_success $PREREQ 'Extract patches' '
  37    patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
  38'
  39
  40# Test no confirm early to ensure remaining tests will not hang
  41test_no_confirm () {
  42        rm -f no_confirm_okay
  43        echo n | \
  44                GIT_SEND_EMAIL_NOTTY=1 \
  45                git send-email \
  46                --from="Example <from@example.com>" \
  47                --to=nobody@example.com \
  48                --smtp-server="$(pwd)/fake.sendmail" \
  49                $@ \
  50                $patches > stdout &&
  51                test_must_fail grep "Send this email" stdout &&
  52                > no_confirm_okay
  53}
  54
  55# Exit immediately to prevent hang if a no-confirm test fails
  56check_no_confirm () {
  57        if ! test -f no_confirm_okay
  58        then
  59                say 'confirm test failed; skipping remaining tests to prevent hanging'
  60                PREREQ="$PREREQ,CHECK_NO_CONFIRM"
  61        fi
  62        return 0
  63}
  64
  65test_expect_success $PREREQ 'No confirm with --suppress-cc' '
  66        test_no_confirm --suppress-cc=sob &&
  67        check_no_confirm
  68'
  69
  70
  71test_expect_success $PREREQ 'No confirm with --confirm=never' '
  72        test_no_confirm --confirm=never &&
  73        check_no_confirm
  74'
  75
  76# leave sendemail.confirm set to never after this so that none of the
  77# remaining tests prompt unintentionally.
  78test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
  79        git config sendemail.confirm never &&
  80        test_no_confirm --compose --subject=foo &&
  81        check_no_confirm
  82'
  83
  84test_expect_success $PREREQ '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
  88test_expect_success $PREREQ 'setup expect' '
  89cat >expected <<\EOF
  90!nobody@example.com!
  91!author@example.com!
  92!one@example.com!
  93!two@example.com!
  94EOF
  95'
  96
  97test_expect_success $PREREQ \
  98    'Verify commandline' \
  99    'test_cmp expected commandline1'
 100
 101test_expect_success $PREREQ 'Send patches with --envelope-sender' '
 102    clean_fake_sendmail &&
 103     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
 104'
 105
 106test_expect_success $PREREQ 'setup expect' '
 107cat >expected <<\EOF
 108!patch@example.com!
 109!-i!
 110!nobody@example.com!
 111!author@example.com!
 112!one@example.com!
 113!two@example.com!
 114EOF
 115'
 116
 117test_expect_success $PREREQ \
 118    'Verify commandline' \
 119    'test_cmp expected commandline1'
 120
 121test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
 122    clean_fake_sendmail &&
 123     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
 124'
 125
 126test_expect_success $PREREQ 'setup expect' '
 127cat >expected <<\EOF
 128!nobody@example.com!
 129!-i!
 130!nobody@example.com!
 131!author@example.com!
 132!one@example.com!
 133!two@example.com!
 134EOF
 135'
 136
 137test_expect_success $PREREQ \
 138    'Verify commandline' \
 139    'test_cmp expected commandline1'
 140
 141test_expect_success $PREREQ 'setup expect' "
 142cat >expected-show-all-headers <<\EOF
 1430001-Second.patch
 144(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 145(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 146(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 147Dry-OK. Log says:
 148Server: relay.example.com
 149MAIL FROM:<from@example.com>
 150RCPT TO:<to@example.com>
 151RCPT TO:<cc@example.com>
 152RCPT TO:<author@example.com>
 153RCPT TO:<one@example.com>
 154RCPT TO:<two@example.com>
 155RCPT TO:<bcc@example.com>
 156From: Example <from@example.com>
 157To: to@example.com
 158Cc: cc@example.com,
 159        A <author@example.com>,
 160        One <one@example.com>,
 161        two@example.com
 162Subject: [PATCH 1/1] Second.
 163Date: DATE-STRING
 164Message-Id: MESSAGE-ID-STRING
 165X-Mailer: X-MAILER-STRING
 166In-Reply-To: <unique-message-id@example.com>
 167References: <unique-message-id@example.com>
 168
 169Result: OK
 170EOF
 171"
 172
 173test_expect_success $PREREQ 'Show all headers' '
 174        git send-email \
 175                --dry-run \
 176                --suppress-cc=sob \
 177                --from="Example <from@example.com>" \
 178                --to=to@example.com \
 179                --cc=cc@example.com \
 180                --bcc=bcc@example.com \
 181                --in-reply-to="<unique-message-id@example.com>" \
 182                --smtp-server relay.example.com \
 183                $patches |
 184        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 185                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 186                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 187                >actual-show-all-headers &&
 188        test_cmp expected-show-all-headers actual-show-all-headers
 189'
 190
 191test_expect_success $PREREQ 'Prompting works' '
 192        clean_fake_sendmail &&
 193        (echo "Example <from@example.com>"
 194         echo "to@example.com"
 195         echo ""
 196        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 197                --smtp-server="$(pwd)/fake.sendmail" \
 198                $patches \
 199                2>errors &&
 200                grep "^From: Example <from@example.com>\$" msgtxt1 &&
 201                grep "^To: to@example.com\$" msgtxt1
 202'
 203
 204test_expect_success $PREREQ 'cccmd works' '
 205        clean_fake_sendmail &&
 206        cp $patches cccmd.patch &&
 207        echo cccmd--cccmd@example.com >>cccmd.patch &&
 208        {
 209          echo "#!$SHELL_PATH"
 210          echo sed -n -e s/^cccmd--//p \"\$1\"
 211        } > cccmd-sed &&
 212        chmod +x cccmd-sed &&
 213        git send-email \
 214                --from="Example <nobody@example.com>" \
 215                --to=nobody@example.com \
 216                --cc-cmd=./cccmd-sed \
 217                --smtp-server="$(pwd)/fake.sendmail" \
 218                cccmd.patch \
 219                &&
 220        grep "^ cccmd@example.com" msgtxt1
 221'
 222
 223test_expect_success $PREREQ 'reject long lines' '
 224        z8=zzzzzzzz &&
 225        z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
 226        z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
 227        clean_fake_sendmail &&
 228        cp $patches longline.patch &&
 229        echo $z512$z512 >>longline.patch &&
 230        test_must_fail git send-email \
 231                --from="Example <nobody@example.com>" \
 232                --to=nobody@example.com \
 233                --smtp-server="$(pwd)/fake.sendmail" \
 234                $patches longline.patch \
 235                2>errors &&
 236        grep longline.patch errors
 237'
 238
 239test_expect_success $PREREQ 'no patch was sent' '
 240        ! test -e commandline1
 241'
 242
 243test_expect_success $PREREQ 'Author From: in message body' '
 244        clean_fake_sendmail &&
 245        git send-email \
 246                --from="Example <nobody@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 $PREREQ 'Author From: not in message body' '
 255        clean_fake_sendmail &&
 256        git send-email \
 257                --from="A <author@example.com>" \
 258                --to=nobody@example.com \
 259                --smtp-server="$(pwd)/fake.sendmail" \
 260                $patches &&
 261        sed "1,/^\$/d" < msgtxt1 > msgbody1
 262        ! grep "From: A <author@example.com>" msgbody1
 263'
 264
 265test_expect_success $PREREQ 'allow long lines with --no-validate' '
 266        git send-email \
 267                --from="Example <nobody@example.com>" \
 268                --to=nobody@example.com \
 269                --smtp-server="$(pwd)/fake.sendmail" \
 270                --novalidate \
 271                $patches longline.patch \
 272                2>errors
 273'
 274
 275test_expect_success $PREREQ 'Invalid In-Reply-To' '
 276        clean_fake_sendmail &&
 277        git send-email \
 278                --from="Example <nobody@example.com>" \
 279                --to=nobody@example.com \
 280                --in-reply-to=" " \
 281                --smtp-server="$(pwd)/fake.sendmail" \
 282                $patches
 283                2>errors
 284        ! grep "^In-Reply-To: < *>" msgtxt1
 285'
 286
 287test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
 288        clean_fake_sendmail &&
 289        (echo "From Example <from@example.com>"
 290         echo "To Example <to@example.com>"
 291         echo ""
 292        ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
 293                --smtp-server="$(pwd)/fake.sendmail" \
 294                $patches 2>errors &&
 295        ! grep "^In-Reply-To: < *>" msgtxt1
 296'
 297
 298test_expect_success $PREREQ 'setup fake editor' '
 299        (echo "#!$SHELL_PATH" &&
 300         echo "echo fake edit >>\"\$1\""
 301        ) >fake-editor &&
 302        chmod +x fake-editor
 303'
 304
 305test_set_editor "$(pwd)/fake-editor"
 306
 307test_expect_success $PREREQ '--compose works' '
 308        clean_fake_sendmail &&
 309        git send-email \
 310        --compose --subject foo \
 311        --from="Example <nobody@example.com>" \
 312        --to=nobody@example.com \
 313        --smtp-server="$(pwd)/fake.sendmail" \
 314        $patches \
 315        2>errors
 316'
 317
 318test_expect_success $PREREQ 'first message is compose text' '
 319        grep "^fake edit" msgtxt1
 320'
 321
 322test_expect_success $PREREQ 'second message is patch' '
 323        grep "Subject:.*Second" msgtxt2
 324'
 325
 326test_expect_success $PREREQ 'setup expect' "
 327cat >expected-suppress-sob <<\EOF
 3280001-Second.patch
 329(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 330(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 331(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 332Dry-OK. Log says:
 333Server: relay.example.com
 334MAIL FROM:<from@example.com>
 335RCPT TO:<to@example.com>
 336RCPT TO:<cc@example.com>
 337RCPT TO:<author@example.com>
 338RCPT TO:<one@example.com>
 339RCPT TO:<two@example.com>
 340From: Example <from@example.com>
 341To: to@example.com
 342Cc: cc@example.com,
 343        A <author@example.com>,
 344        One <one@example.com>,
 345        two@example.com
 346Subject: [PATCH 1/1] Second.
 347Date: DATE-STRING
 348Message-Id: MESSAGE-ID-STRING
 349X-Mailer: X-MAILER-STRING
 350
 351Result: OK
 352EOF
 353"
 354
 355test_suppression () {
 356        git send-email \
 357                --dry-run \
 358                --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
 359                --from="Example <from@example.com>" \
 360                --to=to@example.com \
 361                --smtp-server relay.example.com \
 362                $patches |
 363        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 364                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 365                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 366                >actual-suppress-$1${2+"-$2"} &&
 367        test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
 368}
 369
 370test_expect_success $PREREQ 'sendemail.cc set' '
 371        git config sendemail.cc cc@example.com &&
 372        test_suppression sob
 373'
 374
 375test_expect_success $PREREQ 'setup expect' "
 376cat >expected-suppress-sob <<\EOF
 3770001-Second.patch
 378(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 379(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 380(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 381Dry-OK. Log says:
 382Server: relay.example.com
 383MAIL FROM:<from@example.com>
 384RCPT TO:<to@example.com>
 385RCPT TO:<author@example.com>
 386RCPT TO:<one@example.com>
 387RCPT TO:<two@example.com>
 388From: Example <from@example.com>
 389To: to@example.com
 390Cc: A <author@example.com>,
 391        One <one@example.com>,
 392        two@example.com
 393Subject: [PATCH 1/1] Second.
 394Date: DATE-STRING
 395Message-Id: MESSAGE-ID-STRING
 396X-Mailer: X-MAILER-STRING
 397
 398Result: OK
 399EOF
 400"
 401
 402test_expect_success $PREREQ 'sendemail.cc unset' '
 403        git config --unset sendemail.cc &&
 404        test_suppression sob
 405'
 406
 407test_expect_success $PREREQ 'setup expect' "
 408cat >expected-suppress-cccmd <<\EOF
 4090001-Second.patch
 410(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 411(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 412(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 413(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 414Dry-OK. Log says:
 415Server: relay.example.com
 416MAIL FROM:<from@example.com>
 417RCPT TO:<to@example.com>
 418RCPT TO:<author@example.com>
 419RCPT TO:<one@example.com>
 420RCPT TO:<two@example.com>
 421RCPT TO:<committer@example.com>
 422From: Example <from@example.com>
 423To: to@example.com
 424Cc: A <author@example.com>,
 425        One <one@example.com>,
 426        two@example.com,
 427        C O Mitter <committer@example.com>
 428Subject: [PATCH 1/1] Second.
 429Date: DATE-STRING
 430Message-Id: MESSAGE-ID-STRING
 431X-Mailer: X-MAILER-STRING
 432
 433Result: OK
 434EOF
 435"
 436
 437test_expect_success $PREREQ 'sendemail.cccmd' '
 438        echo echo cc-cmd@example.com > cccmd &&
 439        chmod +x cccmd &&
 440        git config sendemail.cccmd ./cccmd &&
 441        test_suppression cccmd
 442'
 443
 444test_expect_success $PREREQ 'setup expect' '
 445cat >expected-suppress-all <<\EOF
 4460001-Second.patch
 447Dry-OK. Log says:
 448Server: relay.example.com
 449MAIL FROM:<from@example.com>
 450RCPT TO:<to@example.com>
 451From: Example <from@example.com>
 452To: to@example.com
 453Subject: [PATCH 1/1] Second.
 454Date: DATE-STRING
 455Message-Id: MESSAGE-ID-STRING
 456X-Mailer: X-MAILER-STRING
 457
 458Result: OK
 459EOF
 460'
 461
 462test_expect_success $PREREQ '--suppress-cc=all' '
 463        test_suppression all
 464'
 465
 466test_expect_success $PREREQ 'setup expect' "
 467cat >expected-suppress-body <<\EOF
 4680001-Second.patch
 469(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 470(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 471(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 472(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
 473Dry-OK. Log says:
 474Server: relay.example.com
 475MAIL FROM:<from@example.com>
 476RCPT TO:<to@example.com>
 477RCPT TO:<author@example.com>
 478RCPT TO:<one@example.com>
 479RCPT TO:<two@example.com>
 480RCPT TO:<cc-cmd@example.com>
 481From: Example <from@example.com>
 482To: to@example.com
 483Cc: A <author@example.com>,
 484        One <one@example.com>,
 485        two@example.com,
 486        cc-cmd@example.com
 487Subject: [PATCH 1/1] Second.
 488Date: DATE-STRING
 489Message-Id: MESSAGE-ID-STRING
 490X-Mailer: X-MAILER-STRING
 491
 492Result: OK
 493EOF
 494"
 495
 496test_expect_success $PREREQ '--suppress-cc=body' '
 497        test_suppression body
 498'
 499
 500test_expect_success $PREREQ 'setup expect' "
 501cat >expected-suppress-body-cccmd <<\EOF
 5020001-Second.patch
 503(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 504(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 505(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 506Dry-OK. Log says:
 507Server: relay.example.com
 508MAIL FROM:<from@example.com>
 509RCPT TO:<to@example.com>
 510RCPT TO:<author@example.com>
 511RCPT TO:<one@example.com>
 512RCPT TO:<two@example.com>
 513From: Example <from@example.com>
 514To: to@example.com
 515Cc: A <author@example.com>,
 516        One <one@example.com>,
 517        two@example.com
 518Subject: [PATCH 1/1] Second.
 519Date: DATE-STRING
 520Message-Id: MESSAGE-ID-STRING
 521X-Mailer: X-MAILER-STRING
 522
 523Result: OK
 524EOF
 525"
 526
 527test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
 528        test_suppression body cccmd
 529'
 530
 531test_expect_success $PREREQ 'setup expect' "
 532cat >expected-suppress-sob <<\EOF
 5330001-Second.patch
 534(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 535(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 536(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 537Dry-OK. Log says:
 538Server: relay.example.com
 539MAIL FROM:<from@example.com>
 540RCPT TO:<to@example.com>
 541RCPT TO:<author@example.com>
 542RCPT TO:<one@example.com>
 543RCPT TO:<two@example.com>
 544From: Example <from@example.com>
 545To: to@example.com
 546Cc: A <author@example.com>,
 547        One <one@example.com>,
 548        two@example.com
 549Subject: [PATCH 1/1] Second.
 550Date: DATE-STRING
 551Message-Id: MESSAGE-ID-STRING
 552X-Mailer: X-MAILER-STRING
 553
 554Result: OK
 555EOF
 556"
 557
 558test_expect_success $PREREQ '--suppress-cc=sob' '
 559        git config --unset sendemail.cccmd
 560        test_suppression sob
 561'
 562
 563test_expect_success $PREREQ 'setup expect' "
 564cat >expected-suppress-bodycc <<\EOF
 5650001-Second.patch
 566(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 567(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 568(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 569(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 570Dry-OK. Log says:
 571Server: relay.example.com
 572MAIL FROM:<from@example.com>
 573RCPT TO:<to@example.com>
 574RCPT TO:<author@example.com>
 575RCPT TO:<one@example.com>
 576RCPT TO:<two@example.com>
 577RCPT TO:<committer@example.com>
 578From: Example <from@example.com>
 579To: to@example.com
 580Cc: A <author@example.com>,
 581        One <one@example.com>,
 582        two@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"
 592
 593test_expect_success $PREREQ '--suppress-cc=bodycc' '
 594        test_suppression bodycc
 595'
 596
 597test_expect_success $PREREQ 'setup expect' "
 598cat >expected-suppress-cc <<\EOF
 5990001-Second.patch
 600(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 601(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 602Dry-OK. Log says:
 603Server: relay.example.com
 604MAIL FROM:<from@example.com>
 605RCPT TO:<to@example.com>
 606RCPT TO:<author@example.com>
 607RCPT TO:<committer@example.com>
 608From: Example <from@example.com>
 609To: to@example.com
 610Cc: A <author@example.com>,
 611        C O Mitter <committer@example.com>
 612Subject: [PATCH 1/1] Second.
 613Date: DATE-STRING
 614Message-Id: MESSAGE-ID-STRING
 615X-Mailer: X-MAILER-STRING
 616
 617Result: OK
 618EOF
 619"
 620
 621test_expect_success $PREREQ '--suppress-cc=cc' '
 622        test_suppression cc
 623'
 624
 625test_confirm () {
 626        echo y | \
 627                GIT_SEND_EMAIL_NOTTY=1 \
 628                git send-email \
 629                --from="Example <nobody@example.com>" \
 630                --to=nobody@example.com \
 631                --smtp-server="$(pwd)/fake.sendmail" \
 632                $@ $patches > stdout &&
 633        grep "Send this email" stdout
 634}
 635
 636test_expect_success $PREREQ '--confirm=always' '
 637        test_confirm --confirm=always --suppress-cc=all
 638'
 639
 640test_expect_success $PREREQ '--confirm=auto' '
 641        test_confirm --confirm=auto
 642'
 643
 644test_expect_success $PREREQ '--confirm=cc' '
 645        test_confirm --confirm=cc
 646'
 647
 648test_expect_success $PREREQ '--confirm=compose' '
 649        test_confirm --confirm=compose --compose
 650'
 651
 652test_expect_success $PREREQ 'confirm by default (due to cc)' '
 653        CONFIRM=$(git config --get sendemail.confirm) &&
 654        git config --unset sendemail.confirm &&
 655        test_confirm
 656        ret="$?"
 657        git config sendemail.confirm ${CONFIRM:-never}
 658        test $ret = "0"
 659'
 660
 661test_expect_success $PREREQ 'confirm by default (due to --compose)' '
 662        CONFIRM=$(git config --get sendemail.confirm) &&
 663        git config --unset sendemail.confirm &&
 664        test_confirm --suppress-cc=all --compose
 665        ret="$?"
 666        git config sendemail.confirm ${CONFIRM:-never}
 667        test $ret = "0"
 668'
 669
 670test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
 671        CONFIRM=$(git config --get sendemail.confirm) &&
 672        git config --unset sendemail.confirm &&
 673        rm -fr outdir &&
 674        git format-patch -2 -o outdir &&
 675        GIT_SEND_EMAIL_NOTTY=1 \
 676                git send-email \
 677                        --from="Example <nobody@example.com>" \
 678                        --to=nobody@example.com \
 679                        --smtp-server="$(pwd)/fake.sendmail" \
 680                        outdir/*.patch < /dev/null
 681        ret="$?"
 682        git config sendemail.confirm ${CONFIRM:-never}
 683        test $ret = "0"
 684'
 685
 686test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
 687        CONFIRM=$(git config --get sendemail.confirm) &&
 688        git config sendemail.confirm auto &&
 689        GIT_SEND_EMAIL_NOTTY=1 &&
 690        export GIT_SEND_EMAIL_NOTTY &&
 691                test_must_fail git send-email \
 692                        --from="Example <nobody@example.com>" \
 693                        --to=nobody@example.com \
 694                        --smtp-server="$(pwd)/fake.sendmail" \
 695                        $patches < /dev/null
 696        ret="$?"
 697        git config sendemail.confirm ${CONFIRM:-never}
 698        test $ret = "0"
 699'
 700
 701test_expect_success $PREREQ 'confirm doesnt loop forever' '
 702        CONFIRM=$(git config --get sendemail.confirm) &&
 703        git config sendemail.confirm auto &&
 704        GIT_SEND_EMAIL_NOTTY=1 &&
 705        export GIT_SEND_EMAIL_NOTTY &&
 706                yes "bogus" | test_must_fail git send-email \
 707                        --from="Example <nobody@example.com>" \
 708                        --to=nobody@example.com \
 709                        --smtp-server="$(pwd)/fake.sendmail" \
 710                        $patches
 711        ret="$?"
 712        git config sendemail.confirm ${CONFIRM:-never}
 713        test $ret = "0"
 714'
 715
 716test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
 717        clean_fake_sendmail &&
 718        rm -fr outdir &&
 719        git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
 720        git send-email \
 721        --from="Example <nobody@example.com>" \
 722        --to=nobody@example.com \
 723        --smtp-server="$(pwd)/fake.sendmail" \
 724        outdir/*.patch &&
 725        grep "^ " msgtxt1 |
 726        grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
 727'
 728
 729test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
 730        clean_fake_sendmail &&
 731        (echo "#!$SHELL_PATH" &&
 732         echo "echo utf8 body: àéìöú >>\"\$1\""
 733        ) >fake-editor-utf8 &&
 734        chmod +x fake-editor-utf8 &&
 735          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 736          git send-email \
 737          --compose --subject foo \
 738          --from="Example <nobody@example.com>" \
 739          --to=nobody@example.com \
 740          --smtp-server="$(pwd)/fake.sendmail" \
 741          $patches &&
 742        grep "^utf8 body" msgtxt1 &&
 743        grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 744'
 745
 746test_expect_success $PREREQ '--compose respects user mime type' '
 747        clean_fake_sendmail &&
 748        (echo "#!$SHELL_PATH" &&
 749         echo "(echo MIME-Version: 1.0"
 750         echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
 751         echo " echo Content-Transfer-Encoding: 8bit"
 752         echo " echo Subject: foo"
 753         echo " echo "
 754         echo " echo utf8 body: àéìöú) >\"\$1\""
 755        ) >fake-editor-utf8-mime &&
 756        chmod +x fake-editor-utf8-mime &&
 757          GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
 758          git send-email \
 759          --compose --subject foo \
 760          --from="Example <nobody@example.com>" \
 761          --to=nobody@example.com \
 762          --smtp-server="$(pwd)/fake.sendmail" \
 763          $patches &&
 764        grep "^utf8 body" msgtxt1 &&
 765        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
 766        ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 767'
 768
 769test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
 770        clean_fake_sendmail &&
 771          GIT_EDITOR="\"$(pwd)/fake-editor\"" \
 772          git send-email \
 773          --compose --subject utf8-sübjëct \
 774          --from="Example <nobody@example.com>" \
 775          --to=nobody@example.com \
 776          --smtp-server="$(pwd)/fake.sendmail" \
 777          $patches &&
 778        grep "^fake edit" msgtxt1 &&
 779        grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
 780'
 781
 782test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
 783        echo master > master &&
 784        git add master &&
 785        git commit -m"add master" &&
 786        test_must_fail git send-email --dry-run master 2>errors &&
 787        grep disambiguate errors
 788'
 789
 790test_expect_success $PREREQ 'feed two files' '
 791        rm -fr outdir &&
 792        git format-patch -2 -o outdir &&
 793        git send-email \
 794        --dry-run \
 795        --from="Example <nobody@example.com>" \
 796        --to=nobody@example.com \
 797        outdir/000?-*.patch 2>errors >out &&
 798        grep "^Subject: " out >subjects &&
 799        test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
 800        test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
 801'
 802
 803test_expect_success $PREREQ 'in-reply-to but no threading' '
 804        git send-email \
 805                --dry-run \
 806                --from="Example <nobody@example.com>" \
 807                --to=nobody@example.com \
 808                --in-reply-to="<in-reply-id@example.com>" \
 809                --nothread \
 810                $patches |
 811        grep "In-Reply-To: <in-reply-id@example.com>"
 812'
 813
 814test_expect_success $PREREQ 'no in-reply-to and no threading' '
 815        git send-email \
 816                --dry-run \
 817                --from="Example <nobody@example.com>" \
 818                --to=nobody@example.com \
 819                --nothread \
 820                $patches $patches >stdout &&
 821        ! grep "In-Reply-To: " stdout
 822'
 823
 824test_expect_success $PREREQ 'threading but no chain-reply-to' '
 825        git send-email \
 826                --dry-run \
 827                --from="Example <nobody@example.com>" \
 828                --to=nobody@example.com \
 829                --thread \
 830                --nochain-reply-to \
 831                $patches $patches >stdout &&
 832        grep "In-Reply-To: " stdout
 833'
 834
 835test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
 836        git send-email \
 837        --dry-run \
 838        --from="Example <nobody@example.com>" \
 839        --to=nobody@example.com \
 840        outdir/000?-*.patch 2>errors >out &&
 841        grep "no-chain-reply-to" errors
 842'
 843
 844test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
 845        git send-email \
 846        --dry-run \
 847        --from="Example <nobody@example.com>" \
 848        --to=nobody@example.com \
 849        --chain-reply-to \
 850        outdir/000?-*.patch 2>errors >out &&
 851        ! grep "no-chain-reply-to" errors
 852'
 853
 854test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
 855        git send-email \
 856        --dry-run \
 857        --from="Example <nobody@example.com>" \
 858        --to=nobody@example.com \
 859        --nochain-reply-to \
 860        outdir/000?-*.patch 2>errors >out &&
 861        ! grep "no-chain-reply-to" errors
 862'
 863
 864test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
 865        git config sendemail.chainreplyto false &&
 866        git send-email \
 867        --dry-run \
 868        --from="Example <nobody@example.com>" \
 869        --to=nobody@example.com \
 870        outdir/000?-*.patch 2>errors >out &&
 871        ! grep "no-chain-reply-to" errors
 872'
 873
 874test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
 875        git config sendemail.chainreplyto true &&
 876        git send-email \
 877        --dry-run \
 878        --from="Example <nobody@example.com>" \
 879        --to=nobody@example.com \
 880        outdir/000?-*.patch 2>errors >out &&
 881        ! grep "no-chain-reply-to" errors
 882'
 883
 884test_expect_success $PREREQ 'sendemail.to works' '
 885        git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
 886        git send-email \
 887                --dry-run \
 888                --from="Example <nobody@example.com>" \
 889                $patches $patches >stdout &&
 890        grep "To: Somebody <somebody@ex.com>" stdout
 891'
 892
 893test_expect_success $PREREQ '--no-to overrides sendemail.to' '
 894        git send-email \
 895                --dry-run \
 896                --from="Example <nobody@example.com>" \
 897                --no-to \
 898                --to=nobody@example.com \
 899                $patches $patches >stdout &&
 900        grep "To: nobody@example.com" stdout &&
 901        ! grep "To: Somebody <somebody@ex.com>" stdout
 902'
 903
 904test_expect_success $PREREQ 'sendemail.cc works' '
 905        git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
 906        git send-email \
 907                --dry-run \
 908                --from="Example <nobody@example.com>" \
 909                --to=nobody@example.com \
 910                $patches $patches >stdout &&
 911        grep "Cc: Somebody <somebody@ex.com>" stdout
 912'
 913
 914test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
 915        git send-email \
 916                --dry-run \
 917                --from="Example <nobody@example.com>" \
 918                --no-cc \
 919                --cc=bodies@example.com \
 920                --to=nobody@example.com \
 921                $patches $patches >stdout &&
 922        grep "Cc: bodies@example.com" stdout &&
 923        ! grep "Cc: Somebody <somebody@ex.com>" stdout
 924'
 925
 926test_expect_success $PREREQ 'sendemail.bcc works' '
 927        git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
 928        git send-email \
 929                --dry-run \
 930                --from="Example <nobody@example.com>" \
 931                --to=nobody@example.com \
 932                --smtp-server relay.example.com \
 933                $patches $patches >stdout &&
 934        grep "RCPT TO:<other@ex.com>" stdout
 935'
 936
 937test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
 938        git send-email \
 939                --dry-run \
 940                --from="Example <nobody@example.com>" \
 941                --no-bcc \
 942                --bcc=bodies@example.com \
 943                --to=nobody@example.com \
 944                --smtp-server relay.example.com \
 945                $patches $patches >stdout &&
 946        grep "RCPT TO:<bodies@example.com>" stdout &&
 947        ! grep "RCPT TO:<other@ex.com>" stdout
 948'
 949
 950test_expect_success $PREREQ 'setup expect' '
 951cat >email-using-8bit <<EOF
 952From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
 953Message-Id: <bogus-message-id@example.com>
 954From: author@example.com
 955Date: Sat, 12 Jun 2010 15:53:58 +0200
 956Subject: subject goes here
 957
 958Dieser deutsche Text enthält einen Umlaut!
 959EOF
 960'
 961
 962test_expect_success $PREREQ 'setup expect' '
 963cat >content-type-decl <<EOF
 964MIME-Version: 1.0
 965Content-Type: text/plain; charset=UTF-8
 966Content-Transfer-Encoding: 8bit
 967EOF
 968'
 969
 970test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
 971        clean_fake_sendmail &&
 972        echo |
 973        git send-email --from=author@example.com --to=nobody@example.com \
 974                        --smtp-server="$(pwd)/fake.sendmail" \
 975                        email-using-8bit >stdout &&
 976        grep "do not declare a Content-Transfer-Encoding" stdout &&
 977        grep email-using-8bit stdout &&
 978        grep "Which 8bit encoding" stdout &&
 979        egrep "Content|MIME" msgtxt1 >actual &&
 980        test_cmp actual content-type-decl
 981'
 982
 983test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
 984        clean_fake_sendmail &&
 985        git config sendemail.assume8bitEncoding UTF-8 &&
 986        echo bogus |
 987        git send-email --from=author@example.com --to=nobody@example.com \
 988                        --smtp-server="$(pwd)/fake.sendmail" \
 989                        email-using-8bit >stdout &&
 990        egrep "Content|MIME" msgtxt1 >actual &&
 991        test_cmp actual content-type-decl
 992'
 993
 994test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
 995        clean_fake_sendmail &&
 996        git config sendemail.assume8bitEncoding "bogus too" &&
 997        echo bogus |
 998        git send-email --from=author@example.com --to=nobody@example.com \
 999                        --smtp-server="$(pwd)/fake.sendmail" \
1000                        --8bit-encoding=UTF-8 \
1001                        email-using-8bit >stdout &&
1002        egrep "Content|MIME" msgtxt1 >actual &&
1003        test_cmp actual content-type-decl
1004'
1005
1006test_expect_success $PREREQ 'setup expect' '
1007cat >email-using-8bit <<EOF
1008From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1009Message-Id: <bogus-message-id@example.com>
1010From: author@example.com
1011Date: Sat, 12 Jun 2010 15:53:58 +0200
1012Subject: Dieser Betreff enthält auch einen Umlaut!
1013
1014Nothing to see here.
1015EOF
1016'
1017
1018test_expect_success $PREREQ 'setup expect' '
1019cat >expected <<EOF
1020Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1021EOF
1022'
1023
1024test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1025        clean_fake_sendmail &&
1026        echo bogus |
1027        git send-email --from=author@example.com --to=nobody@example.com \
1028                        --smtp-server="$(pwd)/fake.sendmail" \
1029                        --8bit-encoding=UTF-8 \
1030                        email-using-8bit >stdout &&
1031        grep "Subject" msgtxt1 >actual &&
1032        test_cmp expected actual
1033'
1034
1035test_done