Code

i18n: git-revert "Your local changes" message
[git.git] / t / t9300-fast-import.sh
index 5a1925f690fe309436a06534addf26a30bc10e1f..52ac0e56dce12016ab03155bd16b2b66b062fca3 100755 (executable)
@@ -7,6 +7,23 @@ 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'
 
@@ -902,6 +919,48 @@ test_expect_success \
         git diff-tree -C --find-copies-harder -r N4 N6 >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 </dev/null) &&
+        cat >input <<-INPUT_END &&
+       commit refs/heads/N-delete
+       committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+       data <<COMMIT
+       collect data to be deleted
+       COMMIT
+
+       deleteall
+       M 100644 inline foo/bar/baz
+       data <<DATA_END
+       hello
+       DATA_END
+       C "foo/bar/baz" "foo/bar/qux"
+       C "foo/bar/baz" "foo/bar/quux/1"
+       C "foo/bar/baz" "foo/bar/quuux"
+       M 040000 $empty_tree foo/bar/quux
+       M 040000 $empty_tree foo/bar/quuux
+
+       commit refs/heads/N-delete
+       committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+       data <<COMMIT
+       delete subdirectory
+       COMMIT
+
+       M 040000 $empty_tree foo/bar/qux
+       INPUT_END
+        git fast-import <input &&
+        git rev-list N-delete |
+               git diff-tree -r --stdin --root --always |
+               sed -e "s/$_x40/OBJID/g" >actual &&
+        test_cmp expect actual'
+
 test_expect_success \
        'N: modify copied tree' \
        'cat >expect <<-\EOF &&
@@ -1689,6 +1748,61 @@ test_expect_success \
     '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 </dev/null &&
+       echo "feature import-marks=nonexistent.marks" |
+       test_must_fail git fast-import
+'
+
+test_expect_success 'R: import and output marks can be the same file' '
+       rm -f io.marks &&
+       blob=$(echo hi | git hash-object --stdin) &&
+       cat >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
+'
+
 cat >input << EOF
 feature import-marks=marks.out
 feature export-marks=marks.new
@@ -1888,44 +2002,41 @@ test_expect_success PIPE 'R: copy using cat-file' '
        rm -f blobs &&
        cat >frontend <<-\FRONTEND_END &&
        #!/bin/sh
-       cat <<EOF &&
-       feature cat-blob
-       blob
-       mark :1
-       data <<BLOB
-       EOF
-       cat big
-       cat <<EOF
-       BLOB
-       cat-blob :1
-       EOF
-
-       read blob_id type size <&3 &&
-       echo "$blob_id $type $size" >response &&
-       dd of=blob bs=1 count=$size <&3 &&
-       read newline <&3 &&
-
-       cat <<EOF &&
-       commit refs/heads/copied
-       committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-       data <<COMMIT
-       copy big file as file3
-       COMMIT
-       M 644 inline file3
-       data <<BLOB
-       EOF
-       cat blob &&
-       cat <<EOF
-       BLOB
-       EOF
        FRONTEND_END
 
        mkfifo blobs &&
        (
                export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
-               sh frontend 3<blobs |
-               git fast-import --cat-blob-fd=3 3>blobs
-       ) &&
+               cat <<-\EOF &&
+               feature cat-blob
+               blob
+               mark :1
+               data <<BLOB
+               EOF
+               cat big &&
+               cat <<-\EOF &&
+               BLOB
+               cat-blob :1
+               EOF
+
+               read blob_id type size <&3 &&
+               echo "$blob_id $type $size" >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 <<COMMIT
+               copy big file as file3
+               COMMIT
+               M 644 inline file3
+               data <<BLOB
+               EOF
+               cat blob &&
+               echo BLOB
+       ) 3<blobs |
+       git fast-import --cat-blob-fd=3 3>blobs &&
        git show copied:file3 >actual &&
        test_cmp expect.response response &&
        test_cmp big actual
@@ -1953,7 +2064,7 @@ test_expect_success PIPE 'R: print blob mid-commit' '
                EOF
 
                read blob_id type size <&3 &&
-               dd of=actual bs=1 count=$size <&3 &&
+               head_c $size >actual <&3 &&
                read newline <&3 &&
 
                echo
@@ -1988,7 +2099,7 @@ test_expect_success PIPE 'R: print staged blob within commit' '
                echo "cat-blob $to_get" &&
 
                read blob_id type size <&3 &&
-               dd of=actual bs=1 count=$size <&3 &&
+               head_c $size >actual <&3 &&
                read newline <&3 &&
 
                echo deleteall