git-push: make --thin pack transfer the default.
[git.git] / t / t5000-tar-tree.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2005 Rene Scharfe
4 #
5
6 test_description='git-tar-tree and git-get-tar-commit-id test
7
8 This test covers the topics of file contents, commit date handling and
9 commit 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
28 TAR=${TAR:-tar}
29
30 test_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      (cd a && find .) | sort >a.lst'
38
39 test_expect_success \
40     'add files to repository' \
41     'find a -type f | xargs git-update-index --add &&
42      find a -type l | xargs git-update-index --add &&
43      treeid=`git-write-tree` &&
44      echo $treeid >treeid &&
45      git-update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
46      git-commit-tree $treeid </dev/null)'
47
48 test_expect_success \
49     'git-tar-tree' \
50     'git-tar-tree HEAD >b.tar'
51
52 test_expect_success \
53     'validate file modification time' \
54     'TZ=GMT $TAR tvf b.tar a/a |
55      awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
56      >b.mtime &&
57      echo "2005-05-27 22:00:00" >expected.mtime &&
58      diff expected.mtime b.mtime'
59
60 test_expect_success \
61     'git-get-tar-commit-id' \
62     'git-get-tar-commit-id <b.tar >b.commitid &&
63      diff .git/$(git-symbolic-ref HEAD) b.commitid'
64
65 test_expect_success \
66     'extract tar archive' \
67     '(cd b && $TAR xf -) <b.tar'
68
69 test_expect_success \
70     'validate filenames' \
71     '(cd b/a && find .) | sort >b.lst &&
72      diff a.lst b.lst'
73
74 test_expect_success \
75     'validate file contents' \
76     'diff -r a b/a'
77
78 test_expect_success \
79     'git-tar-tree with prefix' \
80     'git-tar-tree HEAD prefix >c.tar'
81
82 test_expect_success \
83     'extract tar archive with prefix' \
84     '(cd c && $TAR xf -) <c.tar'
85
86 test_expect_success \
87     'validate filenames with prefix' \
88     '(cd c/prefix/a && find .) | sort >c.lst &&
89      diff a.lst c.lst'
90
91 test_expect_success \
92     'validate file contents with prefix' \
93     'diff -r a c/prefix/a'
94
95 test_done