Avoid importing invalid and duplicate patch names
[stgit.git] / t / t1801-import-email.sh
blob157036d21b9ef5c1761024102bd9195b52c47ef0
1 #!/bin/sh
3 test_description='Test import from emails'
5 . ./test-lib.sh
7 test_expect_success \
8 'Initialize the StGIT repository' \
10 cp "$TEST_DIRECTORY"/t1800/foo.txt . &&
11 stg add foo.txt &&
12 git commit -a -m "initial version" &&
13 stg init
16 test_expect_success \
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 ] &&
24 stg delete ..
27 test_expect_success \
28 'Apply a patch from an 8bit-encoded e-mail with CRLF endings' \
30 cat "$TEST_DIRECTORY"/t1801/email-8bit | append_cr |
31 stg import -m &&
32 [ $(git cat-file -p $(stg id) \
33 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
34 [ $(git cat-file -p $(stg id) \
35 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
36 stg delete ..
39 test_expect_success \
40 'Apply e-mail with CRLF endings and --keep-cr' \
42 stg new -m foo-with-crlf &&
43 cat foo.txt | append_cr > foo-crlf.txt &&
44 mv foo-crlf.txt foo.txt &&
45 stg refresh &&
46 cat "$TEST_DIRECTORY"/t1801/email-8bit | append_cr |
47 stg import -m --keep-cr &&
48 [ $(git cat-file -p $(stg id) \
49 | grep -c "tree ecb72e62394189fd2a095047076dab1ae473ed4d") = 1 ] &&
50 [ $(git cat-file -p $(stg id) \
51 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
52 stg delete ..
55 test_expect_success \
56 'Apply a patch from latin1-encoded email specifying utf-8 charset' \
58 iconv -f UTF-8 -t LATIN1 "$TEST_DIRECTORY"/t1801/email-8bit > email-latin1 &&
59 stg import -m email-latin1 &&
60 [ $(git cat-file -p $(stg id) \
61 | grep -c "tree cf0f9884fdb30bca14d2411e1711f6ae413c9213") = 1 ] &&
62 [ $(git cat-file -p $(stg id) \
63 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
64 stg delete ..
67 test_expect_success \
68 'Apply a patch from email with quoted "From" header' \
70 stg import -m "$TEST_DIRECTORY"/t1801/email-quoted-from &&
71 [ $(git cat-file -p $(stg id) \
72 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
73 [ $(git cat-file -p $(stg id) \
74 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
75 stg delete ..
78 test_expect_success \
79 'Apply a patch from a QP-encoded e-mail' \
81 stg import -m "$TEST_DIRECTORY"/t1801/email-qp &&
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 ] &&
86 stg delete ..
89 test_expect_success \
90 'Apply several patches from an mbox file' \
92 stg import -M "$TEST_DIRECTORY"/t1801/email-mbox &&
93 [ $(git cat-file -p $(stg id change-1) \
94 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
95 [ $(git cat-file -p $(stg id change-1) \
96 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
97 [ $(git cat-file -p $(stg id change-2) \
98 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
99 [ $(git cat-file -p $(stg id change-2) \
100 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
101 [ $(git cat-file -p $(stg id change-3-colon) \
102 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
103 [ $(git cat-file -p $(stg id change-3-colon) \
104 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
105 stg delete ..
108 test_expect_success \
109 'Import patches from mbox with duplicate subjects' \
111 stg import -M "$TEST_DIRECTORY"/t1801/email-mbox-same-subject &&
112 test "$(echo $(stg series --noprefix --applied))" = "my-patch my-patch-1 my-patch-2" &&
113 stg delete ..
116 test_expect_success \
117 'Apply several patches from an mbox file from stdin' \
119 cat "$TEST_DIRECTORY"/t1801/email-mbox | stg import -M &&
120 [ $(git cat-file -p $(stg id change-1) \
121 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
122 [ $(git cat-file -p $(stg id change-1) \
123 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
124 [ $(git cat-file -p $(stg id change-2) \
125 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
126 [ $(git cat-file -p $(stg id change-2) \
127 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
128 [ $(git cat-file -p $(stg id change-3-colon) \
129 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
130 [ $(git cat-file -p $(stg id change-3-colon) \
131 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
132 stg delete ..
135 test_expect_success \
136 'Apply several patches from an mbox file with CRLF line endings' \
138 cat "$TEST_DIRECTORY"/t1801/email-mbox | append_cr |
139 stg import -M &&
140 [ $(git cat-file -p $(stg id change-1) \
141 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
142 [ $(git cat-file -p $(stg id change-1) \
143 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
144 [ $(git cat-file -p $(stg id change-2) \
145 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
146 [ $(git cat-file -p $(stg id change-2) \
147 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
148 [ $(git cat-file -p $(stg id change-3-colon) \
149 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
150 [ $(git cat-file -p $(stg id change-3-colon) \
151 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
152 stg delete ..
155 test_expect_success \
156 'Import from git format-patch output' '
158 test_create_repo upstream &&
159 cd upstream &&
160 echo "something" > some.txt &&
161 git add some.txt &&
162 git commit -m "Add something"
163 stg init
164 ) &&
166 git clone upstream downstream
167 cd downstream &&
168 echo "else µ" >> some.txt &&
169 git commit -a --author "Éd <ed@example.com>" -m "something else" &&
170 git format-patch --stdout HEAD~1 > ../downstream.mbox
171 ) &&
173 cd upstream &&
174 stg import --mbox ../downstream.mbox &&
175 stg top | grep "something-else" &&
176 grep "else µ" some.txt
180 test_done