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