t / t9001-send-email.shon commit GIT 1.6.2.2 (3346330)
   1#!/bin/sh
   2
   3test_description='git send-email'
   4. ./test-lib.sh
   5
   6PROG='git send-email'
   7test_expect_success \
   8    'prepare reference tree' \
   9    'echo "1A quick brown fox jumps over the" >file &&
  10     echo "lazy dog" >>file &&
  11     git add file &&
  12     GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
  13
  14test_expect_success \
  15    'Setup helper tool' \
  16    '(echo "#!$SHELL_PATH"
  17      echo shift
  18      echo output=1
  19      echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
  20      echo for a
  21      echo do
  22      echo "  echo \"!\$a!\""
  23      echo "done >commandline\$output"
  24      echo "cat > msgtxt\$output"
  25      ) >fake.sendmail &&
  26     chmod +x ./fake.sendmail &&
  27     git add fake.sendmail &&
  28     GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
  29
  30clean_fake_sendmail() {
  31        rm -f commandline* msgtxt*
  32}
  33
  34test_expect_success 'Extract patches' '
  35    patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
  36'
  37
  38test_expect_success 'Send patches' '
  39     git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
  40'
  41
  42cat >expected <<\EOF
  43!nobody@example.com!
  44!author@example.com!
  45!one@example.com!
  46!two@example.com!
  47EOF
  48test_expect_success \
  49    'Verify commandline' \
  50    'diff commandline1 expected'
  51
  52cat >expected-show-all-headers <<\EOF
  530001-Second.patch
  54(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
  55(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
  56(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
  57Dry-OK. Log says:
  58Server: relay.example.com
  59MAIL FROM:<from@example.com>
  60RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<bcc@example.com>
  61From: Example <from@example.com>
  62To: to@example.com
  63Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
  64Subject: [PATCH 1/1] Second.
  65Date: DATE-STRING
  66Message-Id: MESSAGE-ID-STRING
  67X-Mailer: X-MAILER-STRING
  68In-Reply-To: <unique-message-id@example.com>
  69References: <unique-message-id@example.com>
  70
  71Result: OK
  72EOF
  73
  74test_expect_success 'Show all headers' '
  75        git send-email \
  76                --dry-run \
  77                --suppress-cc=sob \
  78                --from="Example <from@example.com>" \
  79                --to=to@example.com \
  80                --cc=cc@example.com \
  81                --bcc=bcc@example.com \
  82                --in-reply-to="<unique-message-id@example.com>" \
  83                --smtp-server relay.example.com \
  84                $patches |
  85        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
  86                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
  87                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
  88                >actual-show-all-headers &&
  89        test_cmp expected-show-all-headers actual-show-all-headers
  90'
  91
  92z8=zzzzzzzz
  93z64=$z8$z8$z8$z8$z8$z8$z8$z8
  94z512=$z64$z64$z64$z64$z64$z64$z64$z64
  95test_expect_success 'reject long lines' '
  96        clean_fake_sendmail &&
  97        cp $patches longline.patch &&
  98        echo $z512$z512 >>longline.patch &&
  99        test_must_fail git send-email \
 100                --from="Example <nobody@example.com>" \
 101                --to=nobody@example.com \
 102                --smtp-server="$(pwd)/fake.sendmail" \
 103                $patches longline.patch \
 104                2>errors &&
 105        grep longline.patch errors
 106'
 107
 108test_expect_success 'no patch was sent' '
 109        ! test -e commandline1
 110'
 111
 112test_expect_success 'Author From: in message body' '
 113        clean_fake_sendmail &&
 114        git send-email \
 115                --from="Example <nobody@example.com>" \
 116                --to=nobody@example.com \
 117                --smtp-server="$(pwd)/fake.sendmail" \
 118                $patches &&
 119        sed "1,/^$/d" < msgtxt1 > msgbody1
 120        grep "From: A <author@example.com>" msgbody1
 121'
 122
 123test_expect_success 'Author From: not in message body' '
 124        clean_fake_sendmail &&
 125        git send-email \
 126                --from="A <author@example.com>" \
 127                --to=nobody@example.com \
 128                --smtp-server="$(pwd)/fake.sendmail" \
 129                $patches &&
 130        sed "1,/^$/d" < msgtxt1 > msgbody1
 131        ! grep "From: A <author@example.com>" msgbody1
 132'
 133
 134test_expect_success 'allow long lines with --no-validate' '
 135        git send-email \
 136                --from="Example <nobody@example.com>" \
 137                --to=nobody@example.com \
 138                --smtp-server="$(pwd)/fake.sendmail" \
 139                --novalidate \
 140                $patches longline.patch \
 141                2>errors
 142'
 143
 144test_expect_success 'Invalid In-Reply-To' '
 145        clean_fake_sendmail &&
 146        git send-email \
 147                --from="Example <nobody@example.com>" \
 148                --to=nobody@example.com \
 149                --in-reply-to=" " \
 150                --smtp-server="$(pwd)/fake.sendmail" \
 151                $patches
 152                2>errors
 153        ! grep "^In-Reply-To: < *>" msgtxt1
 154'
 155
 156test_expect_success 'Valid In-Reply-To when prompting' '
 157        clean_fake_sendmail &&
 158        (echo "From Example <from@example.com>"
 159         echo "To Example <to@example.com>"
 160         echo ""
 161        ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
 162                --smtp-server="$(pwd)/fake.sendmail" \
 163                $patches 2>errors &&
 164        ! grep "^In-Reply-To: < *>" msgtxt1
 165'
 166
 167test_expect_success 'setup fake editor' '
 168        (echo "#!$SHELL_PATH" &&
 169         echo "echo fake edit >>\"\$1\""
 170        ) >fake-editor &&
 171        chmod +x fake-editor
 172'
 173
 174test_set_editor "$(pwd)/fake-editor"
 175
 176test_expect_success '--compose works' '
 177        clean_fake_sendmail &&
 178        echo y | \
 179                GIT_SEND_EMAIL_NOTTY=1 \
 180                git send-email \
 181                --compose --subject foo \
 182                --from="Example <nobody@example.com>" \
 183                --to=nobody@example.com \
 184                --smtp-server="$(pwd)/fake.sendmail" \
 185                $patches \
 186                2>errors
 187'
 188
 189test_expect_success 'first message is compose text' '
 190        grep "^fake edit" msgtxt1
 191'
 192
 193test_expect_success 'second message is patch' '
 194        grep "Subject:.*Second" msgtxt2
 195'
 196
 197cat >expected-suppress-sob <<\EOF
 1980001-Second.patch
 199(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 200(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 201(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 202Dry-OK. Log says:
 203Server: relay.example.com
 204MAIL FROM:<from@example.com>
 205RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
 206From: Example <from@example.com>
 207To: to@example.com
 208Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
 209Subject: [PATCH 1/1] Second.
 210Date: DATE-STRING
 211Message-Id: MESSAGE-ID-STRING
 212X-Mailer: X-MAILER-STRING
 213
 214Result: OK
 215EOF
 216
 217test_suppression () {
 218        git send-email \
 219                --dry-run \
 220                --suppress-cc=$1 \
 221                --from="Example <from@example.com>" \
 222                --to=to@example.com \
 223                --smtp-server relay.example.com \
 224                $patches |
 225        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 226                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 227                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 228                >actual-suppress-$1 &&
 229        test_cmp expected-suppress-$1 actual-suppress-$1
 230}
 231
 232test_expect_success 'sendemail.cc set' '
 233        git config sendemail.cc cc@example.com &&
 234        test_suppression sob
 235'
 236
 237cat >expected-suppress-sob <<\EOF
 2380001-Second.patch
 239(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 240(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 241(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 242Dry-OK. Log says:
 243Server: relay.example.com
 244MAIL FROM:<from@example.com>
 245RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
 246From: Example <from@example.com>
 247To: to@example.com
 248Cc: A <author@example.com>, One <one@example.com>, two@example.com
 249Subject: [PATCH 1/1] Second.
 250Date: DATE-STRING
 251Message-Id: MESSAGE-ID-STRING
 252X-Mailer: X-MAILER-STRING
 253
 254Result: OK
 255EOF
 256
 257test_expect_success 'sendemail.cc unset' '
 258        git config --unset sendemail.cc &&
 259        test_suppression sob
 260'
 261
 262cat >expected-suppress-all <<\EOF
 2630001-Second.patch
 264Dry-OK. Log says:
 265Server: relay.example.com
 266MAIL FROM:<from@example.com>
 267RCPT TO:<to@example.com>
 268From: Example <from@example.com>
 269To: to@example.com
 270Subject: [PATCH 1/1] Second.
 271Date: DATE-STRING
 272Message-Id: MESSAGE-ID-STRING
 273X-Mailer: X-MAILER-STRING
 274
 275Result: OK
 276EOF
 277
 278test_expect_success '--suppress-cc=all' '
 279        test_suppression all
 280'
 281
 282cat >expected-suppress-body <<\EOF
 2830001-Second.patch
 284(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 285(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 286(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 287Dry-OK. Log says:
 288Server: relay.example.com
 289MAIL FROM:<from@example.com>
 290RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
 291From: Example <from@example.com>
 292To: to@example.com
 293Cc: A <author@example.com>, One <one@example.com>, two@example.com
 294Subject: [PATCH 1/1] Second.
 295Date: DATE-STRING
 296Message-Id: MESSAGE-ID-STRING
 297X-Mailer: X-MAILER-STRING
 298
 299Result: OK
 300EOF
 301
 302test_expect_success '--suppress-cc=body' '
 303        test_suppression body
 304'
 305
 306cat >expected-suppress-sob <<\EOF
 3070001-Second.patch
 308(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 309(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 310(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 311Dry-OK. Log says:
 312Server: relay.example.com
 313MAIL FROM:<from@example.com>
 314RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
 315From: Example <from@example.com>
 316To: to@example.com
 317Cc: A <author@example.com>, One <one@example.com>, two@example.com
 318Subject: [PATCH 1/1] Second.
 319Date: DATE-STRING
 320Message-Id: MESSAGE-ID-STRING
 321X-Mailer: X-MAILER-STRING
 322
 323Result: OK
 324EOF
 325
 326test_expect_success '--suppress-cc=sob' '
 327        test_suppression sob
 328'
 329
 330cat >expected-suppress-bodycc <<\EOF
 3310001-Second.patch
 332(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 333(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 334(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 335(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 336Dry-OK. Log says:
 337Server: relay.example.com
 338MAIL FROM:<from@example.com>
 339RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com>
 340From: Example <from@example.com>
 341To: to@example.com
 342Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com>
 343Subject: [PATCH 1/1] Second.
 344Date: DATE-STRING
 345Message-Id: MESSAGE-ID-STRING
 346X-Mailer: X-MAILER-STRING
 347
 348Result: OK
 349EOF
 350
 351test_expect_success '--suppress-cc=bodycc' '
 352        test_suppression bodycc
 353'
 354
 355cat >expected-suppress-cc <<\EOF
 3560001-Second.patch
 357(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 358(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 359Dry-OK. Log says:
 360Server: relay.example.com
 361MAIL FROM:<from@example.com>
 362RCPT TO:<to@example.com>,<author@example.com>,<committer@example.com>
 363From: Example <from@example.com>
 364To: to@example.com
 365Cc: A <author@example.com>, C O Mitter <committer@example.com>
 366Subject: [PATCH 1/1] Second.
 367Date: DATE-STRING
 368Message-Id: MESSAGE-ID-STRING
 369X-Mailer: X-MAILER-STRING
 370
 371Result: OK
 372EOF
 373
 374test_expect_success '--suppress-cc=cc' '
 375        test_suppression cc
 376'
 377
 378test_expect_success '--compose adds MIME for utf8 body' '
 379        clean_fake_sendmail &&
 380        (echo "#!$SHELL_PATH" &&
 381         echo "echo utf8 body: àéìöú >>\"\$1\""
 382        ) >fake-editor-utf8 &&
 383        chmod +x fake-editor-utf8 &&
 384        echo y | \
 385          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 386          GIT_SEND_EMAIL_NOTTY=1 \
 387          git send-email \
 388          --compose --subject foo \
 389          --from="Example <nobody@example.com>" \
 390          --to=nobody@example.com \
 391          --smtp-server="$(pwd)/fake.sendmail" \
 392          $patches &&
 393        grep "^utf8 body" msgtxt1 &&
 394        grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
 395'
 396
 397test_expect_success '--compose respects user mime type' '
 398        clean_fake_sendmail &&
 399        (echo "#!$SHELL_PATH" &&
 400         echo "(echo MIME-Version: 1.0"
 401         echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
 402         echo " echo Content-Transfer-Encoding: 8bit"
 403         echo " echo Subject: foo"
 404         echo " echo "
 405         echo " echo utf8 body: àéìöú) >\"\$1\""
 406        ) >fake-editor-utf8-mime &&
 407        chmod +x fake-editor-utf8-mime &&
 408        echo y | \
 409          GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
 410          GIT_SEND_EMAIL_NOTTY=1 \
 411          git send-email \
 412          --compose --subject foo \
 413          --from="Example <nobody@example.com>" \
 414          --to=nobody@example.com \
 415          --smtp-server="$(pwd)/fake.sendmail" \
 416          $patches &&
 417        grep "^utf8 body" msgtxt1 &&
 418        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
 419        ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
 420'
 421
 422test_expect_success '--compose adds MIME for utf8 subject' '
 423        clean_fake_sendmail &&
 424        echo y | \
 425          GIT_EDITOR="\"$(pwd)/fake-editor\"" \
 426          GIT_SEND_EMAIL_NOTTY=1 \
 427          git send-email \
 428          --compose --subject utf8-sübjëct \
 429          --from="Example <nobody@example.com>" \
 430          --to=nobody@example.com \
 431          --smtp-server="$(pwd)/fake.sendmail" \
 432          $patches &&
 433        grep "^fake edit" msgtxt1 &&
 434        grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
 435'
 436
 437test_expect_success 'detects ambiguous reference/file conflict' '
 438        echo master > master &&
 439        git add master &&
 440        git commit -m"add master" &&
 441        test_must_fail git send-email --dry-run master 2>errors &&
 442        grep disambiguate errors
 443'
 444
 445test_expect_success 'feed two files' '
 446        rm -fr outdir &&
 447        git format-patch -2 -o outdir &&
 448        GIT_SEND_EMAIL_NOTTY=1 git send-email \
 449        --dry-run \
 450        --from="Example <nobody@example.com>" \
 451        --to=nobody@example.com \
 452        outdir/000?-*.patch 2>errors >out &&
 453        grep "^Subject: " out >subjects &&
 454        test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
 455        test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
 456'
 457
 458test_expect_success 'in-reply-to but no threading' '
 459        git send-email \
 460                --dry-run \
 461                --from="Example <nobody@example.com>" \
 462                --to=nobody@example.com \
 463                --in-reply-to="<in-reply-id@example.com>" \
 464                --no-thread \
 465                $patches |
 466        grep "In-Reply-To: <in-reply-id@example.com>"
 467'
 468
 469test_done