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"
26 export GOT_IGNORE_GITCONFIG=1
28 export MALLOC_OPTIONS=S
34 # Switch the default branch to match our test expectations if needed.
35 # Only need to change HEAD since 'git init' did not create any refs.
36 # Relying on implementation details of 'git init' is no problem for us.
37 # We want to be alerted when Git changes fundamental assumptions such
38 # as what an empty repository looks like and where the default branch
39 # is set. In such cases Got's own tooling might well need to change
40 # its behaviour, too, and our tests should fail.
41 # TODO: Update all tests to assume 'main' instead of 'master' and
42 # switch to main here, to match Got's own default.
43 echo "ref: refs/heads/master" > "$1/.git/HEAD"
49 if [ -n "$GOT_TEST_PACK" ]; then
50 (cd $repo && gotadmin pack -a > /dev/null)
51 (cd $repo && gotadmin cleanup -a -q)
59 (cd $repo && git commit --author="$GOT_AUTHOR" -q -a "$@")
67 (cd $repo && git rm -q "$@")
73 (cd $repo && git show --no-patch --pretty='format:%H')
76 git_show_branch_head()
80 (cd $repo && git show --no-patch --pretty='format:%H' $branch)
84 git_show_author_time()
88 (cd $repo && git show --no-patch --pretty='format:%at' $object)
91 git_show_tagger_time()
95 (cd $repo && git cat-file tag $tag | grep ^tagger | \
96 sed -e "s/^tagger $GOT_AUTHOR//" | cut -d' ' -f2)
99 git_show_parent_commit()
103 (cd $repo && git show --no-patch --pretty='format:%P' $commit)
109 (cd $repo && git show --no-patch --pretty='format:%T')
118 while [ "$trimcount" -gt 0 ]; do
120 trimcount=$((trimcount - 1))
131 (cd $repo && git commit-tree -m "$msg" "$tree")
139 (cd $repo && git fsck --strict \
140 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
142 if [ $ret -ne 0 ]; then
144 cat $testroot/fsck.stderr
145 echo "git fsck failed; leaving test data in $testroot"
156 echo alpha > $repo/alpha
157 echo beta > $repo/beta
159 echo delta > $repo/gamma/delta
161 echo zeta > $repo/epsilon/zeta
164 make_single_file_repo()
171 echo "this is file $file" > $repo/$file
172 (cd $repo && git add .)
173 git_commit $repo -m "intialize $repo with file $file"
176 get_loose_object_path()
180 local id0=`trim_obj_id 38 $id`
181 local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
182 echo "$repo/.git/objects/$id0/$idrest"
191 got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \
199 if [ -z "$testname" ]; then
200 echo "No test name provided" >&2
203 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
205 git_init $testroot/repo
206 if [ -z "$no_tree" ]; then
207 make_test_tree $testroot/repo
208 (cd $repo && git add .)
209 git_commit $testroot/repo -m "adding the test tree"
211 touch $testroot/repo/.git/git-daemon-export-ok
219 git_fsck $testroot $testroot/repo
221 if [ $ret -ne 0 ]; then
230 while getopts qr: flag; do
232 q) export GOT_TEST_QUIET=1
234 r) export GOT_TEST_ROOT=$OPTARG
236 ?) echo "Supported options:"
237 echo " -q: quiet mode"
238 echo " -r PATH: use PATH as test data root directory"
248 if [ -z "$GOT_TEST_QUIET" ]; then
258 if [ "$result" = "0" ]; then
259 test_cleanup "$testroot" || return 1
260 if [ -z "$GOT_TEST_QUIET" ]; then
263 elif echo "$result" | grep -q "^xfail"; then
264 # expected test failure; test reproduces an unfixed bug
266 test_cleanup "$testroot" || return 1
268 echo "test failed; leaving test data in $testroot"