3c61664c905d8dc6ed957099bd1baeccd266644a
   1#!/bin/sh
   2
   3test_description='git archive --format=zip test'
   4
   5. ./test-lib.sh
   6GIT_UNZIP=${GIT_UNZIP:-unzip}
   7
   8SUBSTFORMAT=%H%n
   9
  10test_lazy_prereq UNZIP '
  11        "$GIT_UNZIP" -v
  12        test $? -ne 127
  13'
  14
  15check_zip() {
  16        zipfile=$1.zip
  17        listfile=$1.lst
  18        dir=$1
  19        dir_with_prefix=$dir/$2
  20
  21        test_expect_success UNZIP " extract ZIP archive" '
  22                (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
  23        '
  24
  25        test_expect_success UNZIP " validate filenames" "
  26                (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
  27                test_cmp a.lst $listfile
  28        "
  29
  30        test_expect_success UNZIP " validate file contents" "
  31                diff -r a ${dir_with_prefix}a
  32        "
  33}
  34
  35test_expect_success \
  36    'populate workdir' \
  37    'mkdir a b c &&
  38     echo simple textfile >a/a &&
  39     mkdir a/bin &&
  40     cp /bin/sh a/bin &&
  41     printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
  42     printf "A not substituted O" >a/substfile2 &&
  43     if test_have_prereq SYMLINKS; then
  44        ln -s a a/l1
  45     else
  46        printf %s a > a/l1
  47     fi &&
  48     (p=long_path_to_a_file && cd a &&
  49      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
  50      echo text >file_with_long_path) &&
  51     (cd a && find .) | sort >a.lst'
  52
  53test_expect_success \
  54    'add ignored file' \
  55    'echo ignore me >a/ignored &&
  56     echo ignored export-ignore >.git/info/attributes'
  57
  58test_expect_success \
  59    'add files to repository' \
  60    'find a -type f | xargs git update-index --add &&
  61     find a -type l | xargs git update-index --add &&
  62     treeid=`git write-tree` &&
  63     echo $treeid >treeid &&
  64     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
  65     git commit-tree $treeid </dev/null)'
  66
  67test_expect_success \
  68    'create bare clone' \
  69    'git clone --bare . bare.git &&
  70     cp .git/info/attributes bare.git/info/attributes'
  71
  72test_expect_success \
  73    'remove ignored file' \
  74    'rm a/ignored'
  75
  76test_expect_success \
  77    'git archive --format=zip' \
  78    'git archive --format=zip HEAD >d.zip'
  79
  80check_zip d
  81
  82test_expect_success \
  83    'git archive --format=zip in a bare repo' \
  84    '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
  85
  86test_expect_success \
  87    'git archive --format=zip vs. the same in a bare repo' \
  88    'test_cmp d.zip d1.zip'
  89
  90test_expect_success 'git archive --format=zip with --output' \
  91    'git archive --format=zip --output=d2.zip HEAD &&
  92    test_cmp d.zip d2.zip'
  93
  94test_expect_success 'git archive with --output, inferring format' '
  95        git archive --output=d3.zip HEAD &&
  96        test_cmp d.zip d3.zip
  97'
  98
  99test_expect_success \
 100    'git archive --format=zip with prefix' \
 101    'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
 102
 103check_zip e prefix/
 104
 105test_expect_success 'git archive -0 --format=zip on large files' '
 106        test_config core.bigfilethreshold 1 &&
 107        git archive -0 --format=zip HEAD >large.zip
 108'
 109
 110check_zip large
 111
 112test_expect_success 'git archive --format=zip on large files' '
 113        test_config core.bigfilethreshold 1 &&
 114        git archive --format=zip HEAD >large-compressed.zip
 115'
 116
 117check_zip large-compressed
 118
 119test_done