t / t5000-tar-tree.shon commit checkout: tone down the "forked status" diagnostic messages (b0030db)
   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
  28TAR=${TAR:-tar}
  29UNZIP=${UNZIP:-unzip}
  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     ln -s a a/l1 &&
  42     (p=long_path_to_a_file && cd a &&
  43      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
  44      echo text >file_with_long_path) &&
  45     (cd a && find .) | sort >a.lst'
  46
  47test_expect_success \
  48    'add files to repository' \
  49    'find a -type f | xargs git update-index --add &&
  50     find a -type l | xargs git update-index --add &&
  51     treeid=`git write-tree` &&
  52     echo $treeid >treeid &&
  53     git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
  54     git commit-tree $treeid </dev/null)'
  55
  56test_expect_success \
  57    'git archive' \
  58    'git archive HEAD >b.tar'
  59
  60test_expect_success \
  61    'git tar-tree' \
  62    'git tar-tree HEAD >b2.tar'
  63
  64test_expect_success \
  65    'git archive vs. git tar-tree' \
  66    'diff b.tar b2.tar'
  67
  68test_expect_success \
  69    'validate file modification time' \
  70    'TZ=GMT $TAR tvf b.tar a/a |
  71     awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
  72     >b.mtime &&
  73     echo "2005-05-27 22:00:00" >expected.mtime &&
  74     diff expected.mtime b.mtime'
  75
  76test_expect_success \
  77    'git get-tar-commit-id' \
  78    'git get-tar-commit-id <b.tar >b.commitid &&
  79     diff .git/$(git symbolic-ref HEAD) b.commitid'
  80
  81test_expect_success \
  82    'extract tar archive' \
  83    '(cd b && $TAR xf -) <b.tar'
  84
  85test_expect_success \
  86    'validate filenames' \
  87    '(cd b/a && find .) | sort >b.lst &&
  88     diff a.lst b.lst'
  89
  90test_expect_success \
  91    'validate file contents' \
  92    'diff -r a b/a'
  93
  94test_expect_success \
  95    'git tar-tree with prefix' \
  96    'git tar-tree HEAD prefix >c.tar'
  97
  98test_expect_success \
  99    'extract tar archive with prefix' \
 100    '(cd c && $TAR xf -) <c.tar'
 101
 102test_expect_success \
 103    'validate filenames with prefix' \
 104    '(cd c/prefix/a && find .) | sort >c.lst &&
 105     diff a.lst c.lst'
 106
 107test_expect_success \
 108    'validate file contents with prefix' \
 109    'diff -r a c/prefix/a'
 110
 111test_expect_success \
 112    'create an archive with a substfiles' \
 113    'echo "substfile?" export-subst >a/.gitattributes &&
 114     git archive HEAD >f.tar &&
 115     rm a/.gitattributes'
 116
 117test_expect_success \
 118    'extract substfiles' \
 119    '(mkdir f && cd f && $TAR xf -) <f.tar'
 120
 121test_expect_success \
 122     'validate substfile contents' \
 123     'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
 124      >f/a/substfile1.expected &&
 125      diff f/a/substfile1.expected f/a/substfile1 &&
 126      diff a/substfile2 f/a/substfile2
 127'
 128
 129test_expect_success \
 130    'git archive --format=zip' \
 131    'git archive --format=zip HEAD >d.zip'
 132
 133$UNZIP -v >/dev/null 2>&1
 134if [ $? -eq 127 ]; then
 135        echo "Skipping ZIP tests, because unzip was not found"
 136        test_done
 137        exit
 138fi
 139
 140test_expect_success \
 141    'extract ZIP archive' \
 142    '(mkdir d && cd d && $UNZIP ../d.zip)'
 143
 144test_expect_success \
 145    'validate filenames' \
 146    '(cd d/a && find .) | sort >d.lst &&
 147     diff a.lst d.lst'
 148
 149test_expect_success \
 150    'validate file contents' \
 151    'diff -r a d/a'
 152
 153test_expect_success \
 154    'git archive --format=zip with prefix' \
 155    'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
 156
 157test_expect_success \
 158    'extract ZIP archive with prefix' \
 159    '(mkdir e && cd e && $UNZIP ../e.zip)'
 160
 161test_expect_success \
 162    'validate filenames with prefix' \
 163    '(cd e/prefix/a && find .) | sort >e.lst &&
 164     diff a.lst e.lst'
 165
 166test_expect_success \
 167    'validate file contents with prefix' \
 168    'diff -r a e/prefix/a'
 169
 170test_expect_success \
 171    'git archive --list outside of a git repo' \
 172    'GIT_DIR=some/non-existing/directory git archive --list'
 173
 174test_done