Blame


1 e9424ba1 2022-09-20 thomas #!/bin/sh
2 e9424ba1 2022-09-20 thomas #
3 e9424ba1 2022-09-20 thomas # Copyright (c) 2022 Mark Jamsek <mark@jamsek.dev>
4 e9424ba1 2022-09-20 thomas #
5 e9424ba1 2022-09-20 thomas # Permission to use, copy, modify, and distribute this software for any
6 e9424ba1 2022-09-20 thomas # purpose with or without fee is hereby granted, provided that the above
7 e9424ba1 2022-09-20 thomas # copyright notice and this permission notice appear in all copies.
8 e9424ba1 2022-09-20 thomas #
9 e9424ba1 2022-09-20 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 e9424ba1 2022-09-20 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 e9424ba1 2022-09-20 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 e9424ba1 2022-09-20 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 e9424ba1 2022-09-20 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 e9424ba1 2022-09-20 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 e9424ba1 2022-09-20 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 e9424ba1 2022-09-20 thomas
17 e9424ba1 2022-09-20 thomas . ./common.sh
18 e9424ba1 2022-09-20 thomas
19 e9424ba1 2022-09-20 thomas test_init_basic() {
20 e9424ba1 2022-09-20 thomas local testname=init_basic
21 d6e78555 2023-06-01 thomas local testroot=`mktemp -d \
22 d6e78555 2023-06-01 thomas "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
23 e9424ba1 2022-09-20 thomas local headref=main
24 e9424ba1 2022-09-20 thomas
25 e9424ba1 2022-09-20 thomas gotadmin init $testroot/repo
26 e9424ba1 2022-09-20 thomas
27 d1e03b8c 2023-10-08 thomas local git_head=`git -C $testroot/repo symbolic-ref HEAD`
28 e9424ba1 2022-09-20 thomas echo $git_head > $testroot/content
29 e9424ba1 2022-09-20 thomas echo refs/heads/$headref > $testroot/content.expected
30 e9424ba1 2022-09-20 thomas cmp -s $testroot/content.expected $testroot/content
31 e9424ba1 2022-09-20 thomas ret=$?
32 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
33 e9424ba1 2022-09-20 thomas echo "fail"
34 e9424ba1 2022-09-20 thomas diff -u $testroot/content.expected $testroot/content
35 e9424ba1 2022-09-20 thomas fi
36 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
37 e9424ba1 2022-09-20 thomas }
38 e9424ba1 2022-09-20 thomas
39 e9424ba1 2022-09-20 thomas test_init_specified_head() {
40 e9424ba1 2022-09-20 thomas local testname=init_specified_head
41 d6e78555 2023-06-01 thomas local testroot=`mktemp -d \
42 d6e78555 2023-06-01 thomas "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
43 e9424ba1 2022-09-20 thomas local headref=trunk
44 e9424ba1 2022-09-20 thomas
45 e9424ba1 2022-09-20 thomas gotadmin init -b $headref $testroot/repo
46 e9424ba1 2022-09-20 thomas
47 d1e03b8c 2023-10-08 thomas local git_head=`git -C $testroot/repo symbolic-ref HEAD`
48 e9424ba1 2022-09-20 thomas echo refs/heads/$headref > $testroot/content.expected
49 e9424ba1 2022-09-20 thomas echo $git_head > $testroot/content
50 e9424ba1 2022-09-20 thomas cmp -s $testroot/content.expected $testroot/content
51 e9424ba1 2022-09-20 thomas ret=$?
52 e9424ba1 2022-09-20 thomas if [ $ret -ne 0 ]; then
53 e9424ba1 2022-09-20 thomas echo "fail"
54 e9424ba1 2022-09-20 thomas diff -u $testroot/content.expected $testroot/content
55 e9424ba1 2022-09-20 thomas fi
56 e9424ba1 2022-09-20 thomas test_done "$testroot" "$ret"
57 e9424ba1 2022-09-20 thomas }
58 e9424ba1 2022-09-20 thomas
59 e9424ba1 2022-09-20 thomas test_parseargs "$@"
60 e9424ba1 2022-09-20 thomas run_test test_init_basic
61 e9424ba1 2022-09-20 thomas run_test test_init_specified_head