t / t5003-archive-zip.shon commit Merge branch 'rs/deflate-init-cleanup' into maint (a393c6b)
   1#!/bin/sh
   2
   3test_description='git archive --format=zip test'
   4
   5. ./test-lib.sh
   6
   7SUBSTFORMAT=%H%n
   8
   9test_lazy_prereq UNZIP_SYMLINKS '
  10        (
  11                mkdir unzip-symlinks &&
  12                cd unzip-symlinks &&
  13                "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
  14                test -h symlink
  15        )
  16'
  17
  18check_zip() {
  19        zipfile=$1.zip
  20        listfile=$1.lst
  21        dir=$1
  22        dir_with_prefix=$dir/$2
  23
  24        test_expect_success UNZIP " extract ZIP archive" '
  25                (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
  26        '
  27
  28        test_expect_success UNZIP " validate filenames" "
  29                (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
  30                test_cmp a.lst $listfile
  31        "
  32
  33        test_expect_success UNZIP " validate file contents" "
  34                diff -r a ${dir_with_prefix}a
  35        "
  36}
  37
  38test_expect_success \
  39    'populate workdir' \
  40    'mkdir a &&
  41     echo simple textfile >a/a &&
  42     mkdir a/bin &&
  43     cp /bin/sh a/bin &&
  44     printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
  45     printf "A not substituted O" >a/substfile2 &&
  46     (p=long_path_to_a_file && cd a &&
  47      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
  48      echo text >file_with_long_path)
  49'
  50
  51test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
  52        ln -s a a/symlink_to_a
  53'
  54
  55test_expect_success 'prepare file list' '
  56        (cd a && find .) | sort >a.lst
  57'
  58
  59test_expect_success \
  60    'add ignored file' \
  61    'echo ignore me >a/ignored &&
  62     echo ignored export-ignore >.git/info/attributes'
  63
  64test_expect_success 'add files to repository' '
  65        git add a &&
  66        GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
  67'
  68
  69test_expect_success 'setup export-subst' '
  70        echo "substfile?" export-subst >>.git/info/attributes &&
  71        git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
  72                >a/substfile1
  73'
  74
  75test_expect_success \
  76    'create bare clone' \
  77    'git clone --bare . bare.git &&
  78     cp .git/info/attributes bare.git/info/attributes'
  79
  80test_expect_success \
  81    'remove ignored file' \
  82    'rm a/ignored'
  83
  84test_expect_success \
  85    'git archive --format=zip' \
  86    'git archive --format=zip HEAD >d.zip'
  87
  88check_zip d
  89
  90test_expect_success \
  91    'git archive --format=zip in a bare repo' \
  92    '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
  93
  94test_expect_success \
  95    'git archive --format=zip vs. the same in a bare repo' \
  96    'test_cmp_bin d.zip d1.zip'
  97
  98test_expect_success 'git archive --format=zip with --output' \
  99    'git archive --format=zip --output=d2.zip HEAD &&
 100    test_cmp_bin d.zip d2.zip'
 101
 102test_expect_success 'git archive with --output, inferring format' '
 103        git archive --output=d3.zip HEAD &&
 104        test_cmp_bin d.zip d3.zip
 105'
 106
 107test_expect_success \
 108    'git archive --format=zip with prefix' \
 109    'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
 110
 111check_zip e prefix/
 112
 113test_expect_success 'git archive -0 --format=zip on large files' '
 114        test_config core.bigfilethreshold 1 &&
 115        git archive -0 --format=zip HEAD >large.zip
 116'
 117
 118check_zip large
 119
 120test_expect_success 'git archive --format=zip on large files' '
 121        test_config core.bigfilethreshold 1 &&
 122        git archive --format=zip HEAD >large-compressed.zip
 123'
 124
 125check_zip large-compressed
 126
 127test_done