t / t5000-tar-tree.shon commit Merge git://git.kernel.org/pub/scm/gitk/gitk (1a17ee2)
   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 pathes 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}
  29
  30test_expect_success \
  31    'populate workdir' \
  32    'mkdir a b c &&
  33     echo simple textfile >a/a &&
  34     mkdir a/bin &&
  35     cp /bin/sh a/bin &&
  36     ln -s a a/l1 &&
  37     (p=long_path_to_a_file && cd a &&
  38      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
  39      echo text >file_with_long_path) &&
  40     (cd a && find .) | sort >a.lst'
  41
  42test_expect_success \
  43    'add files to repository' \
  44    'find a -type f | xargs git-update-index --add &&
  45     find a -type l | xargs git-update-index --add &&
  46     treeid=`git-write-tree` &&
  47     echo $treeid >treeid &&
  48     git-update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
  49     git-commit-tree $treeid </dev/null)'
  50
  51test_expect_success \
  52    'git-tar-tree' \
  53    'git-tar-tree HEAD >b.tar'
  54
  55test_expect_success \
  56    'validate file modification time' \
  57    'TZ=GMT $TAR tvf b.tar a/a |
  58     awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
  59     >b.mtime &&
  60     echo "2005-05-27 22:00:00" >expected.mtime &&
  61     diff expected.mtime b.mtime'
  62
  63test_expect_success \
  64    'git-get-tar-commit-id' \
  65    'git-get-tar-commit-id <b.tar >b.commitid &&
  66     diff .git/$(git-symbolic-ref HEAD) b.commitid'
  67
  68test_expect_success \
  69    'extract tar archive' \
  70    '(cd b && $TAR xf -) <b.tar'
  71
  72test_expect_success \
  73    'validate filenames' \
  74    '(cd b/a && find .) | sort >b.lst &&
  75     diff a.lst b.lst'
  76
  77test_expect_success \
  78    'validate file contents' \
  79    'diff -r a b/a'
  80
  81test_expect_success \
  82    'git-tar-tree with prefix' \
  83    'git-tar-tree HEAD prefix >c.tar'
  84
  85test_expect_success \
  86    'extract tar archive with prefix' \
  87    '(cd c && $TAR xf -) <c.tar'
  88
  89test_expect_success \
  90    'validate filenames with prefix' \
  91    '(cd c/prefix/a && find .) | sort >c.lst &&
  92     diff a.lst c.lst'
  93
  94test_expect_success \
  95    'validate file contents with prefix' \
  96    'diff -r a c/prefix/a'
  97
  98test_done