#!/bin/sh # # Copyright (c) 2007 Shawn Pearce # test_description='test git fast-import utility' . ./test-lib.sh . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash # Print $1 bytes from stdin to stdout. # # This could be written as "head -c $1", but IRIX "head" does not # support the -c option. head_c () { perl -e ' my $len = $ARGV[1]; while ($len > 0) { my $s; my $nread = sysread(STDIN, $s, $len); die "cannot read: $!" unless defined($nread); print $s; $len -= $nread; } ' - "$1" } file2_data='file2 second line of EOF' file3_data='EOF in 3rd file END' file4_data=abcd file4_len=4 file5_data='an inline file. we should see it later.' file6_data='#!/bin/sh echo "$@"' >empty ### ### series A ### test_tick test_expect_success 'empty stream succeeds' ' git fast-import input < $GIT_COMMITTER_DATE data <expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE initial EOF test_expect_success \ 'A: verify commit' \ 'git cat-file commit master | sed 1d >actual && test_cmp expect actual' cat >expect <actual && test_cmp expect actual' echo "$file2_data" >expect test_expect_success \ 'A: verify file2' \ 'git cat-file blob master:file2 >actual && test_cmp expect actual' echo "$file3_data" >expect test_expect_success \ 'A: verify file3' \ 'git cat-file blob master:file3 >actual && test_cmp expect actual' printf "$file4_data" >expect test_expect_success \ 'A: verify file4' \ 'git cat-file blob master:file4 >actual && test_cmp expect actual' cat >expect <actual && test_cmp expect actual ' cat >expect <input < $GIT_COMMITTER_DATE data <expect <actual test_expect_success \ 'A: verify diff' \ 'compare_diff_raw expect actual && test `git rev-parse --verify master:file2` \ = `git rev-parse --verify verify--import-marks:copy-of-file2`' test_tick mt=$(git hash-object --stdin < /dev/null) : >input.blob : >marks.exp : >tree.exp cat >input.commit < $GIT_COMMITTER_DATE data <>input.blob <>input.commit echo "M 100644 :$m m$i" >>input.commit echo "M 100644 :$n n$i" >>input.commit echo ":$l $mt" >>marks.exp echo ":$m $mt" >>marks.exp echo ":$n $mt" >>marks.exp printf "100644 blob $mt\tl$i\n" >>tree.exp printf "100644 blob $mt\tm$i\n" >>tree.exp printf "100644 blob $mt\tn$i\n" >>tree.exp l=$(($l + $l)) m=$(($m + $m)) n=$(($l + $n)) i=$((1 + $i)) done sort tree.exp > tree.exp_s test_expect_success 'A: export marks with large values' ' cat input.blob input.commit | git fast-import --export-marks=marks.large && git ls-tree refs/heads/verify--dump-marks >tree.out && test_cmp tree.exp_s tree.out && test_cmp marks.exp marks.large' ### ### series B ### test_tick cat >input < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data <expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE second EOF test_expect_success \ 'C: verify commit' \ 'git cat-file commit branch | sed 1d >actual && test_cmp expect actual' cat >expect <actual test_expect_success \ 'C: validate rename result' \ 'compare_diff_raw expect actual' ### ### series D ### test_tick cat >input < $GIT_COMMITTER_DATE data <expect <actual test_expect_success \ 'D: validate new files added' \ 'compare_diff_raw expect actual' echo "$file5_data" >expect test_expect_success \ 'D: verify file5' \ 'git cat-file blob branch:newdir/interesting >actual && test_cmp expect actual' echo "$file6_data" >expect test_expect_success \ 'D: verify file6' \ 'git cat-file blob branch:newdir/exec.sh >actual && test_cmp expect actual' ### ### series E ### cat >input < Tue Feb 6 11:22:18 2007 -0500 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500 data <expect < 1170778938 -0500 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500 RFC 2822 type date EOF test_expect_success \ 'E: verify commit' \ 'git cat-file commit branch | sed 1,2d >actual && test_cmp expect actual' ### ### series F ### old_branch=`git rev-parse --verify branch^0` test_tick cat >input < $GIT_COMMITTER_DATE data <expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE losing things already? EOF test_expect_success \ 'F: verify other commit' \ 'git cat-file commit other >actual && test_cmp expect actual' ### ### series G ### old_branch=`git rev-parse --verify branch^0` test_tick cat >input < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data <expect <actual test_expect_success \ 'H: validate old files removed, new files added' \ 'compare_diff_raw expect actual' echo "$file5_data" >expect test_expect_success \ 'H: verify file' \ 'git cat-file blob H:h/e/l/lo >actual && test_cmp expect actual' ### ### series I ### cat >input < $GIT_COMMITTER_DATE data <expect <actual && test_cmp expect actual' ### ### series J ### cat >input < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <expect <output && test_cmp expect output' ### ### series M ### test_tick cat >input < $GIT_COMMITTER_DATE data <expect <actual && compare_diff_raw expect actual' cat >input < $GIT_COMMITTER_DATE data <expect <actual && compare_diff_raw expect actual' cat >input < $GIT_COMMITTER_DATE data <expect <actual && compare_diff_raw expect actual' ### ### series N ### test_tick cat >input < $GIT_COMMITTER_DATE data <expect <actual && compare_diff_raw expect actual' cat >input < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <expect <actual && compare_diff_raw expect actual' cat >input < $GIT_COMMITTER_DATE data <expect <<-\EOF && :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf EOF subdir=$(git rev-parse refs/heads/branch^0:file2) && cat >input <<-INPUT_END && commit refs/heads/N4 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <actual && compare_diff_raw expect actual' test_expect_success \ 'N: copy root directory by tree hash' \ 'cat >expect <<-\EOF && :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf EOF root=$(git rev-parse refs/heads/branch^0^{tree}) && cat >input <<-INPUT_END && commit refs/heads/N6 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <actual && compare_diff_raw expect actual' test_expect_success \ 'N: delete directory by copying' \ 'cat >expect <<-\EOF && OBJID :100644 000000 OBJID OBJID D foo/bar/qux OBJID :000000 100644 OBJID OBJID A foo/bar/baz :000000 100644 OBJID OBJID A foo/bar/qux EOF empty_tree=$(git mktree input <<-INPUT_END && commit refs/heads/N-delete committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <actual && test_cmp expect actual' test_expect_success \ 'N: modify copied tree' \ 'cat >expect <<-\EOF && :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf EOF subdir=$(git rev-parse refs/heads/branch^0:file2) && cat >input <<-INPUT_END && commit refs/heads/N5 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <actual && compare_diff_raw expect actual' test_expect_success \ 'N: reject foo/ syntax' \ 'subdir=$(git rev-parse refs/heads/branch^0:file2) && test_must_fail git fast-import <<-INPUT_END commit refs/heads/N5B committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect.foo && echo hello >expect.bar && git fast-import <<-SETUP_END && commit refs/heads/N7 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <actual.foo && git show N8:foo/bar >actual.bar && test_cmp expect.foo actual.foo && test_cmp expect.bar actual.bar' test_expect_success \ 'N: extract subtree' \ 'branch=$(git rev-parse --verify refs/heads/branch^{tree}) && cat >input <<-INPUT_END && commit refs/heads/N9 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect.baz && echo hello, world >expect.qux && git fast-import <<-SETUP_END && commit refs/heads/N10 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <actual.baz && git show N11:bar/qux >actual.qux && git show N11:bar/quux >actual.quux && test_cmp expect.baz actual.baz && test_cmp expect.qux actual.qux && test_cmp expect.qux actual.quux' ### ### series O ### cat >input < $GIT_COMMITTER_DATE # $GIT_COMMITTER_NAME has inserted here for his benefit. data <input < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <expect <actual && test_cmp expect actual' cat >input < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <actual && grep "progress " expect && test_cmp expect actual' ### ### series P (gitlinks) ### cat >input < $GIT_COMMITTER_DATE data 12 sub_initial M 100644 :1 file blob mark :3 data < $GIT_COMMITTER_DATE data 8 initial from refs/heads/master M 100644 :3 .gitmodules M 160000 :2 sub blob mark :5 data 20 test file more data commit refs/heads/sub mark :6 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data 11 sub_second from :2 M 100644 :5 file commit refs/heads/subuse1 mark :7 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data 7 second from :4 M 160000 :6 sub INPUT_END test_expect_success \ 'P: supermodule & submodule mix' \ 'git fast-import input < $GIT_COMMITTER_DATE data 8 initial from refs/heads/master M 100644 :1 .gitmodules M 160000 $SUBPREV sub commit refs/heads/subuse2 mark :3 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data 7 second from :2 M 160000 $SUBLAST sub INPUT_END test_expect_success \ 'P: verbatim SHA gitlinks' \ 'git branch -D sub && git gc && git prune && git fast-import input < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data <input < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE first (:3) EOF test_expect_success \ 'Q: verify first commit' \ 'git cat-file commit notes-test~2 | sed 1d >actual && test_cmp expect actual' cat >expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE second (:5) EOF test_expect_success \ 'Q: verify second commit' \ 'git cat-file commit notes-test^ | sed 1d >actual && test_cmp expect actual' cat >expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE third (:6) EOF test_expect_success \ 'Q: verify third commit' \ 'git cat-file commit notes-test | sed 1d >actual && test_cmp expect actual' cat >expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE notes (:9) EOF test_expect_success \ 'Q: verify first notes commit' \ 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual && test_cmp expect actual' cat >expect.unsorted <expect test_expect_success \ 'Q: verify first notes tree' \ 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual' echo "$note1_data" >expect test_expect_success \ 'Q: verify first note for first commit' \ 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual' echo "$note2_data" >expect test_expect_success \ 'Q: verify first note for second commit' \ 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual' echo "$note3_data" >expect test_expect_success \ 'Q: verify first note for third commit' \ 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual' cat >expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE notes (:10) EOF test_expect_success \ 'Q: verify second notes commit' \ 'git cat-file commit refs/notes/foobar^ | sed 1d >actual && test_cmp expect actual' cat >expect.unsorted <expect test_expect_success \ 'Q: verify second notes tree' \ 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual' echo "$note1b_data" >expect test_expect_success \ 'Q: verify second note for first commit' \ 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual' echo "$note2_data" >expect test_expect_success \ 'Q: verify first note for second commit' \ 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual' echo "$note3_data" >expect test_expect_success \ 'Q: verify first note for third commit' \ 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual' cat >expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE notes (:11) EOF test_expect_success \ 'Q: verify third notes commit' \ 'git cat-file commit refs/notes/foobar2 | sed 1d >actual && test_cmp expect actual' cat >expect.unsorted <expect test_expect_success \ 'Q: verify third notes tree' \ 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual' echo "$note1c_data" >expect test_expect_success \ 'Q: verify third note for first commit' \ 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual' cat >expect < $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE notes (:12) EOF test_expect_success \ 'Q: verify fourth notes commit' \ 'git cat-file commit refs/notes/foobar | sed 1d >actual && test_cmp expect actual' cat >expect.unsorted <expect test_expect_success \ 'Q: verify fourth notes tree' \ 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual' echo "$note2b_data" >expect test_expect_success \ 'Q: verify second note for second commit' \ 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual' ### ### series R (feature and option) ### cat >input <input <input << EOF blob data 3 hi feature date-format=now EOF test_expect_success 'R: abort on receiving feature after data command' ' test_must_fail git fast-import input << EOF feature import-marks=git.marks feature import-marks=git2.marks EOF test_expect_success 'R: only one import-marks feature allowed per stream' ' test_must_fail git fast-import input << EOF feature export-marks=git.marks blob mark :1 data 3 hi EOF test_expect_success \ 'R: export-marks feature results in a marks file being created' \ 'cat input | git fast-import && grep :1 git.marks' test_expect_success \ 'R: export-marks options can be overriden by commandline options' \ 'cat input | git fast-import --export-marks=other.marks && grep :1 other.marks' cat >input << EOF feature import-marks=marks.out feature export-marks=marks.new EOF test_expect_success \ 'R: import to output marks works without any content' \ 'cat input | git fast-import && test_cmp marks.out marks.new' cat >input <input < one.marks && tail -n +3 marks.out > two.marks && git fast-import --import-marks=one.marks --import-marks=two.marks input <input <expect <<-EOF && ${blob} blob 11 yes it can EOF echo "cat-blob $blob" | git fast-import --cat-blob-fd=6 6>actual && test_cmp expect actual ' test_expect_success 'R: in-stream cat-blob-fd not respected' ' echo hello >greeting && blob=$(git hash-object -w greeting) && cat >expect <<-EOF && ${blob} blob 6 hello EOF git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF && cat-blob $blob EOF test_cmp expect actual.3 && test_cmp empty actual.1 && git fast-import 3>actual.3 >actual.1 <<-EOF && option cat-blob-fd=3 cat-blob $blob EOF test_cmp empty actual.3 && test_cmp expect actual.1 ' test_expect_success 'R: print new blob' ' blob=$(echo "yep yep yep" | git hash-object --stdin) && cat >expect <<-EOF && ${blob} blob 12 yep yep yep EOF git fast-import --cat-blob-fd=6 6>actual <<-\EOF && blob mark :1 data <expect <<-EOF && ${blob} blob 25 a new blob named by sha1 EOF git fast-import --cat-blob-fd=6 6>actual <<-EOF && blob data <big && for i in 1 2 3 do cat big big big big >bigger && cat bigger bigger bigger bigger >big || exit done ) ' test_expect_success 'R: print two blobs to stdout' ' blob1=$(git hash-object big) && blob1_len=$(wc -c expect && { cat <<-\END_PART1 && blob mark :1 data <actual && test_cmp expect actual ' test_expect_success 'setup: have pipes?' ' rm -f frob && if mkfifo frob then test_set_prereq PIPE fi ' test_expect_success PIPE 'R: copy using cat-file' ' expect_id=$(git hash-object big) && expect_len=$(wc -c expect.response && rm -f blobs && cat >frontend <<-\FRONTEND_END && #!/bin/sh FRONTEND_END mkfifo blobs && ( export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE && cat <<-\EOF && feature cat-blob blob mark :1 data <response && head_c $size >blob <&3 && read newline <&3 && cat <<-EOF && commit refs/heads/copied committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <blobs && git show copied:file3 >actual && test_cmp expect.response response && test_cmp big actual ' test_expect_success PIPE 'R: print blob mid-commit' ' rm -f blobs && echo "A blob from _before_ the commit." >expect && mkfifo blobs && ( exec 3 $GIT_COMMITTER_DATE data <actual <&3 && read newline <&3 && echo ) | git fast-import --cat-blob-fd=3 3>blobs && test_cmp expect actual ' test_expect_success PIPE 'R: print staged blob within commit' ' rm -f blobs && echo "A blob from _within_ the commit." >expect && mkfifo blobs && ( exec 3 $GIT_COMMITTER_DATE data <actual <&3 && read newline <&3 && echo deleteall ) | git fast-import --cat-blob-fd=3 3>blobs && test_cmp expect actual ' cat >input << EOF option git quiet blob data 3 hi EOF test_expect_success 'R: quiet option results in no stats being output' ' cat input | git fast-import 2> output && test_cmp empty output ' cat >input <input <expect cat >input < $GIT_COMMITTER_DATE data <>input cat >>input <>input echo >>input test_expect_success \ 'R: blob bigger than threshold' \ 'test_create_repo R && git --git-dir=R/.git fast-import --big-file-threshold=1 verify && for p in R/.git/objects/pack/*.pack; do git verify-pack -v $p >>verify || exit; done' test_expect_success \ 'R: verify written objects' \ 'git --git-dir=R/.git cat-file blob big-file:big1 >actual && test_cmp expect actual && a=$(git --git-dir=R/.git rev-parse big-file:big1) && b=$(git --git-dir=R/.git rev-parse big-file:big2) && test $a = $b' test_expect_success \ 'R: blob appears only once' \ 'n=$(grep $a verify | wc -l) && test 1 = $n' test_done