#!/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 verify_packs () { for p in .git/objects/pack/*.pack do git verify-pack "$@" "$p" || return done } 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 "$@"' ### ### series A ### test_expect_success 'empty stream succeeds' ' git config fastimport.unpackLimit 0 && git fast-import input <<-INPUT_END && blob mark :2 data < $GIT_COMMITTER_DATE data <expect <<-EOF && author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE initial EOF git cat-file commit master | sed 1d >actual && test_cmp expect actual ' test_expect_success 'A: verify tree' ' cat >expect <<-EOF && 100644 blob file2 100644 blob file3 100755 blob file4 EOF git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual ' test_expect_success 'A: verify file2' ' echo "$file2_data" >expect && git cat-file blob master:file2 >actual && test_cmp expect actual ' test_expect_success 'A: verify file3' ' echo "$file3_data" >expect && git cat-file blob master:file3 >actual && test_cmp expect actual ' test_expect_success 'A: verify file4' ' printf "$file4_data" >expect && git cat-file blob master:file4 >actual && test_cmp expect actual ' test_expect_success 'A: verify tag/series-A' ' cat >expect <<-EOF && object $(git rev-parse refs/heads/master) type commit tag series-A An annotated tag without a tagger EOF git cat-file tag tags/series-A >actual && test_cmp expect actual ' test_expect_success 'A: verify tag/series-A-blob' ' cat >expect <<-EOF && object $(git rev-parse refs/heads/master:file3) type blob tag series-A-blob An annotated tag that annotates a blob. EOF git cat-file tag tags/series-A-blob >actual && test_cmp expect actual ' test_expect_success 'A: verify marks output' ' cat >expect <<-EOF && :2 $(git rev-parse --verify master:file2) :3 $(git rev-parse --verify master:file3) :4 $(git rev-parse --verify master:file4) :5 $(git rev-parse --verify master^0) EOF test_cmp expect marks.out ' test_expect_success 'A: verify marks import' ' git fast-import \ --import-marks=marks.out \ --export-marks=marks.new \ input <<-INPUT_END && tag series-A-blob-2 from $(git rev-parse refs/heads/master:file3) data < 0 +0000 data 0 M 644 :6 new_blob #pretend we got sha1 from fast-import ls "new_blob" tag series-A-blob-3 from $new_blob data <expect <<-EOF && object $(git rev-parse refs/heads/master:file3) type blob tag series-A-blob-2 Tag blob by sha1. object $new_blob type blob tag series-A-blob-3 Tag new_blob. EOF git fast-import actual && git cat-file tag tags/series-A-blob-3 >>actual && test_cmp expect actual ' test_expect_success 'A: verify marks import does not crash' ' test_tick && cat >input <<-INPUT_END && commit refs/heads/verify--import-marks committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2 EOF git diff-tree -M -r master verify--import-marks >actual && compare_diff_raw expect actual && test $(git rev-parse --verify master:file2) \ = $(git rev-parse --verify verify--import-marks:copy-of-file2) ' test_expect_success 'A: export marks with large values' ' test_tick && mt=$(git hash-object --stdin < /dev/null) && >input.blob && >marks.exp && >tree.exp && cat >input.commit <<-EOF && commit refs/heads/verify--dump-marks committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <>input.blob <<-EOF && blob mark :$l data 0 blob mark :$m data 0 blob mark :$n data 0 EOF echo "M 100644 :$l l$i" >>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)) || return 1 done && sort tree.exp > tree.exp_s && 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_expect_success 'B: fail on invalid blob sha1' ' test_tick && cat >input <<-INPUT_END && commit refs/heads/branch mark :1 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit TEMP_TAG committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/empty-committer-1 committer <> $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/empty-committer-2 committer $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/invalid-committer committer Name email> $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/invalid-committer committer Name $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/invalid-committer committer Name > $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/invalid-committer committer Name input <<-INPUT_END && commit refs/heads/invalid-committer committer Name $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/branch committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && parent $(git rev-parse --verify master^0) author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE second EOF git cat-file commit branch | sed 1d >actual && test_cmp expect actual ' test_expect_success 'C: validate rename result' ' cat >expect <<-EOF && :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3 EOF git diff-tree -M -r master branch >actual && compare_diff_raw expect actual ' ### ### series D ### test_expect_success 'D: inline data in commit' ' test_tick && cat >input <<-INPUT_END && commit refs/heads/branch committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A newdir/exec.sh :000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A newdir/interesting EOF git diff-tree -M -r branch^ branch >actual && compare_diff_raw expect actual ' test_expect_success 'D: verify file5' ' echo "$file5_data" >expect && git cat-file blob branch:newdir/interesting >actual && test_cmp expect actual ' test_expect_success 'D: verify file6' ' echo "$file6_data" >expect && git cat-file blob branch:newdir/exec.sh >actual && test_cmp expect actual ' ### ### series E ### test_expect_success 'E: rfc2822 date, --date-format=raw' ' cat >input <<-INPUT_END && commit refs/heads/branch author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 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 <<-EOF && author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500 RFC 2822 type date EOF git cat-file commit branch | sed 1,2d >actual && test_cmp expect actual ' ### ### series F ### test_expect_success 'F: non-fast-forward update skips' ' old_branch=$(git rev-parse --verify branch^0) && test_tick && cat >input <<-INPUT_END && commit refs/heads/branch committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && tree $(git rev-parse branch~1^{tree}) parent $(git rev-parse branch~1) author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE losing things already? EOF git cat-file commit other >actual && test_cmp expect actual ' ### ### series G ### test_expect_success 'G: non-fast-forward update forced' ' old_branch=$(git rev-parse --verify branch^0) && test_tick && cat >input <<-INPUT_END && commit refs/heads/branch committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/H committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh EOF git diff-tree -M -r H^ H >actual && compare_diff_raw expect actual ' test_expect_success 'H: verify file' ' echo "$file5_data" >expect && git cat-file blob H:h/e/l/lo >actual && test_cmp expect actual ' ### ### series I ### test_expect_success 'I: export-pack-edges' ' cat >input <<-INPUT_END && commit refs/heads/export-boundary committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary) EOF sed -e s/pack-.*pack/pack-.pack/ edges.list >actual && test_cmp expect actual ' ### ### series J ### test_expect_success 'J: reset existing branch creates empty commit' ' cat >input <<-INPUT_END && commit refs/heads/J committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <input <<-INPUT_END && reset refs/heads/J2 tag wrong_tag from refs/heads/J2 data <input <<-INPUT_END && commit refs/heads/K committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <input <<-INPUT_END && blob mark :1 data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <expect <<-EXPECT_END && :100644 100644 4268632... 55d3a52... M b. :040000 040000 0ae5cac... 443c768... M b :100644 100644 4268632... 55d3a52... M ba EXPECT_END git fast-import output && test_cmp expect output ' test_expect_success 'L: nested tree copy does not corrupt deltas' ' cat >input <<-INPUT_END && blob mark :1 data < 1112912473 -0700 data < 1112912473 -0700 data <expect <<-\EOF && g/b/f g/b/h EOF test_when_finished "git update-ref -d refs/heads/L2" && git fast-import tmp && cat tmp | cut -f 2 >actual && test_cmp expect actual && git fsck $(git rev-parse L2) ' ### ### series M ### test_expect_success 'M: rename file in same subdirectory' ' test_tick && cat >input <<-INPUT_END && commit refs/heads/M1 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f EOF git fast-import actual && compare_diff_raw expect actual ' test_expect_success 'M: rename file to new subdirectory' ' cat >input <<-INPUT_END && commit refs/heads/M2 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you EOF git fast-import actual && compare_diff_raw expect actual ' test_expect_success 'M: rename subdirectory to new subdirectory' ' cat >input <<-INPUT_END && commit refs/heads/M3 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you EOF git fast-import actual && compare_diff_raw expect actual ' test_expect_success 'M: rename root to subdirectory' ' cat >input <<-INPUT_END && commit refs/heads/M4 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting EOF git fast-import actual && cat actual && compare_diff_raw expect actual ' ### ### series N ### test_expect_success 'N: copy file in same subdirectory' ' test_tick && cat >input <<-INPUT_END && commit refs/heads/N1 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f EOF git fast-import actual && compare_diff_raw expect actual ' test_expect_success 'N: copy then modify subdirectory' ' cat >input <<-INPUT_END && commit refs/heads/N2 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <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 git fast-import actual && compare_diff_raw expect actual ' test_expect_success 'N: copy dirty subdirectory' ' cat >input <<-INPUT_END && commit refs/heads/N3 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $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 PIPE 'N: read and copy directory' ' cat >expect <<-\EOF && :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf EOF git update-ref -d refs/heads/N4 && rm -f backflow && mkfifo backflow && ( exec $GIT_COMMITTER_DATE data <backflow && git diff-tree -C --find-copies-harder -r N4^ N4 >actual && compare_diff_raw expect actual ' test_expect_success PIPE 'N: empty directory reads as missing' ' cat <<-\EOF >expect && OBJNAME :000000 100644 OBJNAME OBJNAME A unrelated EOF echo "missing src" >expect.response && git update-ref -d refs/heads/read-empty && rm -f backflow && mkfifo backflow && ( exec $GIT_COMMITTER_DATE data <response && cat <<-\EOF D dst1 D dst2 EOF ) | git fast-import --cat-blob-fd=3 3>backflow && test_cmp expect.response response && git rev-list read-empty | git diff-tree -r --root --stdin | sed "s/$OID_REGEX/OBJNAME/g" >actual && test_cmp 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: copy root by path' ' cat >expect <<-\EOF && :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting EOF cat >input <<-INPUT_END && commit refs/heads/N-copy-root-path 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 < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $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 ### test_expect_success 'O: comments are all skipped' ' cat >input <<-INPUT_END && #we will commit refs/heads/O1 # -- ignore all of this text committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE # $GIT_COMMITTER_NAME has inserted here for his benefit. data <input <<-INPUT_END && commit refs/heads/O2 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/O3 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <expect <<-INPUT_END && string of empty commits INPUT_END git fast-import actual && test_cmp expect actual ' test_expect_success 'O: progress outputs as requested by input' ' cat >input <<-INPUT_END && commit refs/heads/O4 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $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) ### test_expect_success 'P: superproject & submodule mix' ' cat >input <<-INPUT_END && blob mark :1 data 10 test file reset refs/heads/sub commit refs/heads/sub mark :2 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $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 git fast-import input <<-INPUT_END && blob mark :1 data < $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 git branch -D sub && git gc && git prune && git fast-import input <<-INPUT_END && commit refs/heads/subuse3 mark :1 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <input <<-INPUT_END && blob mark :1 data < $GIT_COMMITTER_DATE data <input <<-INPUT_END && blob mark :2 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 < $GIT_COMMITTER_DATE data <expect <<-EOF && author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE first (:3) EOF git cat-file commit notes-test~2 | sed 1d >actual && test_cmp expect actual ' test_expect_success 'Q: verify second commit' ' cat >expect <<-EOF && parent $commit1 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE second (:5) EOF git cat-file commit notes-test^ | sed 1d >actual && test_cmp expect actual ' test_expect_success 'Q: verify third commit' ' cat >expect <<-EOF && parent $commit2 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE third (:6) EOF git cat-file commit notes-test | sed 1d >actual && test_cmp expect actual ' test_expect_success 'Q: verify first notes commit' ' cat >expect <<-EOF && author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE notes (:9) EOF git cat-file commit refs/notes/foobar~2 | sed 1d >actual && test_cmp expect actual ' test_expect_success 'Q: verify first notes tree' ' cat >expect.unsorted <<-EOF && 100644 blob $commit1 100644 blob $commit2 100644 blob $commit3 EOF cat expect.unsorted | sort >expect && git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual ' test_expect_success 'Q: verify first note for first commit' ' echo "$note1_data" >expect && git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual ' test_expect_success 'Q: verify first note for second commit' ' echo "$note2_data" >expect && git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual ' test_expect_success 'Q: verify first note for third commit' ' echo "$note3_data" >expect && git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual ' test_expect_success 'Q: verify second notes commit' ' cat >expect <<-EOF && parent $(git rev-parse --verify refs/notes/foobar~2) author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE notes (:10) EOF git cat-file commit refs/notes/foobar^ | sed 1d >actual && test_cmp expect actual ' test_expect_success 'Q: verify second notes tree' ' cat >expect.unsorted <<-EOF && 100644 blob $commit1 100644 blob $commit2 100644 blob $commit3 EOF cat expect.unsorted | sort >expect && git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual ' test_expect_success 'Q: verify second note for first commit' ' echo "$note1b_data" >expect && git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual ' test_expect_success 'Q: verify first note for second commit' ' echo "$note2_data" >expect && git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual ' test_expect_success 'Q: verify first note for third commit' ' echo "$note3_data" >expect && git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual ' test_expect_success 'Q: verify third notes commit' ' cat >expect <<-EOF && author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE notes (:11) EOF git cat-file commit refs/notes/foobar2 | sed 1d >actual && test_cmp expect actual ' test_expect_success 'Q: verify third notes tree' ' cat >expect.unsorted <<-EOF && 100644 blob $commit1 EOF cat expect.unsorted | sort >expect && git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual ' test_expect_success 'Q: verify third note for first commit' ' echo "$note1c_data" >expect && git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual ' test_expect_success 'Q: verify fourth notes commit' ' cat >expect <<-EOF && parent $(git rev-parse --verify refs/notes/foobar^) author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE notes (:12) EOF git cat-file commit refs/notes/foobar | sed 1d >actual && test_cmp expect actual ' test_expect_success 'Q: verify fourth notes tree' ' cat >expect.unsorted <<-EOF && 100644 blob $commit2 EOF cat expect.unsorted | sort >expect && git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual && test_cmp expect actual ' test_expect_success 'Q: verify second note for second commit' ' echo "$note2b_data" >expect && git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual ' test_expect_success 'Q: deny note on empty branch' ' cat >input <<-EOF && reset refs/heads/Q0 commit refs/heads/note-Q0 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <input <<-EOF && feature no-such-feature-exists EOF test_must_fail git fast-import input <<-EOF && feature date-format=now EOF git fast-import input <<-EOF && blob data 3 hi feature date-format=now EOF test_must_fail git fast-import input <<-EOF && feature import-marks=git.marks feature import-marks=git2.marks EOF test_must_fail git fast-import input <<-EOF && feature export-marks=git.marks blob mark :1 data 3 hi EOF cat input | git fast-import && grep :1 git.marks ' test_expect_success 'R: export-marks options can be overridden by commandline options' ' cat input | git fast-import --export-marks=other.marks && grep :1 other.marks ' test_expect_success 'R: catch typo in marks file name' ' test_must_fail git fast-import --import-marks=nonexistent.marks expect <<-EOF && :1 $blob :2 $blob EOF git fast-import --export-marks=io.marks <<-\EOF && blob mark :1 data 3 hi EOF git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && blob mark :2 data 3 hi EOF test_cmp expect io.marks ' test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' ' rm -f io.marks && test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF blob mark :1 data 3 hi EOF ' test_expect_success 'R: --import-marks-if-exists' ' rm -f io.marks && blob=$(echo hi | git hash-object --stdin) && echo ":1 $blob" >expect && git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF && blob mark :1 data 3 hi EOF test_cmp expect io.marks ' test_expect_success 'R: feature import-marks-if-exists' ' rm -f io.marks && git fast-import --export-marks=io.marks <<-\EOF && feature import-marks-if-exists=not_io.marks EOF test_must_be_empty io.marks && blob=$(echo hi | git hash-object --stdin) && echo ":1 $blob" >io.marks && echo ":1 $blob" >expect && echo ":2 $blob" >>expect && git fast-import --export-marks=io.marks <<-\EOF && feature import-marks-if-exists=io.marks blob mark :2 data 3 hi EOF test_cmp expect io.marks && echo ":3 $blob" >>expect && git fast-import --import-marks=io.marks \ --export-marks=io.marks <<-\EOF && feature import-marks-if-exists=not_io.marks blob mark :3 data 3 hi EOF test_cmp expect io.marks && git fast-import --import-marks-if-exists=not_io.marks \ --export-marks=io.marks <<-\EOF && feature import-marks-if-exists=io.marks EOF test_must_be_empty io.marks ' test_expect_success 'R: import to output marks works without any content' ' cat >input <<-EOF && feature import-marks=marks.out feature export-marks=marks.new EOF cat input | git fast-import && test_cmp marks.out marks.new ' test_expect_success 'R: import marks prefers commandline marks file over the stream' ' cat >input <<-EOF && feature import-marks=nonexistent.marks feature export-marks=marks.new EOF cat input | git fast-import --import-marks=marks.out && test_cmp marks.out marks.new ' test_expect_success 'R: multiple --import-marks= should be honoured' ' cat >input <<-EOF && feature import-marks=nonexistent.marks feature export-marks=combined.marks EOF head -n2 marks.out > one.marks && tail -n +3 marks.out > two.marks && git fast-import --import-marks=one.marks --import-marks=two.marks input <<-EOF && feature relative-marks feature import-marks=relative.in feature export-marks=relative.out EOF mkdir -p .git/info/fast-import/ && cp marks.new .git/info/fast-import/relative.in && git fast-import input <<-EOF && feature relative-marks feature import-marks=relative.in feature no-relative-marks feature export-marks=non-relative.out EOF git fast-import 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 !MINGW '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_must_be_empty actual.1 && git fast-import 3>actual.3 >actual.1 <<-EOF && option cat-blob-fd=3 cat-blob $blob EOF test_must_be_empty actual.3 && test_cmp expect actual.1 ' test_expect_success !MINGW 'R: print mark for new blob' ' echo "effluentish" | git hash-object --stdin >expect && git fast-import --cat-blob-fd=6 6>actual <<-\EOF && blob mark :1 data <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 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 && test_copy_bytes $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 ' test_expect_success 'R: quiet option results in no stats being output' ' cat >input <<-EOF && option git quiet blob data 3 hi EOF cat input | git fast-import 2> output && test_must_be_empty output ' test_expect_success 'R: feature done means terminating "done" is mandatory' ' echo feature done | test_must_fail git fast-import && test_must_fail git fast-import --done expect <<-\EOF && OBJID :000000 100644 OBJID OBJID A hello.c :000000 100644 OBJID OBJID A hello2.c EOF git fast-import <<-EOF && commit refs/heads/done-ends committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <actual && test_cmp expect actual ' test_expect_success 'R: die on unknown option' ' cat >input <<-EOF && option git non-existing-option EOF test_must_fail git fast-import input <<-EOF && option non-existing-vcs non-existing-option EOF git fast-import expect <<-EOF && :3 0000000000000000000000000000000000000000 :1 $blob :2 $blob EOF cp expect io.marks && test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && EOF test_cmp expect io.marks ' ## ## R: very large blobs ## test_expect_success 'R: blob bigger than threshold' ' blobsize=$((2*1024*1024 + 53)) && test-tool genrandom bar $blobsize >expect && cat >input <<-INPUT_END && commit refs/heads/big-file committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <>input && cat >>input <<-INPUT_END && M 644 inline big2 data $blobsize INPUT_END cat expect >>input && echo >>input && test_create_repo R && git --git-dir=R/.git config fastimport.unpackLimit 0 && git --git-dir=R/.git fast-import --big-file-threshold=1 ../verify ) ' test_expect_success 'R: verify written objects' ' git --git-dir=R/.git cat-file blob big-file:big1 >actual && test_cmp_bin 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 ' ### ### series S ### # # Make sure missing spaces and EOLs after mark references # cause errors. # # Setup: # # 1--2--4 # \ / # -3- # # commit marks: 301, 302, 303, 304 # blob marks: 403, 404, resp. # note mark: 202 # # The error message when a space is missing not at the # end of the line is: # # Missing space after .. # # or when extra characters come after the mark at the end # of the line: # # Garbage after .. # # or when the dataref is neither "inline " or a known SHA1, # # Invalid dataref .. # test_expect_success 'S: initialize for S tests' ' test_tick && cat >input <<-INPUT_END && commit refs/heads/S mark :301 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <err && commit refs/heads/S committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && commit refs/heads/S committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && commit refs/heads/S committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && commit refs/heads/S committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && commit refs/heads/S committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && commit refs/heads/S committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && commit refs/heads/Snotes committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && commit refs/heads/S2 mark :303 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <err && commit refs/heads/S mark :304 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && tag refs/tags/Stag from :302x tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <err && cat-blob :403x EOF test_i18ngrep "after mark" err ' # # ls markref # test_expect_success 'S: ls with garbage after mark must fail' ' test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && ls :302x hello.c EOF test_i18ngrep "space after mark" err ' test_expect_success 'S: ls with garbage after sha1 must fail' ' sha1=$(grep :302 marks | cut -d\ -f2) && test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && ls ${sha1}x hello.c EOF test_i18ngrep "space after tree-ish" err ' ### ### series T (ls) ### # Setup is carried over from series S. test_expect_success 'T: ls root tree' ' sed -e "s/Z\$//" >expect <<-EOF && 040000 tree $(git rev-parse S^{tree}) Z EOF sha1=$(git rev-parse --verify S) && git fast-import --import-marks=marks <<-EOF >actual && ls $sha1 "" EOF test_cmp expect actual ' test_expect_success 'T: delete branch' ' git branch to-delete && git fast-import <<-EOF && reset refs/heads/to-delete from 0000000000000000000000000000000000000000 EOF test_must_fail git rev-parse --verify refs/heads/to-delete ' test_expect_success 'T: empty reset doesnt delete branch' ' git branch not-to-delete && git fast-import <<-EOF && reset refs/heads/not-to-delete EOF git show-ref && git rev-parse --verify refs/heads/not-to-delete ' ### ### series U (filedelete) ### test_expect_success 'U: initialize for U tests' ' cat >input <<-INPUT_END && commit refs/heads/U committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <input <<-INPUT_END && commit refs/heads/U committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt EOF git diff-tree -M -r U^1 U >actual && compare_diff_raw expect actual ' test_expect_success 'U: filedelete directory succeeds' ' cat >input <<-INPUT_END && commit refs/heads/U committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt EOF git diff-tree -M -r U^1 U >actual && compare_diff_raw expect actual ' test_expect_success 'U: filedelete root succeeds' ' cat >input <<-INPUT_END && commit refs/heads/U committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect <<-EOF && :100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c EOF git diff-tree -M -r U^1 U >actual && compare_diff_raw expect actual ' ### ### series V (checkpoint) ### # The commands in input_file should not produce any output on the file # descriptor set with --cat-blob-fd (or stdout if unspecified). # # To make sure you're observing the side effects of checkpoint *before* # fast-import terminates (and thus writes out its state), check that the # fast-import process is still running using background_import_still_running # *after* evaluating the test conditions. background_import_then_checkpoint () { options=$1 input_file=$2 mkfifo V.input exec 8<>V.input rm V.input mkfifo V.output exec 9<>V.output rm V.output git fast-import $options <&8 >&9 & echo $! >V.pid # We don't mind if fast-import has already died by the time the test # ends. test_when_finished " exec 8>&-; exec 9>&-; kill $(cat V.pid) && wait $(cat V.pid) true" # Start in the background to ensure we adhere strictly to (blocking) # pipes writing sequence. We want to assume that the write below could # block, e.g. if fast-import blocks writing its own output to &9 # because there is no reader on &9 yet. ( cat "$input_file" echo "checkpoint" echo "progress checkpoint" ) >&8 & error=1 ;# assume the worst while read output <&9 do if test "$output" = "progress checkpoint" then error=0 break fi # otherwise ignore cruft echo >&2 "cruft: $output" done if test $error -eq 1 then false fi } background_import_still_running () { if ! kill -0 "$(cat V.pid)" then echo >&2 "background fast-import terminated too early" false fi } test_expect_success PIPE 'V: checkpoint helper does not get stuck with extra output' ' cat >input <<-INPUT_END && progress foo progress bar INPUT_END background_import_then_checkpoint "" input && background_import_still_running ' test_expect_success PIPE 'V: checkpoint updates refs after reset' ' cat >input <<-\INPUT_END && reset refs/heads/V from refs/heads/U INPUT_END background_import_then_checkpoint "" input && test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" && background_import_still_running ' test_expect_success PIPE 'V: checkpoint updates refs and marks after commit' ' cat >input <<-INPUT_END && commit refs/heads/V mark :1 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data 0 from refs/heads/U INPUT_END background_import_then_checkpoint "--export-marks=marks.actual" input && echo ":1 $(git rev-parse --verify V)" >marks.expected && test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" && test_cmp marks.expected marks.actual && background_import_still_running ' # Re-create the exact same commit, but on a different branch: no new object is # created in the database, but the refs and marks still need to be updated. test_expect_success PIPE 'V: checkpoint updates refs and marks after commit (no new objects)' ' cat >input <<-INPUT_END && commit refs/heads/V2 mark :2 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data 0 from refs/heads/U INPUT_END background_import_then_checkpoint "--export-marks=marks.actual" input && echo ":2 $(git rev-parse --verify V2)" >marks.expected && test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" && test_cmp marks.expected marks.actual && background_import_still_running ' test_expect_success PIPE 'V: checkpoint updates tags after tag' ' cat >input <<-INPUT_END && tag Vtag from refs/heads/V tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data 0 INPUT_END background_import_then_checkpoint "" input && git show-ref -d Vtag && background_import_still_running ' ### ### series W (get-mark and empty orphan commits) ### cat >>W-input <<-W_INPUT_END commit refs/heads/W-branch mark :1 author Full Name 1000000000 +0100 committer Full Name 1000000000 +0100 data 27 Intentionally empty commit LFsget-mark :1 W_INPUT_END test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' ' sed -e s/LFs// W-input | tr L "\n" | git fast-import ' test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' ' sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import ' test_expect_success !MINGW 'W: get-mark & empty orphan commit with ugly second newline' ' # Technically, this should fail as it has too many linefeeds # according to the grammar in fast-import.txt. But, for whatever # reason, it works. Since using the correct number of newlines # does not work with older (pre-2.22) versions of git, allow apps # that used this second-newline workaround to keep working by # checking it with this test... sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import ' test_expect_success !MINGW 'W: get-mark & empty orphan commit with erroneous third newline' ' # ...but do NOT allow more empty lines than that (see previous test). sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import ' ### ### series X (other new features) ### test_expect_success 'X: handling encoding' ' test_tick && cat >input <<-INPUT_END && commit refs/heads/encoding committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE encoding iso-8859-7 data <>input && git fast-import