t / t5000-tar-tree.shon commit t5000: use check_tar for prefix test (03d9bc5)
   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
  28GZIP=${GZIP:-gzip}
  29GUNZIP=${GUNZIP:-gzip -d}
  30
  31SUBSTFORMAT=%H%n
  32
  33check_tar() {
  34        tarfile=$1.tar
  35        listfile=$1.lst
  36        dir=$1
  37        dir_with_prefix=$dir/$2
  38
  39        test_expect_success ' extract tar archive' '
  40                (mkdir $dir && cd $dir && "$TAR" xf -) <$tarfile
  41        '
  42
  43        test_expect_success ' validate filenames' '
  44                (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
  45                test_cmp a.lst $listfile
  46        '
  47
  48        test_expect_success ' validate file contents' '
  49                diff -r a ${dir_with_prefix}a
  50        '
  51}
  52
  53test_expect_success \
  54    'populate workdir' \
  55    'mkdir a &&
  56     echo simple textfile >a/a &&
  57     mkdir a/bin &&
  58     cp /bin/sh a/bin &&
  59     printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
  60     printf "A not substituted O" >a/substfile2 &&
  61     if test_have_prereq SYMLINKS; then
  62        ln -s a a/l1
  63     else
  64        printf %s a > a/l1
  65     fi &&
  66     (p=long_path_to_a_file && cd a &&
  67      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
  68      echo text >file_with_long_path) &&
  69     (cd a && find .) | sort >a.lst'
  70
  71test_expect_success \
  72    'add ignored file' \
  73    'echo ignore me >a/ignored &&
  74     echo ignored export-ignore >.git/info/attributes'
  75
  76test_expect_success \
  77    'add files to repository' \
  78    'find a -type f | xargs git update-index --add &&
  79     find a -type l | xargs git update-index --add &&
  80     treeid=`git write-tree` &&
  81     echo $treeid >treeid &&
  82     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
  83     git commit-tree $treeid </dev/null)'
  84
  85test_expect_success 'setup export-subst' '
  86        echo "substfile?" export-subst >>.git/info/attributes &&
  87        git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
  88                >a/substfile1
  89'
  90
  91test_expect_success \
  92    'create bare clone' \
  93    'git clone --bare . bare.git &&
  94     cp .git/info/attributes bare.git/info/attributes'
  95
  96test_expect_success \
  97    'remove ignored file' \
  98    'rm a/ignored'
  99
 100test_expect_success \
 101    'git archive' \
 102    'git archive HEAD >b.tar'
 103
 104check_tar b
 105
 106test_expect_success 'git archive --prefix=prefix/' '
 107        git archive --prefix=prefix/ HEAD >with_prefix.tar
 108'
 109
 110check_tar with_prefix prefix/
 111
 112test_expect_success 'git-archive --prefix=olde-' '
 113        git archive --prefix=olde- HEAD >with_olde-prefix.tar
 114'
 115
 116check_tar with_olde-prefix olde-
 117
 118test_expect_success \
 119    'git tar-tree' \
 120    'git tar-tree HEAD >b2.tar'
 121
 122test_expect_success \
 123    'git archive vs. git tar-tree' \
 124    'test_cmp b.tar b2.tar'
 125
 126test_expect_success 'git archive on large files' '
 127    test_config core.bigfilethreshold 1 &&
 128    git archive HEAD >b3.tar &&
 129    test_cmp b.tar b3.tar
 130'
 131
 132test_expect_success \
 133    'git archive in a bare repo' \
 134    '(cd bare.git && git archive HEAD) >b3.tar'
 135
 136test_expect_success \
 137    'git archive vs. the same in a bare repo' \
 138    'test_cmp b.tar b3.tar'
 139
 140test_expect_success 'git archive with --output' \
 141    'git archive --output=b4.tar HEAD &&
 142    test_cmp b.tar b4.tar'
 143
 144test_expect_success 'git archive --remote' \
 145    'git archive --remote=. HEAD >b5.tar &&
 146    test_cmp b.tar b5.tar'
 147
 148test_expect_success \
 149    'validate file modification time' \
 150    'mkdir extract &&
 151     "$TAR" xf b.tar -C extract a/a &&
 152     test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
 153     echo "1117231200" >expected.mtime &&
 154     test_cmp expected.mtime b.mtime'
 155
 156test_expect_success \
 157    'git get-tar-commit-id' \
 158    'git get-tar-commit-id <b.tar >b.commitid &&
 159     test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
 160
 161test_expect_success \
 162    'git tar-tree with prefix' \
 163    'git tar-tree HEAD prefix >c.tar'
 164
 165test_expect_success \
 166    'extract tar archive with prefix' \
 167    '(mkdir c && cd c && "$TAR" xf -) <c.tar'
 168
 169test_expect_success \
 170    'validate filenames with prefix' \
 171    '(cd c/prefix/a && find .) | sort >c.lst &&
 172     test_cmp a.lst c.lst'
 173
 174test_expect_success \
 175    'validate file contents with prefix' \
 176    'diff -r a c/prefix/a'
 177
 178test_expect_success 'git archive with --output, override inferred format' '
 179        git archive --format=tar --output=d4.zip HEAD &&
 180        test_cmp b.tar d4.zip
 181'
 182
 183test_expect_success \
 184    'git archive --list outside of a git repo' \
 185    'GIT_DIR=some/non-existing/directory git archive --list'
 186
 187test_expect_success 'clients cannot access unreachable commits' '
 188        test_commit unreachable &&
 189        sha1=`git rev-parse HEAD` &&
 190        git reset --hard HEAD^ &&
 191        git archive $sha1 >remote.tar &&
 192        test_must_fail git archive --remote=. $sha1 >remote.tar
 193'
 194
 195test_expect_success 'setup tar filters' '
 196        git config tar.tar.foo.command "tr ab ba" &&
 197        git config tar.bar.command "tr ab ba" &&
 198        git config tar.bar.remote true &&
 199        git config tar.invalid baz
 200'
 201
 202test_expect_success 'archive --list mentions user filter' '
 203        git archive --list >output &&
 204        grep "^tar\.foo\$" output &&
 205        grep "^bar\$" output
 206'
 207
 208test_expect_success 'archive --list shows only enabled remote filters' '
 209        git archive --list --remote=. >output &&
 210        ! grep "^tar\.foo\$" output &&
 211        grep "^bar\$" output
 212'
 213
 214test_expect_success 'invoke tar filter by format' '
 215        git archive --format=tar.foo HEAD >config.tar.foo &&
 216        tr ab ba <config.tar.foo >config.tar &&
 217        test_cmp b.tar config.tar &&
 218        git archive --format=bar HEAD >config.bar &&
 219        tr ab ba <config.bar >config.tar &&
 220        test_cmp b.tar config.tar
 221'
 222
 223test_expect_success 'invoke tar filter by extension' '
 224        git archive -o config-implicit.tar.foo HEAD &&
 225        test_cmp config.tar.foo config-implicit.tar.foo &&
 226        git archive -o config-implicit.bar HEAD &&
 227        test_cmp config.tar.foo config-implicit.bar
 228'
 229
 230test_expect_success 'default output format remains tar' '
 231        git archive -o config-implicit.baz HEAD &&
 232        test_cmp b.tar config-implicit.baz
 233'
 234
 235test_expect_success 'extension matching requires dot' '
 236        git archive -o config-implicittar.foo HEAD &&
 237        test_cmp b.tar config-implicittar.foo
 238'
 239
 240test_expect_success 'only enabled filters are available remotely' '
 241        test_must_fail git archive --remote=. --format=tar.foo HEAD \
 242                >remote.tar.foo &&
 243        git archive --remote=. --format=bar >remote.bar HEAD &&
 244        test_cmp remote.bar config.bar
 245'
 246
 247if $GZIP --version >/dev/null 2>&1; then
 248        test_set_prereq GZIP
 249else
 250        say "Skipping some tar.gz tests because gzip not found"
 251fi
 252
 253test_expect_success GZIP 'git archive --format=tgz' '
 254        git archive --format=tgz HEAD >j.tgz
 255'
 256
 257test_expect_success GZIP 'git archive --format=tar.gz' '
 258        git archive --format=tar.gz HEAD >j1.tar.gz &&
 259        test_cmp j.tgz j1.tar.gz
 260'
 261
 262test_expect_success GZIP 'infer tgz from .tgz filename' '
 263        git archive --output=j2.tgz HEAD &&
 264        test_cmp j.tgz j2.tgz
 265'
 266
 267test_expect_success GZIP 'infer tgz from .tar.gz filename' '
 268        git archive --output=j3.tar.gz HEAD &&
 269        test_cmp j.tgz j3.tar.gz
 270'
 271
 272if $GUNZIP --version >/dev/null 2>&1; then
 273        test_set_prereq GUNZIP
 274else
 275        say "Skipping some tar.gz tests because gunzip was not found"
 276fi
 277
 278test_expect_success GZIP,GUNZIP 'extract tgz file' '
 279        $GUNZIP -c <j.tgz >j.tar &&
 280        test_cmp b.tar j.tar
 281'
 282
 283test_expect_success GZIP 'remote tar.gz is allowed by default' '
 284        git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
 285        test_cmp j.tgz remote.tar.gz
 286'
 287
 288test_expect_success GZIP 'remote tar.gz can be disabled' '
 289        git config tar.tar.gz.remote false &&
 290        test_must_fail git archive --remote=. --format=tar.gz HEAD \
 291                >remote.tar.gz
 292'
 293
 294test_done