t / t5003-archive-zip.shon commit fast-import: do not truncate exported marks file (f4beed6)
   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        dir=eol_$1
  38        dir_with_prefix=$dir/$2
  39        extracted=${dir_with_prefix}a
  40        original=a
  41
  42        test_expect_success UNZIP " extract ZIP archive with EOL conversion" '
  43                (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
  44        '
  45
  46        test_expect_success UNZIP " validate that text files are converted" "
  47                test_cmp_bin $extracted/text.cr $extracted/text.crlf &&
  48                test_cmp_bin $extracted/text.cr $extracted/text.lf
  49        "
  50
  51        test_expect_success UNZIP " validate that binary files are unchanged" "
  52                test_cmp_bin $original/binary.cr   $extracted/binary.cr &&
  53                test_cmp_bin $original/binary.crlf $extracted/binary.crlf &&
  54                test_cmp_bin $original/binary.lf   $extracted/binary.lf
  55        "
  56
  57        test_expect_success UNZIP " validate that diff files are converted" "
  58                test_cmp_bin $extracted/diff.cr $extracted/diff.crlf &&
  59                test_cmp_bin $extracted/diff.cr $extracted/diff.lf
  60        "
  61
  62        test_expect_success UNZIP " validate that -diff files are unchanged" "
  63                test_cmp_bin $original/nodiff.cr   $extracted/nodiff.cr &&
  64                test_cmp_bin $original/nodiff.crlf $extracted/nodiff.crlf &&
  65                test_cmp_bin $original/nodiff.lf   $extracted/nodiff.lf
  66        "
  67}
  68
  69test_expect_success \
  70    'populate workdir' \
  71    'mkdir a &&
  72     echo simple textfile >a/a &&
  73     mkdir a/bin &&
  74     cp /bin/sh a/bin &&
  75     printf "text\r"    >a/text.cr &&
  76     printf "text\r\n"  >a/text.crlf &&
  77     printf "text\n"    >a/text.lf &&
  78     printf "text\r"    >a/nodiff.cr &&
  79     printf "text\r\n"  >a/nodiff.crlf &&
  80     printf "text\n"    >a/nodiff.lf &&
  81     printf "\0\r"      >a/binary.cr &&
  82     printf "\0\r\n"    >a/binary.crlf &&
  83     printf "\0\n"      >a/binary.lf &&
  84     printf "\0\r"      >a/diff.cr &&
  85     printf "\0\r\n"    >a/diff.crlf &&
  86     printf "\0\n"      >a/diff.lf &&
  87     printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
  88     printf "A not substituted O" >a/substfile2 &&
  89     (p=long_path_to_a_file && cd a &&
  90      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
  91      echo text >file_with_long_path)
  92'
  93
  94test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
  95        ln -s a a/symlink_to_a
  96'
  97
  98test_expect_success 'prepare file list' '
  99        (cd a && find .) | sort >a.lst
 100'
 101
 102test_expect_success \
 103    'add ignored file' \
 104    'echo ignore me >a/ignored &&
 105     echo ignored export-ignore >.git/info/attributes'
 106
 107test_expect_success 'add files to repository' '
 108        git add a &&
 109        GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
 110'
 111
 112test_expect_success 'setup export-subst and diff attributes' '
 113        echo "a/nodiff.* -diff" >>.git/info/attributes &&
 114        echo "a/diff.* diff" >>.git/info/attributes &&
 115        echo "substfile?" export-subst >>.git/info/attributes &&
 116        git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
 117                >a/substfile1
 118'
 119
 120test_expect_success \
 121    'create bare clone' \
 122    'git clone --bare . bare.git &&
 123     cp .git/info/attributes bare.git/info/attributes'
 124
 125test_expect_success \
 126    'remove ignored file' \
 127    'rm a/ignored'
 128
 129test_expect_success \
 130    'git archive --format=zip' \
 131    'git archive --format=zip HEAD >d.zip'
 132
 133check_zip d
 134
 135test_expect_success \
 136    'git archive --format=zip in a bare repo' \
 137    '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
 138
 139test_expect_success \
 140    'git archive --format=zip vs. the same in a bare repo' \
 141    'test_cmp_bin d.zip d1.zip'
 142
 143test_expect_success 'git archive --format=zip with --output' \
 144    'git archive --format=zip --output=d2.zip HEAD &&
 145    test_cmp_bin d.zip d2.zip'
 146
 147test_expect_success 'git archive with --output, inferring format' '
 148        git archive --output=d3.zip HEAD &&
 149        test_cmp_bin d.zip d3.zip
 150'
 151
 152test_expect_success \
 153    'git archive --format=zip with prefix' \
 154    'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
 155
 156check_zip e prefix/
 157
 158test_expect_success 'git archive -0 --format=zip on large files' '
 159        test_config core.bigfilethreshold 1 &&
 160        git archive -0 --format=zip HEAD >large.zip
 161'
 162
 163check_zip large
 164
 165test_expect_success 'git archive --format=zip on large files' '
 166        test_config core.bigfilethreshold 1 &&
 167        git archive --format=zip HEAD >large-compressed.zip
 168'
 169
 170check_zip large-compressed
 171
 172test_done