Imported Upstream version 2.10.0
[platform/upstream/git.git] / t / t5000-tar-tree.sh
index 4efaf8c..80b2387 100755 (executable)
@@ -72,7 +72,7 @@ check_tar() {
                        for header in *.paxheader
                        do
                                data=${header%.paxheader}.data &&
-                               if test -h $data -o -e $data
+                               if test -h $data || test -e $data
                                then
                                        path=$(get_pax_header $header path) &&
                                        if test -n "$path"
@@ -101,7 +101,7 @@ test_expect_success \
      ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten &&
      echo long filename >a/four$hundred &&
      mkdir a/bin &&
-     cp /bin/sh a/bin &&
+     test-genrandom "frotz" 500000 >a/bin/sh &&
      printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
      printf "A not substituted O" >a/substfile2 &&
      if test_have_prereq SYMLINKS; then
@@ -119,14 +119,10 @@ test_expect_success \
     'echo ignore me >a/ignored &&
      echo ignored export-ignore >.git/info/attributes'
 
-test_expect_success \
-    'add files to repository' \
-    'find a -type f | xargs git update-index --add &&
-     find a -type l | xargs git update-index --add &&
-     treeid=`git write-tree` &&
-     echo $treeid >treeid &&
-     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
-     git commit-tree $treeid </dev/null)'
+test_expect_success 'add files to repository' '
+       git add a &&
+       GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
+'
 
 test_expect_success 'setup export-subst' '
        echo "substfile?" export-subst >>.git/info/attributes &&
@@ -207,7 +203,7 @@ test_expect_success \
 
 test_expect_success 'clients cannot access unreachable commits' '
        test_commit unreachable &&
-       sha1=`git rev-parse HEAD` &&
+       sha1=$(git rev-parse HEAD) &&
        git reset --hard HEAD^ &&
        git archive $sha1 >remote.tar &&
        test_must_fail git archive --remote=. $sha1 >remote.tar
@@ -215,7 +211,7 @@ test_expect_success 'clients cannot access unreachable commits' '
 
 test_expect_success 'upload-archive can allow unreachable commits' '
        test_commit unreachable1 &&
-       sha1=`git rev-parse HEAD` &&
+       sha1=$(git rev-parse HEAD) &&
        git reset --hard HEAD^ &&
        git archive $sha1 >remote.tar &&
        test_config uploadarchive.allowUnreachable true &&
@@ -309,4 +305,92 @@ test_expect_success GZIP 'remote tar.gz can be disabled' '
                >remote.tar.gz
 '
 
+test_expect_success 'archive and :(glob)' '
+       git archive -v HEAD -- ":(glob)**/sh" >/dev/null 2>actual &&
+       cat >expect <<EOF &&
+a/
+a/bin/
+a/bin/sh
+EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'catch non-matching pathspec' '
+       test_must_fail git archive -v HEAD -- "*.abc" >/dev/null
+'
+
+# Pull the size and date of each entry in a tarfile using the system tar.
+#
+# We'll pull out only the year from the date; that avoids any question of
+# timezones impacting the result (as long as we keep our test times away from a
+# year boundary; our reference times are all in August).
+#
+# The output of tar_info is expected to be "<size> <year>", both in decimal. It
+# ignores the return value of tar. We have to do this, because some of our test
+# input is only partial (the real data is 64GB in some cases).
+tar_info () {
+       "$TAR" tvf "$1" |
+       awk '{
+               split($4, date, "-")
+               print $3 " " date[1]
+       }'
+}
+
+# See if our system tar can handle a tar file with huge sizes and dates far in
+# the future, and that we can actually parse its output.
+#
+# The reference file was generated by GNU tar, and the magic time and size are
+# both octal 01000000000001, which overflows normal ustar fields.
+test_lazy_prereq TAR_HUGE '
+       echo "68719476737 4147" >expect &&
+       tar_info "$TEST_DIRECTORY"/t5000/huge-and-future.tar >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success LONG_IS_64BIT 'set up repository with huge blob' '
+       obj_d=19 &&
+       obj_f=f9c8273ec45a8938e6999cb59b3ff66739902a &&
+       obj=${obj_d}${obj_f} &&
+       mkdir -p .git/objects/$obj_d &&
+       cp "$TEST_DIRECTORY"/t5000/$obj .git/objects/$obj_d/$obj_f &&
+       rm -f .git/index &&
+       git update-index --add --cacheinfo 100644,$obj,huge &&
+       git commit -m huge
+'
+
+# We expect git to die with SIGPIPE here (otherwise we
+# would generate the whole 64GB).
+test_expect_success LONG_IS_64BIT 'generate tar with huge size' '
+       {
+               git archive HEAD
+               echo $? >exit-code
+       } | test_copy_bytes 4096 >huge.tar &&
+       echo 141 >expect &&
+       test_cmp expect exit-code
+'
+
+test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our huge size' '
+       echo 68719476737 >expect &&
+       tar_info huge.tar | cut -d" " -f1 >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success LONG_IS_64BIT 'set up repository with far-future commit' '
+       rm -f .git/index &&
+       echo content >file &&
+       git add file &&
+       GIT_COMMITTER_DATE="@68719476737 +0000" \
+               git commit -m "tempori parendum"
+'
+
+test_expect_success LONG_IS_64BIT 'generate tar with future mtime' '
+       git archive HEAD >future.tar
+'
+
+test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our future mtime' '
+       echo 4147 >expect &&
+       tar_info future.tar | cut -d" " -f2 >actual &&
+       test_cmp expect actual
+'
+
 test_done