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
30 # Check to see if PLATFORM has a value. PLATFORM is populated when running
31 # via `./configure && make` but this isn't guaranteed if an individual test is
32 # run directly, such as `regress/cmdline/tag.sh`. In such cases, PLATFORM
33 # will be empty, but we still want to use it. Since we test for non-linux
34 # values, only set PLATFORM if we're running on Linu so that the correct
36 [ -z "$PLATFORM" -a "$(uname)" = "Linux" ] && PLATFORM="linux"
41 [ "$PLATFORM" != "linux" ] && {
42 command -v "gdate" >/dev/null 2>&1 && {
45 echo "Couldn't find gdate is GNU coreutils installed?"
48 command "$DATECMD" "$@"
54 [ "$PLATFORM" != "linux" ] && {
55 command -v "gln" >/dev/null 2>&1 && {
58 echo "Couldn't find gln is GNU coreutils installed?"
68 # On non-linux systems, the sed command can happily accept "-i ''" as
69 # a valid command to not save backup files for in-place edits.
70 # However, on linux, "-i ''" would be treated as "-i" with a blank
71 # argument, and hence, no file to edit in-place, which is an error.
73 # Therefore, scan the argument list and remove "-i ''", replacing it
76 [ "$PLATFORM" = "linux" ] && {
84 [ "$seen" = "1" -a -z "$w" ] && {
88 command "$SEDCMD" -i "$@"
93 command "$SEDCMD" "$@"
101 # Switch the default branch to match our test expectations if needed.
102 # Only need to change HEAD since 'git init' did not create any refs.
103 # Relying on implementation details of 'git init' is no problem for us.
104 # We want to be alerted when Git changes fundamental assumptions such
105 # as what an empty repository looks like and where the default branch
106 # is set. In such cases Got's own tooling might well need to change
107 # its behaviour, too, and our tests should fail.
108 # TODO: Update all tests to assume 'main' instead of 'master' and
109 # switch to main here, to match Got's own default.
110 echo "ref: refs/heads/master" > "$1/.git/HEAD"
116 if [ -n "$GOT_TEST_PACK" ]; then
117 (cd $repo && git repack -a -q)
125 (cd $repo && git commit --author="$GOT_AUTHOR" -q -a "$@")
126 maybe_pack_repo $repo
133 (cd $repo && git rm -q "$@")
139 (cd $repo && git show --no-patch --pretty='format:%H')
142 git_show_branch_head()
146 (cd $repo && git show --no-patch --pretty='format:%H' $branch)
150 git_show_author_time()
154 (cd $repo && git show --no-patch --pretty='format:%at' $object)
157 git_show_tagger_time()
161 (cd $repo && git cat-file tag $tag | grep ^tagger | \
162 sed -e "s/^tagger $GOT_AUTHOR//" | cut -d' ' -f2)
165 git_show_parent_commit()
169 (cd $repo && git show --no-patch --pretty='format:%P' $commit)
175 (cd $repo && git show --no-patch --pretty='format:%T')
184 while [ "$trimcount" -gt 0 ]; do
186 trimcount=$((trimcount - 1))
197 (cd $repo && git commit-tree -m "$msg" "$tree")
205 (cd $repo && git fsck --strict \
206 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
208 if [ $ret -ne 0 ]; then
210 cat $testroot/fsck.stderr
211 echo "git fsck failed; leaving test data in $testroot"
222 echo alpha > $repo/alpha
223 echo beta > $repo/beta
225 echo delta > $repo/gamma/delta
227 echo zeta > $repo/epsilon/zeta
230 make_single_file_repo()
237 echo "this is file $file" > $repo/$file
238 (cd $repo && git add .)
239 git_commit $repo -m "intialize $repo with file $file"
242 get_loose_object_path()
246 local id0=`trim_obj_id 38 $id`
247 local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
248 echo "$repo/.git/objects/$id0/$idrest"
257 got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \
265 if [ -z "$testname" ]; then
266 echo "No test name provided" >&2
269 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
271 git_init $testroot/repo
272 if [ -z "$no_tree" ]; then
273 make_test_tree $testroot/repo
274 (cd $repo && git add .)
275 git_commit $testroot/repo -m "adding the test tree"
277 touch $testroot/repo/.git/git-daemon-export-ok
285 git_fsck $testroot $testroot/repo
287 if [ $ret -ne 0 ]; then
296 while getopts qr: flag; do
298 q) export GOT_TEST_QUIET=1
300 r) export GOT_TEST_ROOT=$OPTARG
302 ?) echo "Supported options:"
303 echo " -q: quiet mode"
304 echo " -r PATH: use PATH as test data root directory"
314 if [ -z "$GOT_TEST_QUIET" ]; then
324 if [ "$result" = "0" ]; then
325 test_cleanup "$testroot" || return 1
326 if [ -z "$GOT_TEST_QUIET" ]; then
329 elif echo "$result" | grep -q "^xfail"; then
330 # expected test failure; test reproduces an unfixed bug
332 test_cleanup "$testroot" || return 1
334 echo "test failed; leaving test data in $testroot"