3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 export GIT_AUTHOR_NAME="Flan Hacker"
18 export GIT_AUTHOR_EMAIL="flan_hacker@openbsd.org"
19 export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
20 export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
21 export GOT_AUTHOR="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
22 export GOT_AUTHOR_8="flan_hac"
23 export GOT_LOG_DEFAULT_LIMIT=0
25 export MALLOC_OPTIONS=S
32 function maybe_pack_repo
35 if [ -n "$GOT_TEST_PACK" ]; then
36 (cd $repo && git repack -a -q)
44 (cd $repo && git commit --author="$GOT_AUTHOR" -q -a "$@")
52 (cd $repo && git rm -q "$@")
55 function git_show_head
58 (cd $repo && git show --no-patch --pretty='format:%H')
61 function git_show_branch_head
65 (cd $repo && git show --no-patch --pretty='format:%H' $branch)
69 function git_show_author_time
73 (cd $repo && git show --no-patch --pretty='format:%at' $object)
76 function git_show_tagger_time
80 (cd $repo && git cat-file tag $tag | grep ^tagger | \
81 sed -e "s/^tagger $GOT_AUTHOR//" | cut -d' ' -f2)
84 function git_show_parent_commit
88 (cd $repo && git show --no-patch --pretty='format:%P' $commit)
91 function git_show_tree
94 (cd $repo && git show --no-patch --pretty='format:%T')
103 while [ trimcount -gt 0 ]; do
111 function git_commit_tree
116 (cd $repo && git commit-tree -m "$msg" "$tree")
117 maybe_pack_repo $repo
120 function make_test_tree
124 echo alpha > $repo/alpha
125 echo beta > $repo/beta
127 echo delta > $repo/gamma/delta
129 echo zeta > $repo/epsilon/zeta
132 function make_single_file_repo
139 echo "this is file $file" > $repo/$file
140 (cd $repo && git add .)
141 git_commit $repo -m "intialize $repo with file $file"
144 function get_loose_object_path
148 local id0=`trim_obj_id 38 $id`
149 local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
150 echo "$repo/.git/objects/$id0/$idrest"
159 got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \
167 if [ -z "$testname" ]; then
168 echo "No test name provided" >&2
171 local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
173 git_init $testroot/repo
174 if [ -z "$no_tree" ]; then
175 make_test_tree $testroot/repo
176 (cd $repo && git add .)
177 git_commit $testroot/repo -m "adding the test tree"
179 touch $testroot/repo/.git/git-daemon-export-ok
183 function test_cleanup
187 (cd $testroot/repo && git fsck --strict \
188 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
190 if [ "$ret" != "0" ]; then
192 cat $testroot/fsck.stderr
193 echo "git fsck failed; leaving test data in $testroot"
211 if [ "$result" == "0" ]; then
212 test_cleanup "$testroot" || return 1
214 elif echo "$result" | grep -q "^xfail"; then
215 # expected test failure; test reproduces an unfixed bug
217 test_cleanup "$testroot" || return 1
219 echo "test failed; leaving test data in $testroot"