Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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 . ../cmdline/common.sh
18 . ./common.sh
20 test_clone_basic() {
21 local testroot=`test_init clone_basic 1`
23 cp -r ${GOTD_TEST_REPO} $testroot/repo-copy
25 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
26 ret=$?
27 if [ $ret -ne 0 ]; then
28 echo "got clone failed unexpectedly" >&2
29 test_done "$testroot" "1"
30 return 1
31 fi
33 # Verify that the clone operation worked fine.
34 git_fsck "$testroot" "$testroot/repo-clone"
35 ret=$?
36 if [ $ret -ne 0 ]; then
37 test_done "$testroot" "1"
38 return 1
39 fi
41 got tree -R -r "$testroot/repo-clone" > $testroot/stdout
42 cat > $testroot/stdout.expected <<EOF
43 alpha
44 beta
45 epsilon/
46 epsilon/zeta
47 gamma/
48 gamma/delta
49 EOF
50 cmp -s $testroot/stdout.expected $testroot/stdout
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 diff -u $testroot/stdout.expected $testroot/stdout
54 test_done "$testroot" "$ret"
55 return 1
56 fi
58 # cloning a repository should not result in modifications
59 diff -urN ${GOTD_TEST_REPO} $testroot/repo-copy \
60 > $testroot/stdout
61 echo -n > $testroot/stdout.expected
62 cmp -s $testroot/stdout.expected $testroot/stdout
63 ret=$?
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 test_done "$testroot" "$ret"
67 return 1
68 fi
70 test_done "$testroot" "$ret"
71 }
73 test_send_to_read_only_repo() {
74 local testroot=`test_init send_to_read_only_repo 1`
76 ls -R ${GOTD_TEST_REPO} > $testroot/repo-list.before
78 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
79 ret=$?
80 if [ $ret -ne 0 ]; then
81 echo "got clone failed unexpectedly" >&2
82 test_done "$testroot" "1"
83 return 1
84 fi
86 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
87 ret=$?
88 if [ $ret -ne 0 ]; then
89 echo "got checkout failed unexpectedly" >&2
90 test_done "$testroot" "1"
91 return 1
92 fi
94 mkdir $testroot/wt/psi
95 echo "new" > $testroot/wt/psi/new
96 (cd $testroot/wt && got add psi/new > /dev/null)
97 echo "more alpha" >> $testroot/wt/alpha
98 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
100 got send -q -r $testroot/repo-clone 2>$testroot/stderr.raw
101 ret=$?
102 if [ $ret -eq 0 ]; then
103 echo "got send succeeded unexpectedly" >&2
104 test_done "$testroot" "1"
105 return 1
106 fi
107 grep -v ^gotsh: $testroot/stderr.raw > $testroot/stderr
109 echo 'got-send-pack: test-repo: Permission denied' \
110 > $testroot/stderr.expected
111 echo 'got: could not send pack file' >> $testroot/stderr.expected
112 cmp -s $testroot/stderr.expected $testroot/stderr
113 ret=$?
114 if [ $ret -ne 0 ]; then
115 diff -u $testroot/stderr.expected $testroot/stderr
116 fi
117 test_done "$testroot" "$ret"
120 test_parseargs "$@"
121 run_test test_clone_basic
122 run_test test_send_to_read_only_repo