Add import -p option
[stgit] / t / t1800-import.sh
1 #!/bin/sh
2 # Copyright (c) 2006 Karl Hasselström
3 test_description='Test the import command'
4 . ./test-lib.sh
5
6 test_expect_success \
7 'Initialize the StGIT repository' \
8 '
9 cp ../t1800-import/foo.txt . &&
10 git add foo.txt &&
11 git commit -a -m "initial version" &&
12 stg init
13 '
14
15 test_expect_success \
16 'Apply a patch created with "git diff"' \
17 '
18 stg import ../t1800-import/git-diff &&
19 [ $(git cat-file -p $(stg id) \
20 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
21 stg delete ..
22 '
23
24 test_expect_success \
25 'Apply a patch created with "git diff" using -p1' \
26 '
27 stg import -p1 ../t1800-import/git-diff &&
28 [ $(git cat-file -p $(stg id) \
29 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
30 stg delete ..
31 '
32
33 test_expect_success \
34 'Apply a patch created with "git diff" using -p0' \
35 '
36 stg import -p0 ../t1800-import/git-diff-p0 &&
37 [ $(git cat-file -p $(stg id) \
38 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
39 stg delete ..
40 '
41
42 test_expect_success \
43 'Apply a patch created with "git diff" using -p2' \
44 '
45 ! stg import -p2 ../t1800-import/git-diff &&
46 [ $(git cat-file -p $(stg id) \
47 | grep -c "tree a5850c97490398571d41d6304dd940800550f507") = 1 ] &&
48 stg delete ..
49 '
50
51 test_expect_success \
52 'Apply a patch created with "git diff" from a subdirectory' \
53 '
54 mkdir subdir && cd subdir &&
55 stg import ../../t1800-import/git-diff &&
56 [ $(git cat-file -p $(stg id) \
57 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
58 stg delete .. &&
59 cd ..
60 '
61
62 test_expect_success \
63 'Apply a patch created with GNU diff' \
64 '
65 stg import ../t1800-import/gnu-diff &&
66 [ $(git cat-file -p $(stg id) \
67 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
68 stg delete ..
69 '
70
71 test_expect_success \
72 'Apply a patch created with "stg export"' \
73 '
74 stg import ../t1800-import/stg-export &&
75 [ $(git cat-file -p $(stg id) \
76 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
77 stg delete ..
78 '
79
80 test_expect_success \
81 'Apply a patch from an 8bit-encoded e-mail' \
82 '
83 stg import -m ../t1800-import/email-8bit &&
84 [ $(git cat-file -p $(stg id) \
85 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
86 [ $(git cat-file -p $(stg id) \
87 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
88 stg delete ..
89 '
90
91 test_expect_success \
92 'Apply a patch from a QP-encoded e-mail' \
93 '
94 stg import -m ../t1800-import/email-qp &&
95 [ $(git cat-file -p $(stg id) \
96 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
97 [ $(git cat-file -p $(stg id) \
98 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
99 stg delete ..
100 '
101
102 test_expect_success \
103 'Apply several patches from an mbox file' \
104 '
105 stg import -M ../t1800-import/email-mbox &&
106 [ $(git cat-file -p $(stg id change-1) \
107 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
108 [ $(git cat-file -p $(stg id change-1) \
109 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
110 [ $(git cat-file -p $(stg id change-2) \
111 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
112 [ $(git cat-file -p $(stg id change-2) \
113 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
114 [ $(git cat-file -p $(stg id change-3) \
115 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
116 [ $(git cat-file -p $(stg id change-3) \
117 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
118 stg delete ..
119 '
120
121 test_expect_success \
122 'Apply a bzip2 patch created with "git diff"' \
123 '
124 bzip2 -c ../t1800-import/git-diff >../t1800-import/bzip2-git-diff &&
125 stg import ../t1800-import/bzip2-git-diff &&
126 [ $(git cat-file -p $(stg id) \
127 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
128 rm ../t1800-import/bzip2-git-diff &&
129 stg delete ..
130 '
131 test_expect_success \
132 'Apply a bzip2 patch with a .bz2 suffix' \
133 '
134 bzip2 -c ../t1800-import/git-diff >../t1800-import/git-diff.bz2 &&
135 stg import ../t1800-import/git-diff.bz2 &&
136 [ $(git cat-file -p $(stg id) \
137 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
138 rm ../t1800-import/git-diff.bz2 &&
139 stg delete ..
140 '
141
142 test_expect_success \
143 'Apply a gzip patch created with GNU diff' \
144 '
145 gzip -c ../t1800-import/gnu-diff >../t1800-import/gzip-gnu-diff &&
146 stg import ../t1800-import/gzip-gnu-diff &&
147 [ $(git cat-file -p $(stg id) \
148 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
149 rm ../t1800-import/gzip-gnu-diff &&
150 stg delete ..
151 '
152 test_expect_success \
153 'Apply a gzip patch with a .gz suffix' \
154 '
155 gzip -c ../t1800-import/gnu-diff >../t1800-import/gnu-diff.gz &&
156 stg import ../t1800-import/gnu-diff.gz &&
157 [ $(git cat-file -p $(stg id) \
158 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
159 rm ../t1800-import/gnu-diff.gz &&
160 stg delete ..
161 '
162
163 test_expect_success \
164 'apply a series from a tarball' \
165 '
166 rm -f jabberwocky.txt && touch jabberwocky.txt &&
167 git add jabberwocky.txt && git commit -m "empty file" jabberwocky.txt &&
168 (cd ../t1800-import; tar -cjf jabberwocky.tar.bz2 patches) &&
169 stg import --series ../t1800-import/jabberwocky.tar.bz2
170 [ $(git cat-file -p $(stg id) \
171 | grep -c "tree 2c33937252a21f1550c0bf21f1de534b68f69635") = 1 ] &&
172 rm ../t1800-import/jabberwocky.tar.bz2
173 '
174
175 test_done