Windows ANSI - hook write()
[git/mingw/4msysgit/peterh.git] / t / t5000-tar-tree.sh
blob7e0b83b03c58338cb8414ed98900238eef3eb1e9
1 #!/bin/sh
3 # Copyright (C) 2005 Rene Scharfe
6 test_description='git tar-tree and git get-tar-commit-id test
8 This test covers the topics of file contents, commit date handling and
9 commit id embedding:
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.
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.
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.
27 . ./test-lib.sh
28 TAR=${TAR:-tar}
29 UNZIP=${UNZIP:-unzip}
31 test "$no_symlinks" && {
32 function ln () {
33 test "$1" = -s && shift
34 date > "$2"
38 SUBSTFORMAT=%H%n
40 test_expect_success \
41 'populate workdir' \
42 'mkdir a b c &&
43 echo simple textfile >a/a &&
44 mkdir a/bin &&
45 cp /bin/sh a/bin &&
46 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
47 printf "A not substituted O" >a/substfile2 &&
48 ln -s a a/l1 &&
49 (p=long_path_to_a_file && cd a &&
50 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
51 echo text >file_with_long_path) &&
52 (cd a && find .) | sort >a.lst'
54 test_expect_success \
55 'add files to repository' \
56 'find a -type f | xargs git update-index --add &&
57 find a -type l | xargs git update-index --add &&
58 treeid=`git write-tree` &&
59 echo $treeid >treeid &&
60 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
61 git commit-tree $treeid </dev/null)'
63 test_expect_success \
64 'git archive' \
65 'git archive HEAD >b.tar'
67 test_expect_success \
68 'git tar-tree' \
69 'git tar-tree HEAD >b2.tar'
71 test_expect_success \
72 'git archive vs. git tar-tree' \
73 'diff b.tar b2.tar'
75 test_expect_success \
76 'validate file modification time' \
77 'mkdir extract &&
78 $TAR xf b.tar -C extract a/a &&
79 perl -e '\''print((stat("extract/a/a"))[9], "\n")'\'' >b.mtime &&
80 echo "1117231200" >expected.mtime &&
81 diff expected.mtime b.mtime'
83 test_expect_success \
84 'git get-tar-commit-id' \
85 'git get-tar-commit-id <b.tar >b.commitid &&
86 diff .git/$(git symbolic-ref HEAD) b.commitid'
88 test_expect_success \
89 'extract tar archive' \
90 '(cd b && $TAR xf -) <b.tar'
92 test_expect_success \
93 'validate filenames' \
94 '(cd b/a && find .) | sort >b.lst &&
95 diff a.lst b.lst'
97 test_expect_success \
98 'validate file contents' \
99 'diff -r a b/a'
101 test_expect_success \
102 'git tar-tree with prefix' \
103 'git tar-tree HEAD prefix >c.tar'
105 test_expect_success \
106 'extract tar archive with prefix' \
107 '(cd c && $TAR xf -) <c.tar'
109 test_expect_success \
110 'validate filenames with prefix' \
111 '(cd c/prefix/a && find .) | sort >c.lst &&
112 diff a.lst c.lst'
114 test_expect_success \
115 'validate file contents with prefix' \
116 'diff -r a c/prefix/a'
118 test_expect_success \
119 'create archives with substfiles' \
120 'echo "substfile?" export-subst >a/.gitattributes &&
121 git archive HEAD >f.tar &&
122 git archive --prefix=prefix/ HEAD >g.tar &&
123 rm a/.gitattributes'
125 test_expect_success \
126 'extract substfiles' \
127 '(mkdir f && cd f && $TAR xf -) <f.tar'
129 test_expect_success \
130 'validate substfile contents' \
131 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
132 >f/a/substfile1.expected &&
133 diff f/a/substfile1.expected f/a/substfile1 &&
134 diff a/substfile2 f/a/substfile2
137 test_expect_success \
138 'extract substfiles from archive with prefix' \
139 '(mkdir g && cd g && $TAR xf -) <g.tar'
141 test_expect_success \
142 'validate substfile contents from archive with prefix' \
143 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
144 >g/prefix/a/substfile1.expected &&
145 diff g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
146 diff a/substfile2 g/prefix/a/substfile2
149 test_expect_success \
150 'git archive --format=zip' \
151 'git archive --format=zip HEAD >d.zip'
153 $UNZIP -v >/dev/null 2>&1
154 if [ $? -eq 127 ]; then
155 echo "Skipping ZIP tests, because unzip was not found"
156 test_done
157 exit
160 test_expect_success \
161 'extract ZIP archive' \
162 '(mkdir d && cd d && $UNZIP ../d.zip)'
164 test_expect_success \
165 'validate filenames' \
166 '(cd d/a && find .) | sort >d.lst &&
167 diff a.lst d.lst'
169 test_expect_success \
170 'validate file contents' \
171 'diff -r a d/a'
173 test_expect_success \
174 'git archive --format=zip with prefix' \
175 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
177 test_expect_success \
178 'extract ZIP archive with prefix' \
179 '(mkdir e && cd e && $UNZIP ../e.zip)'
181 test_expect_success \
182 'validate filenames with prefix' \
183 '(cd e/prefix/a && find .) | sort >e.lst &&
184 diff a.lst e.lst'
186 test_expect_success \
187 'validate file contents with prefix' \
188 'diff -r a e/prefix/a'
190 test_expect_success \
191 'git archive --list outside of a git repo' \
192 'GIT_DIR=some/non-existing/directory git archive --list'
194 test_done