Merge branch 'np/delta'
[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         git diff 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          git diff expect actual'
88
89 echo "$file2_data" >expect
90 test_expect_success \
91         'A: verify file2' \
92         'git-cat-file blob master:file2 >actual && git diff expect actual'
93
94 echo "$file3_data" >expect
95 test_expect_success \
96         'A: verify file3' \
97         'git-cat-file blob master:file3 >actual && git diff expect actual'
98
99 printf "$file4_data" >expect
100 test_expect_success \
101         'A: verify file4' \
102         'git-cat-file blob master:file4 >actual && git diff 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         'git diff expect marks.out'
113
114 test_expect_success \
115         'A: verify marks import' \
116         'git-fast-import \
117                 --import-marks=marks.out \
118                 --export-marks=marks.new \
119                 </dev/null &&
120         git diff -u expect marks.new'
121
122 test_tick
123 cat >input <<INPUT_END
124 commit refs/heads/verify--import-marks
125 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
126 data <<COMMIT
127 recreate from :5
128 COMMIT
129
130 from :5
131 M 755 :2 copy-of-file2
132
133 INPUT_END
134 test_expect_success \
135         'A: verify marks import does not crash' \
136         'git-fast-import --import-marks=marks.out <input &&
137          git-whatchanged verify--import-marks'
138 test_expect_success \
139         'A: verify pack' \
140         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
141 cat >expect <<EOF
142 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A      copy-of-file2
143 EOF
144 git-diff-tree -M -r master verify--import-marks >actual
145 test_expect_success \
146         'A: verify diff' \
147         'compare_diff_raw expect actual &&
148          test `git-rev-parse --verify master:file2` \
149             = `git-rev-parse --verify verify--import-marks:copy-of-file2`'
150
151 ###
152 ### series B
153 ###
154
155 test_tick
156 cat >input <<INPUT_END
157 commit refs/heads/branch
158 mark :1
159 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
160 data <<COMMIT
161 corrupt
162 COMMIT
163
164 from refs/heads/master
165 M 755 0000000000000000000000000000000000000001 zero1
166
167 INPUT_END
168 test_expect_failure \
169     'B: fail on invalid blob sha1' \
170     'git-fast-import <input'
171 rm -f .git/objects/pack_* .git/objects/index_*
172
173 ###
174 ### series C
175 ###
176
177 newf=`echo hi newf | git-hash-object -w --stdin`
178 oldf=`git-rev-parse --verify master:file2`
179 test_tick
180 cat >input <<INPUT_END
181 commit refs/heads/branch
182 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
183 data <<COMMIT
184 second
185 COMMIT
186
187 from refs/heads/master
188 M 644 $oldf file2/oldf
189 M 755 $newf file2/newf
190 D file3
191
192 INPUT_END
193 test_expect_success \
194     'C: incremental import create pack from stdin' \
195     'git-fast-import <input &&
196          git-whatchanged branch'
197 test_expect_success \
198         'C: verify pack' \
199         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
200 test_expect_success \
201         'C: validate reuse existing blob' \
202         'test $newf = `git-rev-parse --verify branch:file2/newf`
203          test $oldf = `git-rev-parse --verify branch:file2/oldf`'
204
205 cat >expect <<EOF
206 parent `git-rev-parse --verify master^0`
207 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
208 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
209
210 second
211 EOF
212 test_expect_success \
213         'C: verify commit' \
214         'git-cat-file commit branch | sed 1d >actual &&
215          git diff expect actual'
216
217 cat >expect <<EOF
218 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
219 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
220 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
221 EOF
222 git-diff-tree -M -r master branch >actual
223 test_expect_success \
224         'C: validate rename result' \
225         'compare_diff_raw expect actual'
226
227 ###
228 ### series D
229 ###
230
231 test_tick
232 cat >input <<INPUT_END
233 commit refs/heads/branch
234 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
235 data <<COMMIT
236 third
237 COMMIT
238
239 from refs/heads/branch^0
240 M 644 inline newdir/interesting
241 data <<EOF
242 $file5_data
243 EOF
244
245 M 755 inline newdir/exec.sh
246 data <<EOF
247 $file6_data
248 EOF
249
250 INPUT_END
251 test_expect_success \
252     'D: inline data in commit' \
253     'git-fast-import <input &&
254          git-whatchanged branch'
255 test_expect_success \
256         'D: verify pack' \
257         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
258
259 cat >expect <<EOF
260 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A      newdir/exec.sh
261 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A      newdir/interesting
262 EOF
263 git-diff-tree -M -r branch^ branch >actual
264 test_expect_success \
265         'D: validate new files added' \
266         'compare_diff_raw expect actual'
267
268 echo "$file5_data" >expect
269 test_expect_success \
270         'D: verify file5' \
271         'git-cat-file blob branch:newdir/interesting >actual &&
272          git diff expect actual'
273
274 echo "$file6_data" >expect
275 test_expect_success \
276         'D: verify file6' \
277         'git-cat-file blob branch:newdir/exec.sh >actual &&
278          git diff expect actual'
279
280 ###
281 ### series E
282 ###
283
284 cat >input <<INPUT_END
285 commit refs/heads/branch
286 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
287 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
288 data <<COMMIT
289 RFC 2822 type date
290 COMMIT
291
292 from refs/heads/branch^0
293
294 INPUT_END
295 test_expect_failure \
296     'E: rfc2822 date, --date-format=raw' \
297     'git-fast-import --date-format=raw <input'
298 test_expect_success \
299     'E: rfc2822 date, --date-format=rfc2822' \
300     'git-fast-import --date-format=rfc2822 <input'
301 test_expect_success \
302         'E: verify pack' \
303         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
304
305 cat >expect <<EOF
306 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
307 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
308
309 RFC 2822 type date
310 EOF
311 test_expect_success \
312         'E: verify commit' \
313         'git-cat-file commit branch | sed 1,2d >actual &&
314         git diff expect actual'
315
316 ###
317 ### series F
318 ###
319
320 old_branch=`git-rev-parse --verify branch^0`
321 test_tick
322 cat >input <<INPUT_END
323 commit refs/heads/branch
324 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
325 data <<COMMIT
326 losing things already?
327 COMMIT
328
329 from refs/heads/branch~1
330
331 reset refs/heads/other
332 from refs/heads/branch
333
334 INPUT_END
335 test_expect_success \
336     'F: non-fast-forward update skips' \
337     'if git-fast-import <input
338          then
339                 echo BAD gfi did not fail
340                 return 1
341          else
342                 if test $old_branch = `git-rev-parse --verify branch^0`
343                 then
344                         : branch unaffected and failure returned
345                         return 0
346                 else
347                         echo BAD gfi changed branch $old_branch
348                         return 1
349                 fi
350          fi
351         '
352 test_expect_success \
353         'F: verify pack' \
354         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
355
356 cat >expect <<EOF
357 tree `git-rev-parse branch~1^{tree}`
358 parent `git-rev-parse branch~1`
359 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
360 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
361
362 losing things already?
363 EOF
364 test_expect_success \
365         'F: verify other commit' \
366         'git-cat-file commit other >actual &&
367         git diff expect actual'
368
369 ###
370 ### series G
371 ###
372
373 old_branch=`git-rev-parse --verify branch^0`
374 test_tick
375 cat >input <<INPUT_END
376 commit refs/heads/branch
377 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
378 data <<COMMIT
379 losing things already?
380 COMMIT
381
382 from refs/heads/branch~1
383
384 INPUT_END
385 test_expect_success \
386     'G: non-fast-forward update forced' \
387     'git-fast-import --force <input'
388 test_expect_success \
389         'G: verify pack' \
390         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
391 test_expect_success \
392         'G: branch changed, but logged' \
393         'test $old_branch != `git-rev-parse --verify branch^0` &&
394          test $old_branch = `git-rev-parse --verify branch@{1}`'
395
396 ###
397 ### series H
398 ###
399
400 test_tick
401 cat >input <<INPUT_END
402 commit refs/heads/H
403 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
404 data <<COMMIT
405 third
406 COMMIT
407
408 from refs/heads/branch^0
409 M 644 inline i-will-die
410 data <<EOF
411 this file will never exist.
412 EOF
413
414 deleteall
415 M 644 inline h/e/l/lo
416 data <<EOF
417 $file5_data
418 EOF
419
420 INPUT_END
421 test_expect_success \
422     'H: deletall, add 1' \
423     'git-fast-import <input &&
424          git-whatchanged H'
425 test_expect_success \
426         'H: verify pack' \
427         'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
428
429 cat >expect <<EOF
430 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D      file2/newf
431 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D      file2/oldf
432 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D      file4
433 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100   newdir/interesting      h/e/l/lo
434 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D      newdir/exec.sh
435 EOF
436 git-diff-tree -M -r H^ H >actual
437 test_expect_success \
438         'H: validate old files removed, new files added' \
439         'compare_diff_raw expect actual'
440
441 echo "$file5_data" >expect
442 test_expect_success \
443         'H: verify file' \
444         'git-cat-file blob H:h/e/l/lo >actual &&
445          git diff expect actual'
446
447 ###
448 ### series I
449 ###
450
451 cat >input <<INPUT_END
452 commit refs/heads/export-boundary
453 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
454 data <<COMMIT
455 we have a border.  its only 40 characters wide.
456 COMMIT
457
458 from refs/heads/branch
459
460 INPUT_END
461 test_expect_success \
462     'I: export-pack-edges' \
463     'git-fast-import --export-pack-edges=edges.list <input'
464
465 cat >expect <<EOF
466 .git/objects/pack/pack-.pack: `git-rev-parse --verify export-boundary`
467 EOF
468 test_expect_success \
469         'I: verify edge list' \
470         'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
471          git diff expect actual'
472
473 ###
474 ### series J
475 ###
476
477 cat >input <<INPUT_END
478 commit refs/heads/J
479 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
480 data <<COMMIT
481 create J
482 COMMIT
483
484 from refs/heads/branch
485
486 reset refs/heads/J
487
488 commit refs/heads/J
489 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
490 data <<COMMIT
491 initialize J
492 COMMIT
493
494 INPUT_END
495 test_expect_success \
496     'J: reset existing branch creates empty commit' \
497     'git-fast-import <input'
498 test_expect_success \
499         'J: branch has 1 commit, empty tree' \
500         'test 1 = `git-rev-list J | wc -l` &&
501          test 0 = `git ls-tree J | wc -l`'
502
503 ###
504 ### series K
505 ###
506
507 cat >input <<INPUT_END
508 commit refs/heads/K
509 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
510 data <<COMMIT
511 create K
512 COMMIT
513
514 from refs/heads/branch
515
516 commit refs/heads/K
517 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
518 data <<COMMIT
519 redo K
520 COMMIT
521
522 from refs/heads/branch^1
523
524 INPUT_END
525 test_expect_success \
526     'K: reinit branch with from' \
527     'git-fast-import <input'
528 test_expect_success \
529     'K: verify K^1 = branch^1' \
530     'test `git-rev-parse --verify branch^1` \
531                 = `git-rev-parse --verify K^1`'
532
533 ###
534 ### series L
535 ###
536
537 cat >input <<INPUT_END
538 blob
539 mark :1
540 data <<EOF
541 some data
542 EOF
543
544 blob
545 mark :2
546 data <<EOF
547 other data
548 EOF
549
550 commit refs/heads/L
551 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
552 data <<COMMIT
553 create L
554 COMMIT
555
556 M 644 :1 b.
557 M 644 :1 b/other
558 M 644 :1 ba
559
560 commit refs/heads/L
561 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
562 data <<COMMIT
563 update L
564 COMMIT
565
566 M 644 :2 b.
567 M 644 :2 b/other
568 M 644 :2 ba
569 INPUT_END
570
571 cat >expect <<EXPECT_END
572 :100644 100644 4268632... 55d3a52... M  b.
573 :040000 040000 0ae5cac... 443c768... M  b
574 :100644 100644 4268632... 55d3a52... M  ba
575 EXPECT_END
576
577 test_expect_success \
578     'L: verify internal tree sorting' \
579         'git-fast-import <input &&
580          git-diff --raw L^ L >output &&
581          git diff expect output'
582
583 test_done