Merge branch 'master' of git://repo.or.cz/git-gui
[git] / t / t9300-fast-import.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Shawn Pearce
4 #
5
6 test_description='test git-fast-import utility'
7 . ./test-lib.sh
8 . ../diff-lib.sh ;# test-lib chdir's into trash
9
10 file2_data='file2
11 second line of EOF'
12
13 file3_data='EOF
14 in 3rd file
15  END'
16
17 file4_data=abcd
18 file4_len=4
19
20 file5_data='an inline file.
21   we should see it later.'
22
23 file6_data='#!/bin/sh
24 echo "$@"'
25
26 ###
27 ### series A
28 ###
29
30 test_tick
31 cat >input <<INPUT_END
32 blob
33 mark :2
34 data <<EOF
35 $file2_data
36 EOF
37
38 blob
39 mark :3
40 data <<END
41 $file3_data
42 END
43
44 blob
45 mark :4
46 data $file4_len
47 $file4_data
48 commit refs/heads/master
49 mark :5
50 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
51 data <<COMMIT
52 initial
53 COMMIT
54
55 M 644 :2 file2
56 M 644 :3 file3
57 M 755 :4 file4
58
59 INPUT_END
60 test_expect_success \
61     'A: create pack from stdin' \
62     'git-fast-import --export-marks=marks.out <input &&
63          git-whatchanged master'
64 test_expect_success \
65         'A: verify pack' \
66         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
67
68 cat >expect <<EOF
69 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
71
72 initial
73 EOF
74 test_expect_success \
75         'A: verify commit' \
76         'git-cat-file commit master | sed 1d >actual &&
77         diff -u expect actual'
78
79 cat >expect <<EOF
80 100644 blob file2
81 100644 blob file3
82 100755 blob file4
83 EOF
84 test_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
89 echo "$file2_data" >expect
90 test_expect_success \
91         'A: verify file2' \
92         'git-cat-file blob master:file2 >actual && diff -u expect actual'
93
94 echo "$file3_data" >expect
95 test_expect_success \
96         'A: verify file3' \
97         'git-cat-file blob master:file3 >actual && diff -u expect actual'
98
99 printf "$file4_data" >expect
100 test_expect_success \
101         'A: verify file4' \
102         'git-cat-file blob master:file4 >actual && diff -u expect actual'
103
104 cat >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`
109 EOF
110 test_expect_success \
111         'A: verify marks output' \
112         'diff -u expect marks.out'
113
114 ###
115 ### series B
116 ###
117
118 test_tick
119 cat >input <<INPUT_END
120 commit refs/heads/branch
121 mark :1
122 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
123 data <<COMMIT
124 corrupt
125 COMMIT
126
127 from refs/heads/master
128 M 755 0000000000000000000000000000000000000001 zero1
129
130 INPUT_END
131 test_expect_failure \
132     'B: fail on invalid blob sha1' \
133     'git-fast-import <input'
134 rm -f .git/objects/pack_* .git/objects/index_*
135
136 ###
137 ### series C
138 ###
139
140 newf=`echo hi newf | git-hash-object -w --stdin`
141 oldf=`git-rev-parse --verify master:file2`
142 test_tick
143 cat >input <<INPUT_END
144 commit refs/heads/branch
145 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
146 data <<COMMIT
147 second
148 COMMIT
149
150 from refs/heads/master
151 M 644 $oldf file2/oldf
152 M 755 $newf file2/newf
153 D file3
154
155 INPUT_END
156 test_expect_success \
157     'C: incremental import create pack from stdin' \
158     'git-fast-import <input &&
159          git-whatchanged branch'
160 test_expect_success \
161         'C: verify pack' \
162         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
163 test_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
168 cat >expect <<EOF
169 parent `git-rev-parse --verify master^0`
170 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
171 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
172
173 second
174 EOF
175 test_expect_success \
176         'C: verify commit' \
177         'git-cat-file commit branch | sed 1d >actual &&
178          diff -u expect actual'
179
180 cat >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
184 EOF
185 git-diff-tree -M -r master branch >actual
186 test_expect_success \
187         'C: validate rename result' \
188         'compare_diff_raw expect actual'
189
190 ###
191 ### series D
192 ###
193
194 test_tick
195 cat >input <<INPUT_END
196 commit refs/heads/branch
197 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
198 data <<COMMIT
199 third
200 COMMIT
201
202 from refs/heads/branch^0
203 M 644 inline newdir/interesting
204 data <<EOF
205 $file5_data
206 EOF
207
208 M 755 inline newdir/exec.sh
209 data <<EOF
210 $file6_data
211 EOF
212
213 INPUT_END
214 test_expect_success \
215     'D: inline data in commit' \
216     'git-fast-import <input &&
217          git-whatchanged branch'
218 test_expect_success \
219         'D: verify pack' \
220         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
221
222 cat >expect <<EOF
223 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A      newdir/exec.sh
224 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A      newdir/interesting
225 EOF
226 git-diff-tree -M -r branch^ branch >actual
227 test_expect_success \
228         'D: validate new files added' \
229         'compare_diff_raw expect actual'
230
231 echo "$file5_data" >expect
232 test_expect_success \
233         'D: verify file5' \
234         'git-cat-file blob branch:newdir/interesting >actual &&
235          diff -u expect actual'
236
237 echo "$file6_data" >expect
238 test_expect_success \
239         'D: verify file6' \
240         'git-cat-file blob branch:newdir/exec.sh >actual &&
241          diff -u expect actual'
242
243 ###
244 ### series E
245 ###
246
247 cat >input <<INPUT_END
248 commit refs/heads/branch
249 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
250 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
251 data <<COMMIT
252 RFC 2822 type date
253 COMMIT
254
255 from refs/heads/branch^0
256
257 INPUT_END
258 test_expect_failure \
259     'E: rfc2822 date, --date-format=raw' \
260     'git-fast-import --date-format=raw <input'
261 test_expect_success \
262     'E: rfc2822 date, --date-format=rfc2822' \
263     'git-fast-import --date-format=rfc2822 <input'
264 test_expect_success \
265         'E: verify pack' \
266         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
267
268 cat >expect <<EOF
269 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
270 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
271
272 RFC 2822 type date
273 EOF
274 test_expect_success \
275         'E: verify commit' \
276         'git-cat-file commit branch | sed 1,2d >actual &&
277         diff -u expect actual'
278
279 ###
280 ### series F
281 ###
282
283 old_branch=`git-rev-parse --verify branch^0`
284 test_tick
285 cat >input <<INPUT_END
286 commit refs/heads/branch
287 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
288 data <<COMMIT
289 losing things already?
290 COMMIT
291
292 from refs/heads/branch~1
293
294 reset refs/heads/other
295 from refs/heads/branch
296
297 INPUT_END
298 test_expect_success \
299     'F: non-fast-forward update skips' \
300     'if git-fast-import <input
301          then
302                 echo BAD gfi did not fail
303                 return 1
304          else
305                 if test $old_branch = `git-rev-parse --verify branch^0`
306                 then
307                         : branch unaffected and failure returned
308                         return 0
309                 else
310                         echo BAD gfi changed branch $old_branch
311                         return 1
312                 fi
313          fi
314         '
315 test_expect_success \
316         'F: verify pack' \
317         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
318
319 cat >expect <<EOF
320 tree `git-rev-parse branch~1^{tree}`
321 parent `git-rev-parse branch~1`
322 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
323 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
324
325 losing things already?
326 EOF
327 test_expect_success \
328         'F: verify other commit' \
329         'git-cat-file commit other >actual &&
330         diff -u expect actual'
331
332 ###
333 ### series G
334 ###
335
336 old_branch=`git-rev-parse --verify branch^0`
337 test_tick
338 cat >input <<INPUT_END
339 commit refs/heads/branch
340 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
341 data <<COMMIT
342 losing things already?
343 COMMIT
344
345 from refs/heads/branch~1
346
347 INPUT_END
348 test_expect_success \
349     'G: non-fast-forward update forced' \
350     'git-fast-import --force <input'
351 test_expect_success \
352         'G: verify pack' \
353         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
354 test_expect_success \
355         'G: branch changed, but logged' \
356         'test $old_branch != `git-rev-parse --verify branch^0` &&
357          test $old_branch = `git-rev-parse --verify branch@{1}`'
358
359 ###
360 ### series H
361 ###
362
363 test_tick
364 cat >input <<INPUT_END
365 commit refs/heads/H
366 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
367 data <<COMMIT
368 third
369 COMMIT
370
371 from refs/heads/branch^0
372 M 644 inline i-will-die
373 data <<EOF
374 this file will never exist.
375 EOF
376
377 deleteall
378 M 644 inline h/e/l/lo
379 data <<EOF
380 $file5_data
381 EOF
382
383 INPUT_END
384 test_expect_success \
385     'H: deletall, add 1' \
386     'git-fast-import <input &&
387          git-whatchanged H'
388 test_expect_success \
389         'H: verify pack' \
390         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
391
392 cat >expect <<EOF
393 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
394 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
395 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
396 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
397 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
398 EOF
399 git-diff-tree -M -r H^ H >actual
400 test_expect_success \
401         'H: validate old files removed, new files added' \
402         'compare_diff_raw expect actual'
403
404 echo "$file5_data" >expect
405 test_expect_success \
406         'H: verify file' \
407         'git-cat-file blob H:h/e/l/lo >actual &&
408          diff -u expect actual'
409
410 ###
411 ### series I
412 ###
413
414 cat >input <<INPUT_END
415 commit refs/heads/export-boundary
416 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
417 data <<COMMIT
418 we have a border.  its only 40 characters wide.
419 COMMIT
420
421 from refs/heads/branch
422
423 INPUT_END
424 test_expect_success \
425     'I: export-pack-edges' \
426     'git-fast-import --export-pack-edges=edges.list <input'
427
428 cat >expect <<EOF
429 .git/objects/pack/pack-.pack: `git-rev-parse --verify export-boundary`
430 EOF
431 test_expect_success \
432         'I: verify edge list' \
433         'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
434          diff -u expect actual'
435
436 ###
437 ### series J
438 ###
439
440 cat >input <<INPUT_END
441 commit refs/heads/J
442 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
443 data <<COMMIT
444 create J
445 COMMIT
446
447 from refs/heads/branch
448
449 reset refs/heads/J
450
451 commit refs/heads/J
452 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
453 data <<COMMIT
454 initialize J
455 COMMIT
456
457 INPUT_END
458 test_expect_success \
459     'J: reset existing branch creates empty commit' \
460     'git-fast-import <input'
461 test_expect_success \
462         'J: branch has 1 commit, empty tree' \
463         'test 1 = `git-rev-list J | wc -l` &&
464          test 0 = `git ls-tree J | wc -l`'
465
466 ###
467 ### series K
468 ###
469
470 cat >input <<INPUT_END
471 commit refs/heads/K
472 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
473 data <<COMMIT
474 create K
475 COMMIT
476
477 from refs/heads/branch
478
479 commit refs/heads/K
480 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
481 data <<COMMIT
482 redo K
483 COMMIT
484
485 from refs/heads/branch^1
486
487 INPUT_END
488 test_expect_success \
489     'K: reinit branch with from' \
490     'git-fast-import <input'
491 test_expect_success \
492     'K: verify K^1 = branch^1' \
493     'test `git-rev-parse --verify branch^1` \
494                 = `git-rev-parse --verify K^1`'
495
496 test_done