t / t5000-tar-tree.shon commit Makefile: fix shell quoting (bfce508)
   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 files to repository' \
  48    'find a -type f | xargs git update-index --add &&
  49     find a -type l | xargs git update-index --add &&
  50     treeid=`git write-tree` &&
  51     echo $treeid >treeid &&
  52     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
  53     git commit-tree $treeid </dev/null)'
  54
  55test_expect_success \
  56    'git archive' \
  57    'git archive HEAD >b.tar'
  58
  59test_expect_success \
  60    'git tar-tree' \
  61    'git tar-tree HEAD >b2.tar'
  62
  63test_expect_success \
  64    'git archive vs. git tar-tree' \
  65    'diff b.tar b2.tar'
  66
  67test_expect_success \
  68    'validate file modification time' \
  69    'mkdir extract &&
  70     "$TAR" xf b.tar -C extract a/a &&
  71     perl -e '\''print((stat("extract/a/a"))[9], "\n")'\'' >b.mtime &&
  72     echo "1117231200" >expected.mtime &&
  73     diff expected.mtime b.mtime'
  74
  75test_expect_success \
  76    'git get-tar-commit-id' \
  77    'git get-tar-commit-id <b.tar >b.commitid &&
  78     diff .git/$(git symbolic-ref HEAD) b.commitid'
  79
  80test_expect_success \
  81    'extract tar archive' \
  82    '(cd b && "$TAR" xf -) <b.tar'
  83
  84test_expect_success \
  85    'validate filenames' \
  86    '(cd b/a && find .) | sort >b.lst &&
  87     diff a.lst b.lst'
  88
  89test_expect_success \
  90    'validate file contents' \
  91    'diff -r a b/a'
  92
  93test_expect_success \
  94    'git tar-tree with prefix' \
  95    'git tar-tree HEAD prefix >c.tar'
  96
  97test_expect_success \
  98    'extract tar archive with prefix' \
  99    '(cd c && "$TAR" xf -) <c.tar'
 100
 101test_expect_success \
 102    'validate filenames with prefix' \
 103    '(cd c/prefix/a && find .) | sort >c.lst &&
 104     diff a.lst c.lst'
 105
 106test_expect_success \
 107    'validate file contents with prefix' \
 108    'diff -r a c/prefix/a'
 109
 110test_expect_success \
 111    'create archives with substfiles' \
 112    'echo "substfile?" export-subst >a/.gitattributes &&
 113     git archive HEAD >f.tar &&
 114     git archive --prefix=prefix/ HEAD >g.tar &&
 115     rm a/.gitattributes'
 116
 117test_expect_success \
 118    'extract substfiles' \
 119    '(mkdir f && cd f && "$TAR" xf -) <f.tar'
 120
 121test_expect_success \
 122     'validate substfile contents' \
 123     'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
 124      >f/a/substfile1.expected &&
 125      diff f/a/substfile1.expected f/a/substfile1 &&
 126      diff a/substfile2 f/a/substfile2
 127'
 128
 129test_expect_success \
 130    'extract substfiles from archive with prefix' \
 131    '(mkdir g && cd g && "$TAR" xf -) <g.tar'
 132
 133test_expect_success \
 134     'validate substfile contents from archive with prefix' \
 135     'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
 136      >g/prefix/a/substfile1.expected &&
 137      diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
 138      diff a/substfile2 g/prefix/a/substfile2
 139'
 140
 141test_expect_success \
 142    'git archive --format=zip' \
 143    'git archive --format=zip HEAD >d.zip'
 144
 145$UNZIP -v >/dev/null 2>&1
 146if [ $? -eq 127 ]; then
 147        echo "Skipping ZIP tests, because unzip was not found"
 148        test_done
 149        exit
 150fi
 151
 152test_expect_success \
 153    'extract ZIP archive' \
 154    '(mkdir d && cd d && $UNZIP ../d.zip)'
 155
 156test_expect_success \
 157    'validate filenames' \
 158    '(cd d/a && find .) | sort >d.lst &&
 159     diff a.lst d.lst'
 160
 161test_expect_success \
 162    'validate file contents' \
 163    'diff -r a d/a'
 164
 165test_expect_success \
 166    'git archive --format=zip with prefix' \
 167    'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
 168
 169test_expect_success \
 170    'extract ZIP archive with prefix' \
 171    '(mkdir e && cd e && $UNZIP ../e.zip)'
 172
 173test_expect_success \
 174    'validate filenames with prefix' \
 175    '(cd e/prefix/a && find .) | sort >e.lst &&
 176     diff a.lst e.lst'
 177
 178test_expect_success \
 179    'validate file contents with prefix' \
 180    'diff -r a e/prefix/a'
 181
 182test_expect_success \
 183    'git archive --list outside of a git repo' \
 184    'GIT_DIR=some/non-existing/directory git archive --list'
 185
 186test_done