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