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 "#!/bin/sh"
17 echo shift
18 echo for a
19 echo do
20 echo " echo \"!\$a!\""
21 echo "done >commandline"
22 echo "cat > msgtxt"
23 ) >fake.sendmail &&
24 chmod +x ./fake.sendmail &&
25 git add fake.sendmail &&
26 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
27
28test_expect_success 'Extract patches' '
29 patches=`git format-patch -n HEAD^1`
30'
31
32test_expect_success 'Send patches' '
33 git send-email --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
34'
35
36cat >expected <<\EOF
37!nobody@example.com!
38!author@example.com!
39EOF
40test_expect_success \
41 'Verify commandline' \
42 'diff commandline expected'
43
44cat >expected-show-all-headers <<\EOF
450001-Second.patch
46(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
47Dry-OK. Log says:
48Server: relay.example.com
49MAIL FROM:<from@example.com>
50RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<bcc@example.com>
51From: Example <from@example.com>
52To: to@example.com
53Cc: cc@example.com, A <author@example.com>
54Subject: [PATCH 1/1] Second.
55Date: DATE-STRING
56Message-Id: MESSAGE-ID-STRING
57X-Mailer: X-MAILER-STRING
58In-Reply-To: <unique-message-id@example.com>
59References: <unique-message-id@example.com>
60
61Result: OK
62EOF
63
64test_expect_success 'Show all headers' '
65 git send-email \
66 --dry-run \
67 --from="Example <from@example.com>" \
68 --to=to@example.com \
69 --cc=cc@example.com \
70 --bcc=bcc@example.com \
71 --in-reply-to="<unique-message-id@example.com>" \
72 --smtp-server relay.example.com \
73 $patches |
74 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
75 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
76 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
77 >actual-show-all-headers &&
78 diff -u expected-show-all-headers actual-show-all-headers
79'
80
81z8=zzzzzzzz
82z64=$z8$z8$z8$z8$z8$z8$z8$z8
83z512=$z64$z64$z64$z64$z64$z64$z64$z64
84test_expect_success 'reject long lines' '
85 rm -f commandline &&
86 cp $patches longline.patch &&
87 echo $z512$z512 >>longline.patch &&
88 ! git send-email \
89 --from="Example <nobody@example.com>" \
90 --to=nobody@example.com \
91 --smtp-server="$(pwd)/fake.sendmail" \
92 $patches longline.patch \
93 2>errors &&
94 grep longline.patch errors
95'
96
97test_expect_success 'no patch was sent' '
98 ! test -e commandline
99'
100
101test_expect_success 'allow long lines with --no-validate' '
102 git send-email \
103 --from="Example <nobody@example.com>" \
104 --to=nobody@example.com \
105 --smtp-server="$(pwd)/fake.sendmail" \
106 --no-validate \
107 $patches longline.patch \
108 2>errors
109'
110
111test_done