Add import -p option
[stgit] / t / t1800-import.sh
CommitLineData
e4fc1f59
KH
1#!/bin/sh
2# Copyright (c) 2006 Karl Hasselström
3test_description='Test the import command'
4. ./test-lib.sh
5
6test_expect_success \
7 'Initialize the StGIT repository' \
8 '
fb336055 9 cp ../t1800-import/foo.txt . &&
e4fc1f59
KH
10 git add foo.txt &&
11 git commit -a -m "initial version" &&
12 stg init
13 '
14
15test_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) \
89f64744 20 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
e4fc1f59
KH
21 stg delete ..
22 '
23
24test_expect_success \
c18842cc
CM
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
33test_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
42test_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
51test_expect_success \
47d51d91
CM
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
62test_expect_success \
e4fc1f59
KH
63 'Apply a patch created with GNU diff' \
64 '
65 stg import ../t1800-import/gnu-diff &&
66 [ $(git cat-file -p $(stg id) \
89f64744 67 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
e4fc1f59
KH
68 stg delete ..
69 '
70
71test_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) \
89f64744 76 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
e4fc1f59
KH
77 stg delete ..
78 '
79
80test_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) \
89f64744 85 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
e4fc1f59 86 [ $(git cat-file -p $(stg id) \
89f64744 87 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
e4fc1f59
KH
88 stg delete ..
89 '
90
91test_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) \
89f64744 96 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
e4fc1f59 97 [ $(git cat-file -p $(stg id) \
89f64744 98 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
e4fc1f59
KH
99 stg delete ..
100 '
101
102test_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) \
89f64744 107 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
e4fc1f59 108 [ $(git cat-file -p $(stg id change-1) \
89f64744 109 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
e4fc1f59 110 [ $(git cat-file -p $(stg id change-2) \
89f64744 111 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
e4fc1f59 112 [ $(git cat-file -p $(stg id change-2) \
89f64744 113 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
e4fc1f59 114 [ $(git cat-file -p $(stg id change-3) \
89f64744 115 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
e4fc1f59 116 [ $(git cat-file -p $(stg id change-3) \
89f64744 117 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
e4fc1f59
KH
118 stg delete ..
119 '
120
354d2031
CW
121test_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 '
131test_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
142test_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 '
152test_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
972de1db
CW
163test_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
e4fc1f59 175test_done