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
24 export GOT_TEST_ROOT="/tmp"
26 export MALLOC_OPTIONS=S
36 if [ -n "$GOT_TEST_PACK" ]; then
37 (cd $repo && git repack -a -q)
45 (cd $repo && git commit --author="$GOT_AUTHOR" -q -a "$@")
53 (cd $repo && git rm -q "$@")
59 (cd $repo && git show --no-patch --pretty='format:%H')
62 git_show_branch_head()
66 (cd $repo && git show --no-patch --pretty='format:%H' $branch)
70 git_show_author_time()
74 (cd $repo && git show --no-patch --pretty='format:%at' $object)
77 git_show_tagger_time()
81 (cd $repo && git cat-file tag $tag | grep ^tagger | \
82 sed -e "s/^tagger $GOT_AUTHOR//" | cut -d' ' -f2)
85 git_show_parent_commit()
89 (cd $repo && git show --no-patch --pretty='format:%P' $commit)
95 (cd $repo && git show --no-patch --pretty='format:%T')
104 while [ "$trimcount" -gt 0 ]; do
106 trimcount=$((trimcount - 1))
117 (cd $repo && git commit-tree -m "$msg" "$tree")
118 maybe_pack_repo $repo
125 echo alpha > $repo/alpha
126 echo beta > $repo/beta
128 echo delta > $repo/gamma/delta
130 echo zeta > $repo/epsilon/zeta
133 make_single_file_repo()
140 echo "this is file $file" > $repo/$file
141 (cd $repo && git add .)
142 git_commit $repo -m "intialize $repo with file $file"
145 get_loose_object_path()
149 local id0=`trim_obj_id 38 $id`
150 local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
151 echo "$repo/.git/objects/$id0/$idrest"
160 got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \
168 if [ -z "$testname" ]; then
169 echo "No test name provided" >&2
172 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
174 git_init $testroot/repo
175 if [ -z "$no_tree" ]; then
176 make_test_tree $testroot/repo
177 (cd $repo && git add .)
178 git_commit $testroot/repo -m "adding the test tree"
180 touch $testroot/repo/.git/git-daemon-export-ok
188 (cd $testroot/repo && git fsck --strict \
189 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
191 if [ "$ret" != "0" ]; then
193 cat $testroot/fsck.stderr
194 echo "git fsck failed; leaving test data in $testroot"
203 while getopts qr: flag; do
205 q) export GOT_TEST_QUIET=1
207 r) export GOT_TEST_ROOT=$OPTARG
209 ?) echo "Supported options:"
210 echo " -q: quiet mode"
211 echo " -r PATH: use PATH as test data root directory"
221 if [ -z "$GOT_TEST_QUIET" ]; then
231 if [ "$result" == "0" ]; then
232 test_cleanup "$testroot" || return 1
233 if [ -z "$GOT_TEST_QUIET" ]; then
236 elif echo "$result" | grep -q "^xfail"; then
237 # expected test failure; test reproduces an unfixed bug
239 test_cleanup "$testroot" || return 1
241 echo "test failed; leaving test data in $testroot"