libgit-thin: Update QUESTIONS file
[git/libgit-gsoc.git] / t / t9300-fast-import.sh
blob6f95305bf461c2659392d3ee6a77a5360c833c37
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 file2_data='file2
11 second line of EOF'
13 file3_data='EOF
14 in 3rd file
15 END'
17 file4_data=abcd
18 file4_len=4
20 file5_data='an inline file.
21 we should see it later.'
23 file6_data='#!/bin/sh
24 echo "$@"'
26 ###
27 ### series A
28 ###
30 test_tick
31 cat >input <<INPUT_END
32 blob
33 mark :2
34 data <<EOF
35 $file2_data
36 EOF
38 blob
39 mark :3
40 data <<END
41 $file3_data
42 END
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
55 M 644 :2 file2
56 M 644 :3 file3
57 M 755 :4 file4
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'
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
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'
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'
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'
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'
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'
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`
110 test_expect_success \
111 'A: verify marks output' \
112 'git diff expect marks.out'
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'
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
130 from :5
131 M 755 :2 copy-of-file2
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
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`'
152 ### series B
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
164 from refs/heads/master
165 M 755 0000000000000000000000000000000000000001 zero1
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_*
174 ### series C
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
187 from refs/heads/master
188 M 644 $oldf file2/oldf
189 M 755 $newf file2/newf
190 D file3
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`'
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
210 second
212 test_expect_success \
213 'C: verify commit' \
214 'git cat-file commit branch | sed 1d >actual &&
215 git diff expect actual'
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
222 git diff-tree -M -r master branch >actual
223 test_expect_success \
224 'C: validate rename result' \
225 'compare_diff_raw expect actual'
228 ### series D
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
239 from refs/heads/branch^0
240 M 644 inline newdir/interesting
241 data <<EOF
242 $file5_data
245 M 755 inline newdir/exec.sh
246 data <<EOF
247 $file6_data
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'
259 cat >expect <<EOF
260 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
261 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
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'
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'
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'
281 ### series E
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
292 from refs/heads/branch^0
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'
305 cat >expect <<EOF
306 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
307 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
309 RFC 2822 type date
311 test_expect_success \
312 'E: verify commit' \
313 'git cat-file commit branch | sed 1,2d >actual &&
314 git diff expect actual'
317 ### series F
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
329 from refs/heads/branch~1
331 reset refs/heads/other
332 from refs/heads/branch
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
352 test_expect_success \
353 'F: verify pack' \
354 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
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
362 losing things already?
364 test_expect_success \
365 'F: verify other commit' \
366 'git cat-file commit other >actual &&
367 git diff expect actual'
370 ### series G
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
382 from refs/heads/branch~1
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}`'
397 ### series H
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
408 from refs/heads/branch^0
409 M 644 inline i-will-die
410 data <<EOF
411 this file will never exist.
414 deleteall
415 M 644 inline h/e/l/lo
416 data <<EOF
417 $file5_data
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'
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
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'
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'
448 ### series I
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
458 from refs/heads/branch
460 INPUT_END
461 test_expect_success \
462 'I: export-pack-edges' \
463 'git-fast-import --export-pack-edges=edges.list <input'
465 cat >expect <<EOF
466 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
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'
474 ### series J
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
484 from refs/heads/branch
486 reset refs/heads/J
488 commit refs/heads/J
489 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
490 data <<COMMIT
491 initialize J
492 COMMIT
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`'
504 ### series K
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
514 from refs/heads/branch
516 commit refs/heads/K
517 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
518 data <<COMMIT
519 redo K
520 COMMIT
522 from refs/heads/branch^1
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`'
534 ### series L
537 cat >input <<INPUT_END
538 blob
539 mark :1
540 data <<EOF
541 some data
544 blob
545 mark :2
546 data <<EOF
547 other data
550 commit refs/heads/L
551 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
552 data <<COMMIT
553 create L
554 COMMIT
556 M 644 :1 b.
557 M 644 :1 b/other
558 M 644 :1 ba
560 commit refs/heads/L
561 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
562 data <<COMMIT
563 update L
564 COMMIT
566 M 644 :2 b.
567 M 644 :2 b/other
568 M 644 :2 ba
569 INPUT_END
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
577 test_expect_success \
578 'L: verify internal tree sorting' \
579 'git-fast-import <input &&
580 git diff-tree --abbrev --raw L^ L >output &&
581 git diff expect output'
584 ### series M
587 test_tick
588 cat >input <<INPUT_END
589 commit refs/heads/M1
590 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
591 data <<COMMIT
592 file rename
593 COMMIT
595 from refs/heads/branch^0
596 R file2/newf file2/n.e.w.f
598 INPUT_END
600 cat >expect <<EOF
601 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
603 test_expect_success \
604 'M: rename file in same subdirectory' \
605 'git-fast-import <input &&
606 git diff-tree -M -r M1^ M1 >actual &&
607 compare_diff_raw expect actual'
609 cat >input <<INPUT_END
610 commit refs/heads/M2
611 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
612 data <<COMMIT
613 file rename
614 COMMIT
616 from refs/heads/branch^0
617 R file2/newf i/am/new/to/you
619 INPUT_END
621 cat >expect <<EOF
622 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
624 test_expect_success \
625 'M: rename file to new subdirectory' \
626 'git-fast-import <input &&
627 git diff-tree -M -r M2^ M2 >actual &&
628 compare_diff_raw expect actual'
630 cat >input <<INPUT_END
631 commit refs/heads/M3
632 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
633 data <<COMMIT
634 file rename
635 COMMIT
637 from refs/heads/M2^0
638 R i other/sub
640 INPUT_END
642 cat >expect <<EOF
643 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
645 test_expect_success \
646 'M: rename subdirectory to new subdirectory' \
647 'git-fast-import <input &&
648 git diff-tree -M -r M3^ M3 >actual &&
649 compare_diff_raw expect actual'
652 ### series N
655 test_tick
656 cat >input <<INPUT_END
657 commit refs/heads/N1
658 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
659 data <<COMMIT
660 file copy
661 COMMIT
663 from refs/heads/branch^0
664 C file2/newf file2/n.e.w.f
666 INPUT_END
668 cat >expect <<EOF
669 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
671 test_expect_success \
672 'N: copy file in same subdirectory' \
673 'git-fast-import <input &&
674 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
675 compare_diff_raw expect actual'
677 cat >input <<INPUT_END
678 commit refs/heads/N2
679 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
680 data <<COMMIT
681 clean directory copy
682 COMMIT
684 from refs/heads/branch^0
685 C file2 file3
687 commit refs/heads/N2
688 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
689 data <<COMMIT
690 modify directory copy
691 COMMIT
693 M 644 inline file3/file5
694 data <<EOF
695 $file5_data
698 INPUT_END
700 cat >expect <<EOF
701 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
702 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
703 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
705 test_expect_success \
706 'N: copy then modify subdirectory' \
707 'git-fast-import <input &&
708 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
709 compare_diff_raw expect actual'
711 cat >input <<INPUT_END
712 commit refs/heads/N3
713 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
714 data <<COMMIT
715 dirty directory copy
716 COMMIT
718 from refs/heads/branch^0
719 M 644 inline file2/file5
720 data <<EOF
721 $file5_data
724 C file2 file3
725 D file2/file5
727 INPUT_END
729 test_expect_success \
730 'N: copy dirty subdirectory' \
731 'git-fast-import <input &&
732 test `git-rev-parse N2^{tree}` = `git-rev-parse N3^{tree}`'
734 test_done