t / t5000-tar-tree.shon commit Merge branch 'js/maint-no-ln-across-libexec-and-bin' (2c8f8b1)
   1#!/bin/sh
   2#
   3# Copyright (C) 2005 Rene Scharfe
   4#
   5
   6test_description='git tar-tree and git get-tar-commit-id test
   7
   8This test covers the topics of file contents, commit date handling and
   9commit id embedding:
  10
  11  The contents of the repository is compared to the extracted tar
  12  archive.  The repository contains simple text files, symlinks and a
  13  binary file (/bin/sh).  Only paths shorter than 99 characters are
  14  used.
  15
  16  git tar-tree applies the commit date to every file in the archive it
  17  creates.  The test sets the commit date to a specific value and checks
  18  if the tar archive contains that value.
  19
  20  When giving git tar-tree a commit id (in contrast to a tree id) it
  21  embeds this commit id into the tar archive as a comment.  The test
  22  checks the ability of git get-tar-commit-id to figure it out from the
  23  tar file.
  24
  25'
  26
  27. ./test-lib.sh
  28UNZIP=${UNZIP:-unzip}
  29
  30SUBSTFORMAT=%H%n
  31
  32test_expect_success \
  33    'populate workdir' \
  34    'mkdir a b c &&
  35     echo simple textfile >a/a &&
  36     mkdir a/bin &&
  37     cp /bin/sh a/bin &&
  38     printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
  39     printf "A not substituted O" >a/substfile2 &&
  40     if test_have_prereq SYMLINKS; then
  41        ln -s a a/l1
  42     else
  43        printf %s a > a/l1
  44     fi &&
  45     (p=long_path_to_a_file && cd a &&
  46      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
  47      echo text >file_with_long_path) &&
  48     (cd a && find .) | sort >a.lst'
  49
  50test_expect_success \
  51    'add ignored file' \
  52    'echo ignore me >a/ignored &&
  53     echo ignored export-ignore >.git/info/attributes'
  54
  55test_expect_success \
  56    'add files to repository' \
  57    'find a -type f | xargs git update-index --add &&
  58     find a -type l | xargs git update-index --add &&
  59     treeid=`git write-tree` &&
  60     echo $treeid >treeid &&
  61     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
  62     git commit-tree $treeid </dev/null)'
  63
  64test_expect_success \
  65    'create bare clone' \
  66    'git clone --bare . bare.git &&
  67     cp .git/info/attributes bare.git/info/attributes'
  68
  69test_expect_success \
  70    'remove ignored file' \
  71    'rm a/ignored'
  72
  73test_expect_success \
  74    'git archive' \
  75    'git archive HEAD >b.tar'
  76
  77test_expect_success \
  78    'git tar-tree' \
  79    'git tar-tree HEAD >b2.tar'
  80
  81test_expect_success \
  82    'git archive vs. git tar-tree' \
  83    'test_cmp b.tar b2.tar'
  84
  85test_expect_success \
  86    'git archive in a bare repo' \
  87    '(cd bare.git && git archive HEAD) >b3.tar'
  88
  89test_expect_success \
  90    'git archive vs. the same in a bare repo' \
  91    'test_cmp b.tar b3.tar'
  92
  93test_expect_success 'git archive with --output' \
  94    'git archive --output=b4.tar HEAD &&
  95    test_cmp b.tar b4.tar'
  96
  97test_expect_success \
  98    'validate file modification time' \
  99    'mkdir extract &&
 100     "$TAR" xf b.tar -C extract a/a &&
 101     test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
 102     echo "1117231200" >expected.mtime &&
 103     test_cmp expected.mtime b.mtime'
 104
 105test_expect_success \
 106    'git get-tar-commit-id' \
 107    'git get-tar-commit-id <b.tar >b.commitid &&
 108     test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
 109
 110test_expect_success \
 111    'extract tar archive' \
 112    '(cd b && "$TAR" xf -) <b.tar'
 113
 114test_expect_success \
 115    'validate filenames' \
 116    '(cd b/a && find .) | sort >b.lst &&
 117     test_cmp a.lst b.lst'
 118
 119test_expect_success \
 120    'validate file contents' \
 121    'diff -r a b/a'
 122
 123test_expect_success \
 124    'git tar-tree with prefix' \
 125    'git tar-tree HEAD prefix >c.tar'
 126
 127test_expect_success \
 128    'extract tar archive with prefix' \
 129    '(cd c && "$TAR" xf -) <c.tar'
 130
 131test_expect_success \
 132    'validate filenames with prefix' \
 133    '(cd c/prefix/a && find .) | sort >c.lst &&
 134     test_cmp a.lst c.lst'
 135
 136test_expect_success \
 137    'validate file contents with prefix' \
 138    'diff -r a c/prefix/a'
 139
 140test_expect_success \
 141    'create archives with substfiles' \
 142    'cp .git/info/attributes .git/info/attributes.before &&
 143     echo "substfile?" export-subst >>.git/info/attributes &&
 144     git archive HEAD >f.tar &&
 145     git archive --prefix=prefix/ HEAD >g.tar &&
 146     mv .git/info/attributes.before .git/info/attributes'
 147
 148test_expect_success \
 149    'extract substfiles' \
 150    '(mkdir f && cd f && "$TAR" xf -) <f.tar'
 151
 152test_expect_success \
 153     'validate substfile contents' \
 154     'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
 155      >f/a/substfile1.expected &&
 156      test_cmp f/a/substfile1.expected f/a/substfile1 &&
 157      test_cmp a/substfile2 f/a/substfile2
 158'
 159
 160test_expect_success \
 161    'extract substfiles from archive with prefix' \
 162    '(mkdir g && cd g && "$TAR" xf -) <g.tar'
 163
 164test_expect_success \
 165     'validate substfile contents from archive with prefix' \
 166     'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
 167      >g/prefix/a/substfile1.expected &&
 168      test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
 169      test_cmp a/substfile2 g/prefix/a/substfile2
 170'
 171
 172test_expect_success \
 173    'git archive --format=zip' \
 174    'git archive --format=zip HEAD >d.zip'
 175
 176test_expect_success \
 177    'git archive --format=zip in a bare repo' \
 178    '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
 179
 180test_expect_success \
 181    'git archive --format=zip vs. the same in a bare repo' \
 182    'test_cmp d.zip d1.zip'
 183
 184test_expect_success 'git archive --format=zip with --output' \
 185    'git archive --format=zip --output=d2.zip HEAD &&
 186    test_cmp d.zip d2.zip'
 187
 188$UNZIP -v >/dev/null 2>&1
 189if [ $? -eq 127 ]; then
 190        say "Skipping ZIP tests, because unzip was not found"
 191else
 192        test_set_prereq UNZIP
 193fi
 194
 195test_expect_success UNZIP \
 196    'extract ZIP archive' \
 197    '(mkdir d && cd d && $UNZIP ../d.zip)'
 198
 199test_expect_success UNZIP \
 200    'validate filenames' \
 201    '(cd d/a && find .) | sort >d.lst &&
 202     test_cmp a.lst d.lst'
 203
 204test_expect_success UNZIP \
 205    'validate file contents' \
 206    'diff -r a d/a'
 207
 208test_expect_success \
 209    'git archive --format=zip with prefix' \
 210    'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
 211
 212test_expect_success UNZIP \
 213    'extract ZIP archive with prefix' \
 214    '(mkdir e && cd e && $UNZIP ../e.zip)'
 215
 216test_expect_success UNZIP \
 217    'validate filenames with prefix' \
 218    '(cd e/prefix/a && find .) | sort >e.lst &&
 219     test_cmp a.lst e.lst'
 220
 221test_expect_success UNZIP \
 222    'validate file contents with prefix' \
 223    'diff -r a e/prefix/a'
 224
 225test_expect_success \
 226    'git archive --list outside of a git repo' \
 227    'GIT_DIR=some/non-existing/directory git archive --list'
 228
 229test_done