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