gitweb: Test if $from_id and $to_id are defined before comparison
[git/git-p4.git] / t / t5000-tar-tree.sh
blobe223c074f043571ff868a2f4783c7cc155185004
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_expect_success \
32 'populate workdir' \
33 'mkdir a b c &&
34 echo simple textfile >a/a &&
35 mkdir a/bin &&
36 cp /bin/sh a/bin &&
37 ln -s a a/l1 &&
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) &&
41 (cd a && find .) | sort >a.lst'
43 test_expect_success \
44 'add files to repository' \
45 'find a -type f | xargs git-update-index --add &&
46 find a -type l | xargs git-update-index --add &&
47 treeid=`git-write-tree` &&
48 echo $treeid >treeid &&
49 git-update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
50 git-commit-tree $treeid </dev/null)'
52 test_expect_success \
53 'git-archive' \
54 'git-archive HEAD >b.tar'
56 test_expect_success \
57 'git-tar-tree' \
58 'git-tar-tree HEAD >b2.tar'
60 test_expect_success \
61 'git-archive vs. git-tar-tree' \
62 'diff b.tar b2.tar'
64 test_expect_success \
65 'validate file modification time' \
66 'TZ=GMT $TAR tvf b.tar a/a |
67 awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
68 >b.mtime &&
69 echo "2005-05-27 22:00:00" >expected.mtime &&
70 diff expected.mtime b.mtime'
72 test_expect_success \
73 'git-get-tar-commit-id' \
74 'git-get-tar-commit-id <b.tar >b.commitid &&
75 diff .git/$(git-symbolic-ref HEAD) b.commitid'
77 test_expect_success \
78 'extract tar archive' \
79 '(cd b && $TAR xf -) <b.tar'
81 test_expect_success \
82 'validate filenames' \
83 '(cd b/a && find .) | sort >b.lst &&
84 diff a.lst b.lst'
86 test_expect_success \
87 'validate file contents' \
88 'diff -r a b/a'
90 test_expect_success \
91 'git-tar-tree with prefix' \
92 'git-tar-tree HEAD prefix >c.tar'
94 test_expect_success \
95 'extract tar archive with prefix' \
96 '(cd c && $TAR xf -) <c.tar'
98 test_expect_success \
99 'validate filenames with prefix' \
100 '(cd c/prefix/a && find .) | sort >c.lst &&
101 diff a.lst c.lst'
103 test_expect_success \
104 'validate file contents with prefix' \
105 'diff -r a c/prefix/a'
107 test_expect_success \
108 'git-archive --format=zip' \
109 'git-archive --format=zip HEAD >d.zip'
111 test_expect_success \
112 'extract ZIP archive' \
113 '(mkdir d && cd d && $UNZIP ../d.zip)'
115 test_expect_success \
116 'validate filenames' \
117 '(cd d/a && find .) | sort >d.lst &&
118 diff a.lst d.lst'
120 test_expect_success \
121 'validate file contents' \
122 'diff -r a d/a'
124 test_expect_success \
125 'git-archive --format=zip with prefix' \
126 'git-archive --format=zip --prefix=prefix/ HEAD >e.zip'
128 test_expect_success \
129 'extract ZIP archive with prefix' \
130 '(mkdir e && cd e && $UNZIP ../e.zip)'
132 test_expect_success \
133 'validate filenames with prefix' \
134 '(cd e/prefix/a && find .) | sort >e.lst &&
135 diff a.lst e.lst'
137 test_expect_success \
138 'validate file contents with prefix' \
139 'diff -r a e/prefix/a'
141 test_expect_success \
142 'git-archive --list outside of a git repo' \
143 'GIT_DIR=some/non-existing/directory git-archive --list'
145 test_done