t / t5000-tar-tree.shon commit lstat_cache(): print a warning if doing ping-pong between cache types (7734f04)
   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     ln -s a a/l1 &&
  41     (p=long_path_to_a_file && cd a &&
  42      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
  43      echo text >file_with_long_path) &&
  44     (cd a && find .) | sort >a.lst'
  45
  46test_expect_success \
  47    'add ignored file' \
  48    'echo ignore me >a/ignored &&
  49     echo ignored export-ignore >.gitattributes'
  50
  51test_expect_success \
  52    'add files to repository' \
  53    'find a -type f | xargs git update-index --add &&
  54     find a -type l | xargs git update-index --add &&
  55     treeid=`git write-tree` &&
  56     echo $treeid >treeid &&
  57     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
  58     git commit-tree $treeid </dev/null)'
  59
  60test_expect_success \
  61    'create bare clone' \
  62    'git clone --bare . bare.git &&
  63     cp .gitattributes bare.git/info/attributes'
  64
  65test_expect_success \
  66    'remove ignored file' \
  67    'rm a/ignored'
  68
  69test_expect_success \
  70    'git archive' \
  71    'git archive HEAD >b.tar'
  72
  73test_expect_success \
  74    'git tar-tree' \
  75    'git tar-tree HEAD >b2.tar'
  76
  77test_expect_success \
  78    'git archive vs. git tar-tree' \
  79    'diff b.tar b2.tar'
  80
  81test_expect_success \
  82    'git archive in a bare repo' \
  83    '(cd bare.git && git archive HEAD) >b3.tar'
  84
  85test_expect_success \
  86    'git archive vs. the same in a bare repo' \
  87    'test_cmp b.tar b3.tar'
  88
  89test_expect_success \
  90    'validate file modification time' \
  91    'mkdir extract &&
  92     "$TAR" xf b.tar -C extract a/a &&
  93     test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
  94     echo "1117231200" >expected.mtime &&
  95     diff expected.mtime b.mtime'
  96
  97test_expect_success \
  98    'git get-tar-commit-id' \
  99    'git get-tar-commit-id <b.tar >b.commitid &&
 100     diff .git/$(git symbolic-ref HEAD) b.commitid'
 101
 102test_expect_success \
 103    'extract tar archive' \
 104    '(cd b && "$TAR" xf -) <b.tar'
 105
 106test_expect_success \
 107    'validate filenames' \
 108    '(cd b/a && find .) | sort >b.lst &&
 109     diff a.lst b.lst'
 110
 111test_expect_success \
 112    'validate file contents' \
 113    'diff -r a b/a'
 114
 115test_expect_success \
 116    'git tar-tree with prefix' \
 117    'git tar-tree HEAD prefix >c.tar'
 118
 119test_expect_success \
 120    'extract tar archive with prefix' \
 121    '(cd c && "$TAR" xf -) <c.tar'
 122
 123test_expect_success \
 124    'validate filenames with prefix' \
 125    '(cd c/prefix/a && find .) | sort >c.lst &&
 126     diff a.lst c.lst'
 127
 128test_expect_success \
 129    'validate file contents with prefix' \
 130    'diff -r a c/prefix/a'
 131
 132test_expect_success \
 133    'create archives with substfiles' \
 134    'echo "substfile?" export-subst >a/.gitattributes &&
 135     git archive HEAD >f.tar &&
 136     git archive --prefix=prefix/ HEAD >g.tar &&
 137     rm a/.gitattributes'
 138
 139test_expect_success \
 140    'extract substfiles' \
 141    '(mkdir f && cd f && "$TAR" xf -) <f.tar'
 142
 143test_expect_success \
 144     'validate substfile contents' \
 145     'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
 146      >f/a/substfile1.expected &&
 147      diff f/a/substfile1.expected f/a/substfile1 &&
 148      diff a/substfile2 f/a/substfile2
 149'
 150
 151test_expect_success \
 152    'extract substfiles from archive with prefix' \
 153    '(mkdir g && cd g && "$TAR" xf -) <g.tar'
 154
 155test_expect_success \
 156     'validate substfile contents from archive with prefix' \
 157     'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
 158      >g/prefix/a/substfile1.expected &&
 159      diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
 160      diff a/substfile2 g/prefix/a/substfile2
 161'
 162
 163test_expect_success \
 164    'git archive --format=zip' \
 165    'git archive --format=zip HEAD >d.zip'
 166
 167test_expect_success \
 168    'git archive --format=zip in a bare repo' \
 169    '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
 170
 171test_expect_success \
 172    'git archive --format=zip vs. the same in a bare repo' \
 173    'test_cmp d.zip d1.zip'
 174
 175$UNZIP -v >/dev/null 2>&1
 176if [ $? -eq 127 ]; then
 177        echo "Skipping ZIP tests, because unzip was not found"
 178        test_done
 179        exit
 180fi
 181
 182test_expect_success \
 183    'extract ZIP archive' \
 184    '(mkdir d && cd d && $UNZIP ../d.zip)'
 185
 186test_expect_success \
 187    'validate filenames' \
 188    '(cd d/a && find .) | sort >d.lst &&
 189     diff a.lst d.lst'
 190
 191test_expect_success \
 192    'validate file contents' \
 193    'diff -r a d/a'
 194
 195test_expect_success \
 196    'git archive --format=zip with prefix' \
 197    'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
 198
 199test_expect_success \
 200    'extract ZIP archive with prefix' \
 201    '(mkdir e && cd e && $UNZIP ../e.zip)'
 202
 203test_expect_success \
 204    'validate filenames with prefix' \
 205    '(cd e/prefix/a && find .) | sort >e.lst &&
 206     diff a.lst e.lst'
 207
 208test_expect_success \
 209    'validate file contents with prefix' \
 210    'diff -r a e/prefix/a'
 211
 212test_expect_success \
 213    'git archive --list outside of a git repo' \
 214    'GIT_DIR=some/non-existing/directory git archive --list'
 215
 216test_done