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_AUTHOR_11="flan_hacker"
24 export GOT_LOG_DEFAULT_LIMIT=0
25 export GOT_TEST_ROOT="/tmp"
27 export MALLOC_OPTIONS=S
37 if [ -n "$GOT_TEST_PACK" ]; then
38 (cd $repo && git repack -a -q)
46 (cd $repo && git commit --author="$GOT_AUTHOR" -q -a "$@")
54 (cd $repo && git rm -q "$@")
60 (cd $repo && git show --no-patch --pretty='format:%H')
63 git_show_branch_head()
67 (cd $repo && git show --no-patch --pretty='format:%H' $branch)
71 git_show_author_time()
75 (cd $repo && git show --no-patch --pretty='format:%at' $object)
78 git_show_tagger_time()
82 (cd $repo && git cat-file tag $tag | grep ^tagger | \
83 sed -e "s/^tagger $GOT_AUTHOR//" | cut -d' ' -f2)
86 git_show_parent_commit()
90 (cd $repo && git show --no-patch --pretty='format:%P' $commit)
96 (cd $repo && git show --no-patch --pretty='format:%T')
105 while [ "$trimcount" -gt 0 ]; do
107 trimcount=$((trimcount - 1))
118 (cd $repo && git commit-tree -m "$msg" "$tree")
119 maybe_pack_repo $repo
126 echo alpha > $repo/alpha
127 echo beta > $repo/beta
129 echo delta > $repo/gamma/delta
131 echo zeta > $repo/epsilon/zeta
134 make_single_file_repo()
141 echo "this is file $file" > $repo/$file
142 (cd $repo && git add .)
143 git_commit $repo -m "intialize $repo with file $file"
146 get_loose_object_path()
150 local id0=`trim_obj_id 38 $id`
151 local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
152 echo "$repo/.git/objects/$id0/$idrest"
161 got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \
169 if [ -z "$testname" ]; then
170 echo "No test name provided" >&2
173 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
175 git_init $testroot/repo
176 if [ -z "$no_tree" ]; then
177 make_test_tree $testroot/repo
178 (cd $repo && git add .)
179 git_commit $testroot/repo -m "adding the test tree"
181 touch $testroot/repo/.git/git-daemon-export-ok
189 (cd $testroot/repo && git fsck --strict \
190 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
192 if [ "$ret" != "0" ]; then
194 cat $testroot/fsck.stderr
195 echo "git fsck failed; leaving test data in $testroot"
204 while getopts qr: flag; do
206 q) export GOT_TEST_QUIET=1
208 r) export GOT_TEST_ROOT=$OPTARG
210 ?) echo "Supported options:"
211 echo " -q: quiet mode"
212 echo " -r PATH: use PATH as test data root directory"
222 if [ -z "$GOT_TEST_QUIET" ]; then
232 if [ "$result" = "0" ]; then
233 test_cleanup "$testroot" || return 1
234 if [ -z "$GOT_TEST_QUIET" ]; then
237 elif echo "$result" | grep -q "^xfail"; then
238 # expected test failure; test reproduces an unfixed bug
240 test_cleanup "$testroot" || return 1
242 echo "test failed; leaving test data in $testroot"