3 # Copyright (c) 2007 Shawn Pearce
6 test_description='test git-fast-import utility'
8 . ../diff-lib.sh ;# test-lib chdir's into trash
20 file5_data='an inline file.
21 we should see it later.'
31 cat >input <<INPUT_END
48 commit refs/heads/master
50 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
61 'A: create pack from stdin' \
62 'git-fast-import --export-marks=marks.out <input &&
63 git whatchanged master'
66 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
69 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
76 'git cat-file commit master | sed 1d >actual &&
77 git diff expect actual'
86 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
87 git diff expect actual'
89 echo "$file2_data" >expect
92 'git cat-file blob master:file2 >actual && git diff expect actual'
94 echo "$file3_data" >expect
97 'git cat-file blob master:file3 >actual && git diff expect actual'
99 printf "$file4_data" >expect
100 test_expect_success \
102 'git cat-file blob master:file4 >actual && git diff expect actual'
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' \
117 --import-marks=marks.out \
118 --export-marks=marks.new \
120 git diff -u expect marks.new'
123 cat >input <<INPUT_END
124 commit refs/heads/verify--import-marks
125 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
131 M 755 :2 copy-of-file2
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 \
140 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
142 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
144 git diff-tree -M -r master verify--import-marks >actual
145 test_expect_success \
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`'
156 cat >input <<INPUT_END
157 commit refs/heads/branch
159 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
164 from refs/heads/master
165 M 755 0000000000000000000000000000000000000001 zero1
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_*
173 cat >input <<INPUT_END
174 commit .badbranchname
175 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
180 from refs/heads/master
183 test_expect_failure \
184 'B: fail on invalid branch name ".badbranchname"' \
185 'git-fast-import <input'
186 rm -f .git/objects/pack_* .git/objects/index_*
188 cat >input <<INPUT_END
189 commit bad[branch]name
190 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
195 from refs/heads/master
198 test_expect_failure \
199 'B: fail on invalid branch name "bad[branch]name"' \
200 'git-fast-import <input'
201 rm -f .git/objects/pack_* .git/objects/index_*
203 cat >input <<INPUT_END
205 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
210 from refs/heads/master
213 test_expect_success \
214 'B: accept branch name "TEMP_TAG"' \
215 'git-fast-import <input &&
216 test -f .git/TEMP_TAG &&
217 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
224 newf=`echo hi newf | git-hash-object -w --stdin`
225 oldf=`git rev-parse --verify master:file2`
227 cat >input <<INPUT_END
228 commit refs/heads/branch
229 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
234 from refs/heads/master
235 M 644 $oldf file2/oldf
236 M 755 $newf file2/newf
240 test_expect_success \
241 'C: incremental import create pack from stdin' \
242 'git-fast-import <input &&
243 git whatchanged branch'
244 test_expect_success \
246 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
247 test_expect_success \
248 'C: validate reuse existing blob' \
249 'test $newf = `git rev-parse --verify branch:file2/newf`
250 test $oldf = `git rev-parse --verify branch:file2/oldf`'
253 parent `git rev-parse --verify master^0`
254 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
255 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
259 test_expect_success \
261 'git cat-file commit branch | sed 1d >actual &&
262 git diff expect actual'
265 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
266 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
267 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
269 git diff-tree -M -r master branch >actual
270 test_expect_success \
271 'C: validate rename result' \
272 'compare_diff_raw expect actual'
279 cat >input <<INPUT_END
280 commit refs/heads/branch
281 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
286 from refs/heads/branch^0
287 M 644 inline newdir/interesting
292 M 755 inline newdir/exec.sh
298 test_expect_success \
299 'D: inline data in commit' \
300 'git-fast-import <input &&
301 git whatchanged branch'
302 test_expect_success \
304 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
307 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
308 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
310 git diff-tree -M -r branch^ branch >actual
311 test_expect_success \
312 'D: validate new files added' \
313 'compare_diff_raw expect actual'
315 echo "$file5_data" >expect
316 test_expect_success \
318 'git cat-file blob branch:newdir/interesting >actual &&
319 git diff expect actual'
321 echo "$file6_data" >expect
322 test_expect_success \
324 'git cat-file blob branch:newdir/exec.sh >actual &&
325 git diff expect actual'
331 cat >input <<INPUT_END
332 commit refs/heads/branch
333 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
334 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
339 from refs/heads/branch^0
342 test_expect_failure \
343 'E: rfc2822 date, --date-format=raw' \
344 'git-fast-import --date-format=raw <input'
345 test_expect_success \
346 'E: rfc2822 date, --date-format=rfc2822' \
347 'git-fast-import --date-format=rfc2822 <input'
348 test_expect_success \
350 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
353 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
354 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
358 test_expect_success \
360 'git cat-file commit branch | sed 1,2d >actual &&
361 git diff expect actual'
367 old_branch=`git rev-parse --verify branch^0`
369 cat >input <<INPUT_END
370 commit refs/heads/branch
371 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
373 losing things already?
376 from refs/heads/branch~1
378 reset refs/heads/other
379 from refs/heads/branch
382 test_expect_success \
383 'F: non-fast-forward update skips' \
384 'if git-fast-import <input
386 echo BAD gfi did not fail
389 if test $old_branch = `git rev-parse --verify branch^0`
391 : branch unaffected and failure returned
394 echo BAD gfi changed branch $old_branch
399 test_expect_success \
401 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
404 tree `git rev-parse branch~1^{tree}`
405 parent `git rev-parse branch~1`
406 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
407 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
409 losing things already?
411 test_expect_success \
412 'F: verify other commit' \
413 'git cat-file commit other >actual &&
414 git diff expect actual'
420 old_branch=`git rev-parse --verify branch^0`
422 cat >input <<INPUT_END
423 commit refs/heads/branch
424 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
426 losing things already?
429 from refs/heads/branch~1
432 test_expect_success \
433 'G: non-fast-forward update forced' \
434 'git-fast-import --force <input'
435 test_expect_success \
437 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
438 test_expect_success \
439 'G: branch changed, but logged' \
440 'test $old_branch != `git rev-parse --verify branch^0` &&
441 test $old_branch = `git rev-parse --verify branch@{1}`'
448 cat >input <<INPUT_END
450 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
455 from refs/heads/branch^0
456 M 644 inline i-will-die
458 this file will never exist.
462 M 644 inline h/e/l/lo
468 test_expect_success \
469 'H: deletall, add 1' \
470 'git-fast-import <input &&
472 test_expect_success \
474 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
477 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
478 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
479 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
480 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
481 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
483 git diff-tree -M -r H^ H >actual
484 test_expect_success \
485 'H: validate old files removed, new files added' \
486 'compare_diff_raw expect actual'
488 echo "$file5_data" >expect
489 test_expect_success \
491 'git cat-file blob H:h/e/l/lo >actual &&
492 git diff expect actual'
498 cat >input <<INPUT_END
499 commit refs/heads/export-boundary
500 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
502 we have a border. its only 40 characters wide.
505 from refs/heads/branch
508 test_expect_success \
509 'I: export-pack-edges' \
510 'git-fast-import --export-pack-edges=edges.list <input'
513 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
515 test_expect_success \
516 'I: verify edge list' \
517 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
518 git diff expect actual'
524 cat >input <<INPUT_END
526 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
531 from refs/heads/branch
536 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
542 test_expect_success \
543 'J: reset existing branch creates empty commit' \
544 'git-fast-import <input'
545 test_expect_success \
546 'J: branch has 1 commit, empty tree' \
547 'test 1 = `git rev-list J | wc -l` &&
548 test 0 = `git ls-tree J | wc -l`'
554 cat >input <<INPUT_END
556 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
561 from refs/heads/branch
564 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
569 from refs/heads/branch^1
572 test_expect_success \
573 'K: reinit branch with from' \
574 'git-fast-import <input'
575 test_expect_success \
576 'K: verify K^1 = branch^1' \
577 'test `git rev-parse --verify branch^1` \
578 = `git rev-parse --verify K^1`'
584 cat >input <<INPUT_END
598 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
608 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
618 cat >expect <<EXPECT_END
619 :100644 100644 4268632... 55d3a52... M b.
620 :040000 040000 0ae5cac... 443c768... M b
621 :100644 100644 4268632... 55d3a52... M ba
624 test_expect_success \
625 'L: verify internal tree sorting' \
626 'git-fast-import <input &&
627 git diff-tree --abbrev --raw L^ L >output &&
628 git diff expect output'
635 cat >input <<INPUT_END
637 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
642 from refs/heads/branch^0
643 R file2/newf file2/n.e.w.f
648 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
650 test_expect_success \
651 'M: rename file in same subdirectory' \
652 'git-fast-import <input &&
653 git diff-tree -M -r M1^ M1 >actual &&
654 compare_diff_raw expect actual'
656 cat >input <<INPUT_END
658 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
663 from refs/heads/branch^0
664 R file2/newf i/am/new/to/you
669 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
671 test_expect_success \
672 'M: rename file to new subdirectory' \
673 'git-fast-import <input &&
674 git diff-tree -M -r M2^ M2 >actual &&
675 compare_diff_raw expect actual'
677 cat >input <<INPUT_END
679 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
690 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
692 test_expect_success \
693 'M: rename subdirectory to new subdirectory' \
694 'git-fast-import <input &&
695 git diff-tree -M -r M3^ M3 >actual &&
696 compare_diff_raw expect actual'
703 cat >input <<INPUT_END
705 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
710 from refs/heads/branch^0
711 C file2/newf file2/n.e.w.f
716 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
718 test_expect_success \
719 'N: copy file in same subdirectory' \
720 'git-fast-import <input &&
721 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
722 compare_diff_raw expect actual'
724 cat >input <<INPUT_END
726 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
731 from refs/heads/branch^0
735 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
737 modify directory copy
740 M 644 inline file3/file5
748 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
749 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
750 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
752 test_expect_success \
753 'N: copy then modify subdirectory' \
754 'git-fast-import <input &&
755 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
756 compare_diff_raw expect actual'
758 cat >input <<INPUT_END
760 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
765 from refs/heads/branch^0
766 M 644 inline file2/file5
776 test_expect_success \
777 'N: copy dirty subdirectory' \
778 'git-fast-import <input &&
779 test `git-rev-parse N2^{tree}` = `git-rev-parse N3^{tree}`'
785 cat >input <<INPUT_END
788 # -- ignore all of this text
789 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
790 # $GIT_COMMITTER_NAME has inserted here for his benefit.
795 # don't forget the import blank line!
797 # yes, we started from our usual base of branch^0.
799 from refs/heads/branch^0
800 # and we need to reuse file2/file5 from N3 above.
801 M 644 inline file2/file5
802 # otherwise the tree will be different
807 # don't forget to copy file2 to file3
810 # or to delete file5 from file2.
816 test_expect_success \
817 'O: comments are all skipped' \
818 'git-fast-import <input &&
819 test `git-rev-parse N3` = `git-rev-parse O1`'
821 cat >input <<INPUT_END
823 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
827 from refs/heads/branch^0
828 M 644 inline file2/file5
837 test_expect_success \
838 'O: blank lines not necessary after data commands' \
839 'git-fast-import <input &&
840 test `git-rev-parse N3` = `git-rev-parse O2`'
842 test_expect_success \
843 'O: repack before next test' \
846 cat >input <<INPUT_END
848 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
853 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
860 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
866 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
870 reset refs/tags/O3-2nd
874 cat >expect <<INPUT_END
880 test_expect_success \
881 'O: blank lines not necessary after other commands' \
882 'git-fast-import <input &&
883 test 8 = `find .git/objects/pack -type f | wc -l` &&
884 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
885 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
886 git diff expect actual'
888 cat >input <<INPUT_END
890 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
895 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
899 progress Two commits down, 2 to go!
901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
905 progress Three commits down, 1 to go!
907 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
913 test_expect_success \
914 'O: progress outputs as requested by input' \
915 'git-fast-import <input >actual &&
916 grep "progress " <input >expect &&
917 git diff expect actual'