]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5000-tar-tree.sh
Missing statics.
[thirdparty/git.git] / t / t5000-tar-tree.sh
CommitLineData
d3d49c3d
RS
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
5b860406
RS
8This test covers the topics of file contents, commit date handling and
9commit id embedding:
d3d49c3d
RS
10
11 The contents of the repository is compared to the extracted tar
12 archive. The repository contains simple text files, symlinks and a
3dff5379 13 binary file (/bin/sh). Only paths shorter than 99 characters are
5b860406 14 used.
d3d49c3d
RS
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
cb34882b 28TAR=${TAR:-tar}
62cdce17 29UNZIP=${UNZIP:-unzip}
d3d49c3d
RS
30
31test_expect_success \
32 'populate workdir' \
33 'mkdir a b c &&
d3d49c3d 34 echo simple textfile >a/a &&
d3d49c3d 35 mkdir a/bin &&
5b860406 36 cp /bin/sh a/bin &&
d3d49c3d 37 ln -s a a/l1 &&
4c691724
RS
38 (p=long_path_to_a_file && cd a &&
39 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
40 echo text >file_with_long_path) &&
d3d49c3d
RS
41 (cd a && find .) | sort >a.lst'
42
43test_expect_success \
44 'add files to repository' \
215a7ad1
JH
45 'find a -type f | xargs git-update-index --add &&
46 find a -type l | xargs git-update-index --add &&
d3d49c3d
RS
47 treeid=`git-write-tree` &&
48 echo $treeid >treeid &&
0a81552e
JS
49 git-update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
50 git-commit-tree $treeid </dev/null)'
d3d49c3d 51
8ff21b1a
RS
52test_expect_success \
53 'git-archive' \
54 'git-archive HEAD >b.tar'
55
d3d49c3d
RS
56test_expect_success \
57 'git-tar-tree' \
8ff21b1a
RS
58 'git-tar-tree HEAD >b2.tar'
59
60test_expect_success \
61 'git-archive vs. git-tar-tree' \
62 'diff b.tar b2.tar'
d3d49c3d
RS
63
64test_expect_success \
65 'validate file modification time' \
455a7f32 66 'TZ=GMT $TAR tvf b.tar a/a |
7737314d
MA
67 awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
68 >b.mtime &&
d3d49c3d
RS
69 echo "2005-05-27 22:00:00" >expected.mtime &&
70 diff expected.mtime b.mtime'
71
72test_expect_success \
73 'git-get-tar-commit-id' \
74 'git-get-tar-commit-id <b.tar >b.commitid &&
0a81552e 75 diff .git/$(git-symbolic-ref HEAD) b.commitid'
d3d49c3d
RS
76
77test_expect_success \
78 'extract tar archive' \
455a7f32 79 '(cd b && $TAR xf -) <b.tar'
d3d49c3d
RS
80
81test_expect_success \
82 'validate filenames' \
83 '(cd b/a && find .) | sort >b.lst &&
84 diff a.lst b.lst'
85
86test_expect_success \
87 'validate file contents' \
88 'diff -r a b/a'
89
90test_expect_success \
91 'git-tar-tree with prefix' \
92 'git-tar-tree HEAD prefix >c.tar'
93
94test_expect_success \
95 'extract tar archive with prefix' \
455a7f32 96 '(cd c && $TAR xf -) <c.tar'
d3d49c3d
RS
97
98test_expect_success \
99 'validate filenames with prefix' \
100 '(cd c/prefix/a && find .) | sort >c.lst &&
101 diff a.lst c.lst'
102
103test_expect_success \
104 'validate file contents with prefix' \
105 'diff -r a c/prefix/a'
106
62cdce17
RS
107test_expect_success \
108 'git-archive --format=zip' \
109 'git-archive --format=zip HEAD >d.zip'
110
3a86f36b
JS
111$UNZIP -v 2>/dev/null
112if [ $? -eq 127 ]; then
113 echo "Skipping ZIP tests, because unzip was not found"
114 test_done
115 exit
116fi
117
62cdce17
RS
118test_expect_success \
119 'extract ZIP archive' \
120 '(mkdir d && cd d && $UNZIP ../d.zip)'
121
122test_expect_success \
123 'validate filenames' \
124 '(cd d/a && find .) | sort >d.lst &&
125 diff a.lst d.lst'
126
127test_expect_success \
128 'validate file contents' \
129 'diff -r a d/a'
130
131test_expect_success \
132 'git-archive --format=zip with prefix' \
133 'git-archive --format=zip --prefix=prefix/ HEAD >e.zip'
134
135test_expect_success \
136 'extract ZIP archive with prefix' \
137 '(mkdir e && cd e && $UNZIP ../e.zip)'
138
139test_expect_success \
140 'validate filenames with prefix' \
141 '(cd e/prefix/a && find .) | sort >e.lst &&
142 diff a.lst e.lst'
143
144test_expect_success \
145 'validate file contents with prefix' \
146 'diff -r a e/prefix/a'
147
265d5280
RS
148test_expect_success \
149 'git-archive --list outside of a git repo' \
150 'GIT_DIR=some/non-existing/directory git-archive --list'
151
d3d49c3d 152test_done