Support RFC 2822 date parsing in fast-import.
[git/git.git] / t / t9300-fast-import.sh
CommitLineData
50aee995
SP
1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn Pearce
4#
5
6test_description='test git-fast-import utility'
7. ./test-lib.sh
8. ../diff-lib.sh ;# test-lib chdir's into trash
9
8232dc42
SP
10file2_data='file2
11second line of EOF'
12
13file3_data='EOF
14in 3rd file
15 END'
16
17file4_data=abcd
18file4_len=4
19
b715cfbb
SP
20file5_data='an inline file.
21 we should see it later.'
22
23file6_data='#!/bin/sh
24echo "$@"'
25
50aee995
SP
26###
27### series A
28###
29
30test_tick
31cat >input <<INPUT_END
32blob
33mark :2
34data <<EOF
8232dc42 35$file2_data
50aee995
SP
36EOF
37
38blob
39mark :3
40data <<END
8232dc42 41$file3_data
50aee995
SP
42END
43
44blob
45mark :4
8232dc42
SP
46data $file4_len
47$file4_data
50aee995
SP
48commit refs/heads/master
49mark :5
50committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
51data <<COMMIT
52initial
53COMMIT
54
55M 644 :2 file2
56M 644 :3 file3
57M 755 :4 file4
58
59INPUT_END
60test_expect_success \
61 'A: create pack from stdin' \
62 'git-fast-import --export-marks=marks.out <input &&
63 git-whatchanged master'
64test_expect_success \
65 'A: verify pack' \
66 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
67
68cat >expect <<EOF
69author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
70committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
71
72initial
73EOF
74test_expect_success \
75 'A: verify commit' \
76 'git-cat-file commit master | sed 1d >actual &&
77 diff -u expect actual'
78
79cat >expect <<EOF
80100644 blob file2
81100644 blob file3
82100755 blob file4
83EOF
84test_expect_success \
85 'A: verify tree' \
86 'git-cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
87 diff -u expect actual'
88
8232dc42 89echo "$file2_data" >expect
50aee995
SP
90test_expect_success \
91 'A: verify file2' \
92 'git-cat-file blob master:file2 >actual && diff -u expect actual'
93
8232dc42 94echo "$file3_data" >expect
50aee995
SP
95test_expect_success \
96 'A: verify file3' \
97 'git-cat-file blob master:file3 >actual && diff -u expect actual'
98
8232dc42 99printf "$file4_data" >expect
50aee995
SP
100test_expect_success \
101 'A: verify file4' \
102 'git-cat-file blob master:file4 >actual && diff -u expect actual'
103
104cat >expect <<EOF
105:2 `git-rev-parse --verify master:file2`
106:3 `git-rev-parse --verify master:file3`
107:4 `git-rev-parse --verify master:file4`
108:5 `git-rev-parse --verify master^0`
109EOF
110test_expect_success \
111 'A: verify marks output' \
112 'diff -u expect marks.out'
113
114###
115### series B
116###
117
118test_tick
119cat >input <<INPUT_END
120commit refs/heads/branch
121mark :1
122committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
123data <<COMMIT
124corrupt
125COMMIT
126
127from refs/heads/master
128M 755 0000000000000000000000000000000000000001 zero1
129
130INPUT_END
131test_expect_failure \
132 'B: fail on invalid blob sha1' \
133 'git-fast-import <input'
134rm -f .git/objects/pack_* .git/objects/index_*
135
136###
137### series C
138###
139
140newf=`echo hi newf | git-hash-object -w --stdin`
141oldf=`git-rev-parse --verify master:file2`
142test_tick
143cat >input <<INPUT_END
144commit refs/heads/branch
145committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
146data <<COMMIT
147second
148COMMIT
149
150from refs/heads/master
151M 644 $oldf file2/oldf
152M 755 $newf file2/newf
153D file3
154
155INPUT_END
156test_expect_success \
157 'C: incremental import create pack from stdin' \
158 'git-fast-import <input &&
159 git-whatchanged branch'
160test_expect_success \
161 'C: verify pack' \
162 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
163test_expect_success \
164 'C: validate reuse existing blob' \
165 'test $newf = `git-rev-parse --verify branch:file2/newf`
166 test $oldf = `git-rev-parse --verify branch:file2/oldf`'
167
168cat >expect <<EOF
169parent `git-rev-parse --verify master^0`
170author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
171committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
172
173second
174EOF
175test_expect_success \
176 'C: verify commit' \
177 'git-cat-file commit branch | sed 1d >actual &&
178 diff -u expect actual'
179
180cat >expect <<EOF
181:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
182:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
183:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
184EOF
185git-diff-tree -M -r master branch >actual
186test_expect_success \
187 'C: validate rename result' \
188 'compare_diff_raw expect actual'
189
b715cfbb
SP
190###
191### series D
192###
193
194test_tick
195cat >input <<INPUT_END
196commit refs/heads/branch
197committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
198data <<COMMIT
199third
200COMMIT
201
202from refs/heads/branch^0
203M 644 inline newdir/interesting
204data <<EOF
205$file5_data
206EOF
207
208M 755 inline newdir/exec.sh
209data <<EOF
210$file6_data
211EOF
212
213INPUT_END
214test_expect_success \
215 'D: inline data in commit' \
216 'git-fast-import <input &&
217 git-whatchanged branch'
218test_expect_success \
219 'D: verify pack' \
220 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
221
222cat >expect <<EOF
223:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
224:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
225EOF
226git-diff-tree -M -r branch^ branch >actual
227test_expect_success \
228 'D: validate new files added' \
229 'compare_diff_raw expect actual'
230
231echo "$file5_data" >expect
232test_expect_success \
233 'D: verify file5' \
234 'git-cat-file blob branch:newdir/interesting >actual &&
235 diff -u expect actual'
236
237echo "$file6_data" >expect
238test_expect_success \
239 'D: verify file6' \
240 'git-cat-file blob branch:newdir/exec.sh >actual &&
241 diff -u expect actual'
242
63e0c8b3
SP
243###
244### series E
245###
246
247cat >input <<INPUT_END
248commit refs/heads/branch
249author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
250committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
251data <<COMMIT
252RFC 2822 type date
253COMMIT
254
255from refs/heads/branch^0
256
257INPUT_END
258test_expect_failure \
259 'E: rfc2822 date, --date-format=raw' \
260 'git-fast-import --date-format=raw <input'
261test_expect_success \
262 'E: rfc2822 date, --date-format=rfc2822' \
263 'git-fast-import --date-format=rfc2822 <input'
264test_expect_success \
265 'E: verify pack' \
266 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
267
268cat >expect <<EOF
269author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
270committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
271
272RFC 2822 type date
273EOF
274test_expect_success \
275 'E: verify commit' \
276 'git-cat-file commit branch | sed 1,2d >actual &&
277 diff -u expect actual'
278
50aee995 279test_done