Merge commit 'spearce/master'
[git/mingw.git] / t / t5000-tar-tree.sh
blobe1772076dcbeca6c3207da71fc630753f35f0e7c
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 'TZ=GMT $TAR tvf b.tar a/a |
78 awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
79 >b.mtime &&
80 echo "2005-05-27 22:00:00" >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 an archive with a substfiles' \
120 'echo "substfile?" export-subst >a/.gitattributes &&
121 git archive HEAD >f.tar &&
122 rm a/.gitattributes'
124 test_expect_success \
125 'extract substfiles' \
126 '(mkdir f && cd f && $TAR xf -) <f.tar'
128 test_expect_success \
129 'validate substfile contents' \
130 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
131 >f/a/substfile1.expected &&
132 diff f/a/substfile1.expected f/a/substfile1 &&
133 diff a/substfile2 f/a/substfile2
136 test_expect_success \
137 'git archive --format=zip' \
138 'git archive --format=zip HEAD >d.zip'
140 $UNZIP -v >/dev/null 2>&1
141 if [ $? -eq 127 ]; then
142 echo "Skipping ZIP tests, because unzip was not found"
143 test_done
144 exit
147 test_expect_success \
148 'extract ZIP archive' \
149 '(mkdir d && cd d && $UNZIP ../d.zip)'
151 test_expect_success \
152 'validate filenames' \
153 '(cd d/a && find .) | sort >d.lst &&
154 diff a.lst d.lst'
156 test_expect_success \
157 'validate file contents' \
158 'diff -r a d/a'
160 test_expect_success \
161 'git archive --format=zip with prefix' \
162 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
164 test_expect_success \
165 'extract ZIP archive with prefix' \
166 '(mkdir e && cd e && $UNZIP ../e.zip)'
168 test_expect_success \
169 'validate filenames with prefix' \
170 '(cd e/prefix/a && find .) | sort >e.lst &&
171 diff a.lst e.lst'
173 test_expect_success \
174 'validate file contents with prefix' \
175 'diff -r a e/prefix/a'
177 test_expect_success \
178 'git archive --list outside of a git repo' \
179 'GIT_DIR=some/non-existing/directory git archive --list'
181 test_done