Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / git / t / t9300-fast-import.sh
blob902b5f5f7fc4dbe027dd4a1c4305fca370dc6084
1 #!/bin/sh
3 # Copyright (c) 2007 Shawn Pearce
6 test_description='test git-fast-import utility'
7 . ./test-lib.sh
8 . ../diff-lib.sh ;# test-lib chdir's into trash
10 say "git-fast-import has not been taken care of, skipping test."
11 test_done
12 exit 0
14 file2_data='file2
15 second line of EOF'
17 file3_data='EOF
18 in 3rd file
19 END'
21 file4_data=abcd
22 file4_len=4
24 file5_data='an inline file.
25 we should see it later.'
27 file6_data='#!/bin/sh
28 echo "$@"'
30 ###
31 ### series A
32 ###
34 test_tick
35 cat >input <<INPUT_END
36 blob
37 mark :2
38 data <<EOF
39 $file2_data
40 EOF
42 blob
43 mark :3
44 data <<END
45 $file3_data
46 END
48 blob
49 mark :4
50 data $file4_len
51 $file4_data
52 commit refs/heads/master
53 mark :5
54 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
55 data <<COMMIT
56 initial
57 COMMIT
59 M 644 :2 file2
60 M 644 :3 file3
61 M 755 :4 file4
63 INPUT_END
64 test_expect_success \
65 'A: create pack from stdin' \
66 'git-fast-import --export-marks=marks.out <input &&
67 git whatchanged master'
68 test_expect_success \
69 'A: verify pack' \
70 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
72 cat >expect <<EOF
73 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
74 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
76 initial
77 EOF
78 test_expect_success \
79 'A: verify commit' \
80 'git cat-file commit master | sed 1d >actual &&
81 git diff expect actual'
83 cat >expect <<EOF
84 100644 blob file2
85 100644 blob file3
86 100755 blob file4
87 EOF
88 test_expect_success \
89 'A: verify tree' \
90 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
91 git diff expect actual'
93 echo "$file2_data" >expect
94 test_expect_success \
95 'A: verify file2' \
96 'git cat-file blob master:file2 >actual && git diff expect actual'
98 echo "$file3_data" >expect
99 test_expect_success \
100 'A: verify file3' \
101 'git cat-file blob master:file3 >actual && git diff expect actual'
103 printf "$file4_data" >expect
104 test_expect_success \
105 'A: verify file4' \
106 'git cat-file blob master:file4 >actual && git diff expect actual'
108 cat >expect <<EOF
109 :2 `git rev-parse --verify master:file2`
110 :3 `git rev-parse --verify master:file3`
111 :4 `git rev-parse --verify master:file4`
112 :5 `git rev-parse --verify master^0`
114 test_expect_success \
115 'A: verify marks output' \
116 'git diff expect marks.out'
118 test_expect_success \
119 'A: verify marks import' \
120 'git-fast-import \
121 --import-marks=marks.out \
122 --export-marks=marks.new \
123 </dev/null &&
124 git diff -u expect marks.new'
126 test_tick
127 cat >input <<INPUT_END
128 commit refs/heads/verify--import-marks
129 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
130 data <<COMMIT
131 recreate from :5
132 COMMIT
134 from :5
135 M 755 :2 copy-of-file2
137 INPUT_END
138 test_expect_success \
139 'A: verify marks import does not crash' \
140 'git-fast-import --import-marks=marks.out <input &&
141 git whatchanged verify--import-marks'
142 test_expect_success \
143 'A: verify pack' \
144 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
145 cat >expect <<EOF
146 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
148 git diff-tree -M -r master verify--import-marks >actual
149 test_expect_success \
150 'A: verify diff' \
151 'compare_diff_raw expect actual &&
152 test `git rev-parse --verify master:file2` \
153 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
156 ### series B
159 test_tick
160 cat >input <<INPUT_END
161 commit refs/heads/branch
162 mark :1
163 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
164 data <<COMMIT
165 corrupt
166 COMMIT
168 from refs/heads/master
169 M 755 0000000000000000000000000000000000000001 zero1
171 INPUT_END
172 test_expect_failure \
173 'B: fail on invalid blob sha1' \
174 'git-fast-import <input'
175 rm -f .git/objects/pack_* .git/objects/index_*
178 ### series C
181 newf=`echo hi newf | git-hash-object -w --stdin`
182 oldf=`git rev-parse --verify master:file2`
183 test_tick
184 cat >input <<INPUT_END
185 commit refs/heads/branch
186 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
187 data <<COMMIT
188 second
189 COMMIT
191 from refs/heads/master
192 M 644 $oldf file2/oldf
193 M 755 $newf file2/newf
194 D file3
196 INPUT_END
197 test_expect_success \
198 'C: incremental import create pack from stdin' \
199 'git-fast-import <input &&
200 git whatchanged branch'
201 test_expect_success \
202 'C: verify pack' \
203 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
204 test_expect_success \
205 'C: validate reuse existing blob' \
206 'test $newf = `git rev-parse --verify branch:file2/newf`
207 test $oldf = `git rev-parse --verify branch:file2/oldf`'
209 cat >expect <<EOF
210 parent `git rev-parse --verify master^0`
211 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
212 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
214 second
216 test_expect_success \
217 'C: verify commit' \
218 'git cat-file commit branch | sed 1d >actual &&
219 git diff expect actual'
221 cat >expect <<EOF
222 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
223 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
224 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
226 git diff-tree -M -r master branch >actual
227 test_expect_success \
228 'C: validate rename result' \
229 'compare_diff_raw expect actual'
232 ### series D
235 test_tick
236 cat >input <<INPUT_END
237 commit refs/heads/branch
238 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
239 data <<COMMIT
240 third
241 COMMIT
243 from refs/heads/branch^0
244 M 644 inline newdir/interesting
245 data <<EOF
246 $file5_data
249 M 755 inline newdir/exec.sh
250 data <<EOF
251 $file6_data
254 INPUT_END
255 test_expect_success \
256 'D: inline data in commit' \
257 'git-fast-import <input &&
258 git whatchanged branch'
259 test_expect_success \
260 'D: verify pack' \
261 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
263 cat >expect <<EOF
264 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
265 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
267 git diff-tree -M -r branch^ branch >actual
268 test_expect_success \
269 'D: validate new files added' \
270 'compare_diff_raw expect actual'
272 echo "$file5_data" >expect
273 test_expect_success \
274 'D: verify file5' \
275 'git cat-file blob branch:newdir/interesting >actual &&
276 git diff expect actual'
278 echo "$file6_data" >expect
279 test_expect_success \
280 'D: verify file6' \
281 'git cat-file blob branch:newdir/exec.sh >actual &&
282 git diff expect actual'
285 ### series E
288 cat >input <<INPUT_END
289 commit refs/heads/branch
290 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
291 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
292 data <<COMMIT
293 RFC 2822 type date
294 COMMIT
296 from refs/heads/branch^0
298 INPUT_END
299 test_expect_failure \
300 'E: rfc2822 date, --date-format=raw' \
301 'git-fast-import --date-format=raw <input'
302 test_expect_success \
303 'E: rfc2822 date, --date-format=rfc2822' \
304 'git-fast-import --date-format=rfc2822 <input'
305 test_expect_success \
306 'E: verify pack' \
307 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
309 cat >expect <<EOF
310 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
311 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
313 RFC 2822 type date
315 test_expect_success \
316 'E: verify commit' \
317 'git cat-file commit branch | sed 1,2d >actual &&
318 git diff expect actual'
321 ### series F
324 old_branch=`git rev-parse --verify branch^0`
325 test_tick
326 cat >input <<INPUT_END
327 commit refs/heads/branch
328 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
329 data <<COMMIT
330 losing things already?
331 COMMIT
333 from refs/heads/branch~1
335 reset refs/heads/other
336 from refs/heads/branch
338 INPUT_END
339 test_expect_success \
340 'F: non-fast-forward update skips' \
341 'if git-fast-import <input
342 then
343 echo BAD gfi did not fail
344 return 1
345 else
346 if test $old_branch = `git rev-parse --verify branch^0`
347 then
348 : branch unaffected and failure returned
349 return 0
350 else
351 echo BAD gfi changed branch $old_branch
352 return 1
356 test_expect_success \
357 'F: verify pack' \
358 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
360 cat >expect <<EOF
361 tree `git rev-parse branch~1^{tree}`
362 parent `git rev-parse branch~1`
363 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
364 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
366 losing things already?
368 test_expect_success \
369 'F: verify other commit' \
370 'git cat-file commit other >actual &&
371 git diff expect actual'
374 ### series G
377 old_branch=`git rev-parse --verify branch^0`
378 test_tick
379 cat >input <<INPUT_END
380 commit refs/heads/branch
381 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
382 data <<COMMIT
383 losing things already?
384 COMMIT
386 from refs/heads/branch~1
388 INPUT_END
389 test_expect_success \
390 'G: non-fast-forward update forced' \
391 'git-fast-import --force <input'
392 test_expect_success \
393 'G: verify pack' \
394 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
395 test_expect_success \
396 'G: branch changed, but logged' \
397 'test $old_branch != `git rev-parse --verify branch^0` &&
398 test $old_branch = `git rev-parse --verify branch@{1}`'
401 ### series H
404 test_tick
405 cat >input <<INPUT_END
406 commit refs/heads/H
407 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
408 data <<COMMIT
409 third
410 COMMIT
412 from refs/heads/branch^0
413 M 644 inline i-will-die
414 data <<EOF
415 this file will never exist.
418 deleteall
419 M 644 inline h/e/l/lo
420 data <<EOF
421 $file5_data
424 INPUT_END
425 test_expect_success \
426 'H: deletall, add 1' \
427 'git-fast-import <input &&
428 git whatchanged H'
429 test_expect_success \
430 'H: verify pack' \
431 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
433 cat >expect <<EOF
434 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
435 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
436 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
437 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
438 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
440 git diff-tree -M -r H^ H >actual
441 test_expect_success \
442 'H: validate old files removed, new files added' \
443 'compare_diff_raw expect actual'
445 echo "$file5_data" >expect
446 test_expect_success \
447 'H: verify file' \
448 'git cat-file blob H:h/e/l/lo >actual &&
449 git diff expect actual'
452 ### series I
455 cat >input <<INPUT_END
456 commit refs/heads/export-boundary
457 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
458 data <<COMMIT
459 we have a border. its only 40 characters wide.
460 COMMIT
462 from refs/heads/branch
464 INPUT_END
465 test_expect_success \
466 'I: export-pack-edges' \
467 'git-fast-import --export-pack-edges=edges.list <input'
469 cat >expect <<EOF
470 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
472 test_expect_success \
473 'I: verify edge list' \
474 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
475 git diff expect actual'
478 ### series J
481 cat >input <<INPUT_END
482 commit refs/heads/J
483 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
484 data <<COMMIT
485 create J
486 COMMIT
488 from refs/heads/branch
490 reset refs/heads/J
492 commit refs/heads/J
493 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
494 data <<COMMIT
495 initialize J
496 COMMIT
498 INPUT_END
499 test_expect_success \
500 'J: reset existing branch creates empty commit' \
501 'git-fast-import <input'
502 test_expect_success \
503 'J: branch has 1 commit, empty tree' \
504 'test 1 = `git rev-list J | wc -l` &&
505 test 0 = `git ls-tree J | wc -l`'
508 ### series K
511 cat >input <<INPUT_END
512 commit refs/heads/K
513 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
514 data <<COMMIT
515 create K
516 COMMIT
518 from refs/heads/branch
520 commit refs/heads/K
521 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
522 data <<COMMIT
523 redo K
524 COMMIT
526 from refs/heads/branch^1
528 INPUT_END
529 test_expect_success \
530 'K: reinit branch with from' \
531 'git-fast-import <input'
532 test_expect_success \
533 'K: verify K^1 = branch^1' \
534 'test `git rev-parse --verify branch^1` \
535 = `git rev-parse --verify K^1`'
538 ### series L
541 cat >input <<INPUT_END
542 blob
543 mark :1
544 data <<EOF
545 some data
548 blob
549 mark :2
550 data <<EOF
551 other data
554 commit refs/heads/L
555 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
556 data <<COMMIT
557 create L
558 COMMIT
560 M 644 :1 b.
561 M 644 :1 b/other
562 M 644 :1 ba
564 commit refs/heads/L
565 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
566 data <<COMMIT
567 update L
568 COMMIT
570 M 644 :2 b.
571 M 644 :2 b/other
572 M 644 :2 ba
573 INPUT_END
575 cat >expect <<EXPECT_END
576 :100644 100644 4268632... 55d3a52... M b.
577 :040000 040000 0ae5cac... 443c768... M b
578 :100644 100644 4268632... 55d3a52... M ba
579 EXPECT_END
581 test_expect_success \
582 'L: verify internal tree sorting' \
583 'git-fast-import <input &&
584 git diff --raw L^ L >output &&
585 git diff expect output'
588 ### series M
591 test_tick
592 cat >input <<INPUT_END
593 commit refs/heads/M1
594 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
595 data <<COMMIT
596 file rename
597 COMMIT
599 from refs/heads/branch^0
600 R file2/newf file2/n.e.w.f
602 INPUT_END
604 cat >expect <<EOF
605 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
607 test_expect_success \
608 'M: rename file in same subdirectory' \
609 'git-fast-import <input &&
610 git diff-tree -M -r M1^ M1 >actual &&
611 compare_diff_raw expect actual'
613 cat >input <<INPUT_END
614 commit refs/heads/M2
615 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
616 data <<COMMIT
617 file rename
618 COMMIT
620 from refs/heads/branch^0
621 R file2/newf i/am/new/to/you
623 INPUT_END
625 cat >expect <<EOF
626 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
628 test_expect_success \
629 'M: rename file to new subdirectory' \
630 'git-fast-import <input &&
631 git diff-tree -M -r M2^ M2 >actual &&
632 compare_diff_raw expect actual'
634 cat >input <<INPUT_END
635 commit refs/heads/M3
636 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
637 data <<COMMIT
638 file rename
639 COMMIT
641 from refs/heads/M2^0
642 R i other/sub
644 INPUT_END
646 cat >expect <<EOF
647 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
649 test_expect_success \
650 'M: rename subdirectory to new subdirectory' \
651 'git-fast-import <input &&
652 git diff-tree -M -r M3^ M3 >actual &&
653 compare_diff_raw expect actual'
656 ### series N
659 test_tick
660 cat >input <<INPUT_END
661 commit refs/heads/N1
662 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
663 data <<COMMIT
664 file copy
665 COMMIT
667 from refs/heads/branch^0
668 C file2/newf file2/n.e.w.f
670 INPUT_END
672 cat >expect <<EOF
673 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
675 test_expect_success \
676 'N: copy file in same subdirectory' \
677 'git-fast-import <input &&
678 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
679 compare_diff_raw expect actual'
681 cat >input <<INPUT_END
682 commit refs/heads/N2
683 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
684 data <<COMMIT
685 clean directory copy
686 COMMIT
688 from refs/heads/branch^0
689 C file2 file3
691 commit refs/heads/N2
692 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
693 data <<COMMIT
694 modify directory copy
695 COMMIT
697 M 644 inline file3/file5
698 data <<EOF
699 $file5_data
702 INPUT_END
704 cat >expect <<EOF
705 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
706 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
707 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
709 test_expect_success \
710 'N: copy then modify subdirectory' \
711 'git-fast-import <input &&
712 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
713 compare_diff_raw expect actual'
715 cat >input <<INPUT_END
716 commit refs/heads/N3
717 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
718 data <<COMMIT
719 dirty directory copy
720 COMMIT
722 from refs/heads/branch^0
723 M 644 inline file2/file5
724 data <<EOF
725 $file5_data
728 C file2 file3
729 D file2/file5
731 INPUT_END
733 test_expect_success \
734 'N: copy dirty subdirectory' \
735 'git-fast-import <input &&
736 test `git-rev-parse N2^{tree}` = `git-rev-parse N3^{tree}`'
738 test_done