3 test_description
='Test import from emails'
8 'Initialize the StGit repository' \
10 cp "$TEST_DIRECTORY"/t1800/foo.txt . &&
12 git commit -a -m "initial version" &&
17 'Apply a patch from an 8bit-encoded e-mail' \
19 stg import -m "$TEST_DIRECTORY"/t1801/email-8bit &&
20 [ $(git cat-file -p $(stg id) \
21 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
22 [ $(git cat-file -p $(stg id) \
23 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
28 'Apply a patch from an 8bit-encoded e-mail url' \
30 stg import -u -m "file://$TEST_DIRECTORY"/t1801/email-8bit &&
31 [ $(git cat-file -p $(stg id) \
32 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
33 [ $(git cat-file -p $(stg id) \
34 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
39 'Apply a patch from an 8bit-encoded e-mail with CRLF endings' \
41 cat "$TEST_DIRECTORY"/t1801/email-8bit | append_cr |
43 [ $(git cat-file -p $(stg id) \
44 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
45 [ $(git cat-file -p $(stg id) \
46 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
51 'Apply e-mail with CRLF endings and --keep-cr' \
53 stg new -m foo-with-crlf &&
54 cat foo.txt | append_cr > foo-crlf.txt &&
55 mv foo-crlf.txt foo.txt &&
57 cat "$TEST_DIRECTORY"/t1801/email-8bit | append_cr |
58 stg import -m --keep-cr &&
59 [ $(git cat-file -p $(stg id) \
60 | grep -c "tree ecb72e62394189fd2a095047076dab1ae473ed4d") = 1 ] &&
61 [ $(git cat-file -p $(stg id) \
62 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
67 'Apply a patch from latin1-encoded email specifying utf-8 charset' \
69 iconv -f UTF-8 -t LATIN1 "$TEST_DIRECTORY"/t1801/email-8bit > email-latin1 &&
70 stg import -m email-latin1 &&
71 [ $(git cat-file -p $(stg id) \
72 | grep -c "tree cf0f9884fdb30bca14d2411e1711f6ae413c9213") = 1 ] &&
73 [ $(git cat-file -p $(stg id) \
74 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
79 'Apply a patch from email with quoted "From" header' \
81 stg import -m "$TEST_DIRECTORY"/t1801/email-quoted-from &&
82 [ $(git cat-file -p $(stg id) \
83 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
84 [ $(git cat-file -p $(stg id) \
85 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
90 'Apply a patch from a QP-encoded e-mail' \
92 stg import -m "$TEST_DIRECTORY"/t1801/email-qp &&
93 [ $(git cat-file -p $(stg id) \
94 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
95 [ $(git cat-file -p $(stg id) \
96 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
100 test_expect_success \
101 'Apply several patches from an mbox file' \
103 stg import -M "$TEST_DIRECTORY"/t1801/email-mbox &&
104 [ $(git cat-file -p $(stg id change-1) \
105 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
106 [ $(git cat-file -p $(stg id change-1) \
107 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
108 [ $(git cat-file -p $(stg id change-2) \
109 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
110 [ $(git cat-file -p $(stg id change-2) \
111 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
112 [ $(git cat-file -p $(stg id change-3-colon) \
113 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
114 [ $(git cat-file -p $(stg id change-3-colon) \
115 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
119 test_expect_success \
120 'Apply several patches from an mbox url' \
122 stg import -u -M "file://$TEST_DIRECTORY"/t1801/email-mbox &&
123 [ $(git cat-file -p $(stg id change-1) \
124 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
125 [ $(git cat-file -p $(stg id change-1) \
126 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
127 [ $(git cat-file -p $(stg id change-2) \
128 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
129 [ $(git cat-file -p $(stg id change-2) \
130 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
131 [ $(git cat-file -p $(stg id change-3-colon) \
132 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
133 [ $(git cat-file -p $(stg id change-3-colon) \
134 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
138 test_expect_success \
139 'Import patches from mbox with duplicate subjects' \
141 stg import -M "$TEST_DIRECTORY"/t1801/email-mbox-same-subject &&
142 test "$(echo $(stg series --noprefix --applied))" = "my-patch my-patch-1 my-patch-2" &&
146 test_expect_success \
147 'Apply several patches from an mbox file from stdin' \
149 cat "$TEST_DIRECTORY"/t1801/email-mbox | stg import -M &&
150 [ $(git cat-file -p $(stg id change-1) \
151 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
152 [ $(git cat-file -p $(stg id change-1) \
153 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
154 [ $(git cat-file -p $(stg id change-2) \
155 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
156 [ $(git cat-file -p $(stg id change-2) \
157 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
158 [ $(git cat-file -p $(stg id change-3-colon) \
159 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
160 [ $(git cat-file -p $(stg id change-3-colon) \
161 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
165 test_expect_success \
166 'Apply several patches from an mbox file with CRLF line endings' \
168 cat "$TEST_DIRECTORY"/t1801/email-mbox | append_cr |
170 [ $(git cat-file -p $(stg id change-1) \
171 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
172 [ $(git cat-file -p $(stg id change-1) \
173 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
174 [ $(git cat-file -p $(stg id change-2) \
175 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
176 [ $(git cat-file -p $(stg id change-2) \
177 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
178 [ $(git cat-file -p $(stg id change-3-colon) \
179 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
180 [ $(git cat-file -p $(stg id change-3-colon) \
181 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
185 test_expect_success \
186 'Import from git format-patch output' '
188 test_create_repo upstream &&
190 echo "something" > some.txt &&
192 git commit -m "Add something"
196 git clone upstream downstream
198 echo "else µ" >> some.txt &&
199 git commit -a --author "Éd <ed@example.com>" -m "something else" &&
200 git format-patch --stdout HEAD~1 > ../downstream.mbox
204 stg import --mbox ../downstream.mbox &&
205 stg top | grep "something-else" &&
206 grep "else µ" some.txt