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