Blame


1 f8a36e22 2021-08-26 stsp #!/bin/sh
2 f8a36e22 2021-08-26 stsp #
3 f8a36e22 2021-08-26 stsp # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 f8a36e22 2021-08-26 stsp #
5 f8a36e22 2021-08-26 stsp # Permission to use, copy, modify, and distribute this software for any
6 f8a36e22 2021-08-26 stsp # purpose with or without fee is hereby granted, provided that the above
7 f8a36e22 2021-08-26 stsp # copyright notice and this permission notice appear in all copies.
8 f8a36e22 2021-08-26 stsp #
9 f8a36e22 2021-08-26 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 f8a36e22 2021-08-26 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 f8a36e22 2021-08-26 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 f8a36e22 2021-08-26 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 f8a36e22 2021-08-26 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 f8a36e22 2021-08-26 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 f8a36e22 2021-08-26 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 f8a36e22 2021-08-26 stsp
17 f8a36e22 2021-08-26 stsp . ./common.sh
18 f8a36e22 2021-08-26 stsp
19 f8a36e22 2021-08-26 stsp test_send_basic() {
20 f8a36e22 2021-08-26 stsp local testroot=`test_init send_basic`
21 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
22 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
23 f8a36e22 2021-08-26 stsp
24 f8a36e22 2021-08-26 stsp got clone -q $testurl/repo $testroot/repo-clone
25 f8a36e22 2021-08-26 stsp ret="$?"
26 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
27 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
28 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
29 f8a36e22 2021-08-26 stsp return 1
30 f8a36e22 2021-08-26 stsp fi
31 f8a36e22 2021-08-26 stsp cat > $testroot/repo/.git/got.conf <<EOF
32 f8a36e22 2021-08-26 stsp remote "origin" {
33 f8a36e22 2021-08-26 stsp protocol ssh
34 f8a36e22 2021-08-26 stsp server 127.0.0.1
35 f8a36e22 2021-08-26 stsp repository "$testroot/repo-clone"
36 f8a36e22 2021-08-26 stsp }
37 f8a36e22 2021-08-26 stsp EOF
38 f8a36e22 2021-08-26 stsp got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
39 f8a36e22 2021-08-26 stsp tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
40 f8a36e22 2021-08-26 stsp | tr -d ' ' | cut -d: -f2`
41 f8a36e22 2021-08-26 stsp
42 f8a36e22 2021-08-26 stsp echo "modified alpha" > $testroot/repo/alpha
43 f8a36e22 2021-08-26 stsp git_commit $testroot/repo -m "modified alpha"
44 f8a36e22 2021-08-26 stsp local commit_id2=`git_show_head $testroot/repo`
45 f8a36e22 2021-08-26 stsp
46 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
47 f8a36e22 2021-08-26 stsp ret="$?"
48 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
49 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
50 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
51 f8a36e22 2021-08-26 stsp return 1
52 f8a36e22 2021-08-26 stsp fi
53 f8a36e22 2021-08-26 stsp
54 f8a36e22 2021-08-26 stsp echo -n > $testroot/stdout.expected
55 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
56 f8a36e22 2021-08-26 stsp ret="$?"
57 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
58 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
59 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
60 f8a36e22 2021-08-26 stsp return 1
61 f8a36e22 2021-08-26 stsp fi
62 f8a36e22 2021-08-26 stsp
63 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo > $testroot/stdout
64 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
65 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
66 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
67 f8a36e22 2021-08-26 stsp return 1
68 f8a36e22 2021-08-26 stsp fi
69 f8a36e22 2021-08-26 stsp
70 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
71 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
72 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id2" \
73 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
74 f8a36e22 2021-08-26 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
75 f8a36e22 2021-08-26 stsp
76 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
77 f8a36e22 2021-08-26 stsp ret="$?"
78 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
79 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
80 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
81 f8a36e22 2021-08-26 stsp return 1
82 f8a36e22 2021-08-26 stsp fi
83 f8a36e22 2021-08-26 stsp
84 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
85 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
86 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
87 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
88 f8a36e22 2021-08-26 stsp return 1
89 f8a36e22 2021-08-26 stsp fi
90 f8a36e22 2021-08-26 stsp
91 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
92 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
93 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
94 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
95 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id" \
96 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
97 f8a36e22 2021-08-26 stsp
98 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
99 f8a36e22 2021-08-26 stsp ret="$?"
100 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
101 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
102 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
103 f8a36e22 2021-08-26 stsp return 1
104 f8a36e22 2021-08-26 stsp fi
105 f8a36e22 2021-08-26 stsp
106 f8a36e22 2021-08-26 stsp got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
107 f8a36e22 2021-08-26 stsp ret="$?"
108 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
109 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
110 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
111 f8a36e22 2021-08-26 stsp return 1
112 f8a36e22 2021-08-26 stsp fi
113 f8a36e22 2021-08-26 stsp
114 f8a36e22 2021-08-26 stsp echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
115 f8a36e22 2021-08-26 stsp echo "Already up-to-date" >> $testroot/stdout.expected
116 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
117 f8a36e22 2021-08-26 stsp ret="$?"
118 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
119 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
120 f8a36e22 2021-08-26 stsp fi
121 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
122 f8a36e22 2021-08-26 stsp }
123 f8a36e22 2021-08-26 stsp
124 f8a36e22 2021-08-26 stsp test_send_rebase_required() {
125 f8a36e22 2021-08-26 stsp local testroot=`test_init send_rebase_required`
126 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
127 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
128 f8a36e22 2021-08-26 stsp
129 f8a36e22 2021-08-26 stsp got clone -q $testurl/repo $testroot/repo-clone
130 f8a36e22 2021-08-26 stsp ret="$?"
131 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
132 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
133 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
134 f8a36e22 2021-08-26 stsp return 1
135 f8a36e22 2021-08-26 stsp fi
136 f8a36e22 2021-08-26 stsp cat > $testroot/repo/.git/got.conf <<EOF
137 f8a36e22 2021-08-26 stsp remote "origin" {
138 f8a36e22 2021-08-26 stsp protocol ssh
139 f8a36e22 2021-08-26 stsp server 127.0.0.1
140 f8a36e22 2021-08-26 stsp repository "$testroot/repo-clone"
141 f8a36e22 2021-08-26 stsp }
142 f8a36e22 2021-08-26 stsp EOF
143 f8a36e22 2021-08-26 stsp echo "modified alpha" > $testroot/repo/alpha
144 f8a36e22 2021-08-26 stsp git_commit $testroot/repo -m "modified alpha"
145 f8a36e22 2021-08-26 stsp local commit_id2=`git_show_head $testroot/repo`
146 f8a36e22 2021-08-26 stsp
147 f8a36e22 2021-08-26 stsp got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
148 f8a36e22 2021-08-26 stsp echo "modified alpha, too" > $testroot/wt-clone/alpha
149 f8a36e22 2021-08-26 stsp (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
150 f8a36e22 2021-08-26 stsp
151 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
152 f8a36e22 2021-08-26 stsp ret="$?"
153 f9756a57 2021-08-26 stsp if [ "$ret" = "0" ]; then
154 f8a36e22 2021-08-26 stsp echo "got send command succeeded unexpectedly" >&2
155 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
156 f8a36e22 2021-08-26 stsp return 1
157 f8a36e22 2021-08-26 stsp fi
158 f8a36e22 2021-08-26 stsp
159 f8a36e22 2021-08-26 stsp echo -n > $testroot/stdout.expected
160 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
161 f8a36e22 2021-08-26 stsp ret="$?"
162 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
163 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
164 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
165 f8a36e22 2021-08-26 stsp return 1
166 f8a36e22 2021-08-26 stsp fi
167 f8a36e22 2021-08-26 stsp
168 f8a36e22 2021-08-26 stsp echo "got: refs/heads/master: fetch and rebase required" \
169 f8a36e22 2021-08-26 stsp > $testroot/stderr.expected
170 f8a36e22 2021-08-26 stsp cmp -s $testroot/stderr $testroot/stderr.expected
171 f8a36e22 2021-08-26 stsp ret="$?"
172 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
173 f8a36e22 2021-08-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
174 f8a36e22 2021-08-26 stsp fi
175 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
176 f8a36e22 2021-08-26 stsp }
177 f8a36e22 2021-08-26 stsp
178 f8a36e22 2021-08-26 stsp test_send_rebase_required_overwrite() {
179 f8a36e22 2021-08-26 stsp local testroot=`test_init send_rebase_required_overwrite`
180 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
181 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
182 f8a36e22 2021-08-26 stsp
183 f8a36e22 2021-08-26 stsp got clone -q $testurl/repo $testroot/repo-clone
184 f8a36e22 2021-08-26 stsp ret="$?"
185 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
186 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
187 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
188 f8a36e22 2021-08-26 stsp return 1
189 f8a36e22 2021-08-26 stsp fi
190 f8a36e22 2021-08-26 stsp cat > $testroot/repo/.git/got.conf <<EOF
191 f8a36e22 2021-08-26 stsp remote "foobar" {
192 f8a36e22 2021-08-26 stsp protocol ssh
193 f8a36e22 2021-08-26 stsp server 127.0.0.1
194 f8a36e22 2021-08-26 stsp repository "$testroot/repo-clone"
195 f8a36e22 2021-08-26 stsp }
196 f8a36e22 2021-08-26 stsp EOF
197 f8a36e22 2021-08-26 stsp echo "modified alpha" > $testroot/repo/alpha
198 f8a36e22 2021-08-26 stsp git_commit $testroot/repo -m "modified alpha"
199 f8a36e22 2021-08-26 stsp local commit_id2=`git_show_head $testroot/repo`
200 f8a36e22 2021-08-26 stsp
201 f8a36e22 2021-08-26 stsp got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
202 f8a36e22 2021-08-26 stsp echo "modified alpha, too" > $testroot/wt-clone/alpha
203 f8a36e22 2021-08-26 stsp (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
204 f8a36e22 2021-08-26 stsp local commit_id3=`git_show_head $testroot/repo-clone`
205 f8a36e22 2021-08-26 stsp
206 f8a36e22 2021-08-26 stsp # non-default remote requires an explicit argument
207 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -f > $testroot/stdout \
208 f8a36e22 2021-08-26 stsp 2> $testroot/stderr
209 f8a36e22 2021-08-26 stsp ret="$?"
210 f9756a57 2021-08-26 stsp if [ "$ret" = "0" ]; then
211 f8a36e22 2021-08-26 stsp echo "got send command succeeded unexpectedly" >&2
212 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
213 f8a36e22 2021-08-26 stsp return 1
214 f8a36e22 2021-08-26 stsp fi
215 f8a36e22 2021-08-26 stsp echo "got: origin: remote repository not found" \
216 f8a36e22 2021-08-26 stsp > $testroot/stderr.expected
217 f8a36e22 2021-08-26 stsp cmp -s $testroot/stderr $testroot/stderr.expected
218 f8a36e22 2021-08-26 stsp ret="$?"
219 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
220 f8a36e22 2021-08-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
221 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
222 f8a36e22 2021-08-26 stsp return 1
223 f8a36e22 2021-08-26 stsp fi
224 f8a36e22 2021-08-26 stsp
225 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -f foobar > $testroot/stdout \
226 f8a36e22 2021-08-26 stsp 2> $testroot/stderr
227 f8a36e22 2021-08-26 stsp ret="$?"
228 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
229 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
230 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
231 f8a36e22 2021-08-26 stsp return 1
232 f8a36e22 2021-08-26 stsp fi
233 f8a36e22 2021-08-26 stsp
234 f8a36e22 2021-08-26 stsp echo -n > $testroot/stdout.expected
235 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
236 f8a36e22 2021-08-26 stsp ret="$?"
237 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
238 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
239 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
240 f8a36e22 2021-08-26 stsp return 1
241 f8a36e22 2021-08-26 stsp fi
242 f8a36e22 2021-08-26 stsp
243 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo > $testroot/stdout
244 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
245 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
246 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
247 f8a36e22 2021-08-26 stsp return 1
248 f8a36e22 2021-08-26 stsp fi
249 f8a36e22 2021-08-26 stsp
250 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
251 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
252 f8a36e22 2021-08-26 stsp echo "refs/remotes/foobar/master: $commit_id2" \
253 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
254 f8a36e22 2021-08-26 stsp
255 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
256 f8a36e22 2021-08-26 stsp ret="$?"
257 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
258 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
259 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
260 f8a36e22 2021-08-26 stsp return 1
261 f8a36e22 2021-08-26 stsp fi
262 f8a36e22 2021-08-26 stsp
263 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
264 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
265 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
266 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
267 f8a36e22 2021-08-26 stsp return 1
268 f8a36e22 2021-08-26 stsp fi
269 f8a36e22 2021-08-26 stsp
270 f8a36e22 2021-08-26 stsp wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
271 f8a36e22 2021-08-26 stsp cut -d ':' -f 2 | tr -d ' ')`
272 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
273 f8a36e22 2021-08-26 stsp echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
274 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
275 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
276 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
277 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
278 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id" \
279 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
280 f8a36e22 2021-08-26 stsp
281 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
282 f8a36e22 2021-08-26 stsp ret="$?"
283 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
284 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
285 f8a36e22 2021-08-26 stsp fi
286 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
287 f8a36e22 2021-08-26 stsp }
288 f8a36e22 2021-08-26 stsp
289 f8a36e22 2021-08-26 stsp test_send_delete() {
290 f8a36e22 2021-08-26 stsp local testroot=`test_init send_delete`
291 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
292 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
293 f8a36e22 2021-08-26 stsp
294 f8a36e22 2021-08-26 stsp # branch1 exists in both repositories
295 f8a36e22 2021-08-26 stsp got branch -r $testroot/repo branch1
296 f8a36e22 2021-08-26 stsp
297 f8a36e22 2021-08-26 stsp got clone -a -q $testurl/repo $testroot/repo-clone
298 f8a36e22 2021-08-26 stsp ret="$?"
299 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
300 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
301 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
302 f8a36e22 2021-08-26 stsp return 1
303 f8a36e22 2021-08-26 stsp fi
304 f8a36e22 2021-08-26 stsp cat > $testroot/repo/.git/got.conf <<EOF
305 f8a36e22 2021-08-26 stsp remote "origin" {
306 f8a36e22 2021-08-26 stsp protocol ssh
307 f8a36e22 2021-08-26 stsp server 127.0.0.1
308 f8a36e22 2021-08-26 stsp repository "$testroot/repo-clone"
309 f8a36e22 2021-08-26 stsp }
310 f8a36e22 2021-08-26 stsp EOF
311 f8a36e22 2021-08-26 stsp # branch2 exists only in the remote repository
312 f8a36e22 2021-08-26 stsp got branch -r $testroot/repo-clone branch2
313 f8a36e22 2021-08-26 stsp
314 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
315 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
316 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
317 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
318 f8a36e22 2021-08-26 stsp return 1
319 f8a36e22 2021-08-26 stsp fi
320 f8a36e22 2021-08-26 stsp
321 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
322 f8a36e22 2021-08-26 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
323 f8a36e22 2021-08-26 stsp echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
324 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
325 f8a36e22 2021-08-26 stsp
326 f8a36e22 2021-08-26 stsp # Sending changes for a branch and deleting it at the same
327 f8a36e22 2021-08-26 stsp # time is not allowed.
328 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -d branch1 -b branch1 \
329 f8a36e22 2021-08-26 stsp > $testroot/stdout 2> $testroot/stderr
330 f8a36e22 2021-08-26 stsp ret="$?"
331 f9756a57 2021-08-26 stsp if [ "$ret" = "0" ]; then
332 f8a36e22 2021-08-26 stsp echo "got send command succeeded unexpectedly" >&2
333 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
334 f8a36e22 2021-08-26 stsp return 1
335 f8a36e22 2021-08-26 stsp fi
336 f8a36e22 2021-08-26 stsp echo -n "got: changes on refs/heads/branch1 will be sent to server" \
337 f8a36e22 2021-08-26 stsp > $testroot/stderr.expected
338 f8a36e22 2021-08-26 stsp echo ": reference cannot be deleted" >> $testroot/stderr.expected
339 f8a36e22 2021-08-26 stsp cmp -s $testroot/stderr $testroot/stderr.expected
340 f8a36e22 2021-08-26 stsp ret="$?"
341 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
342 f8a36e22 2021-08-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
343 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
344 f8a36e22 2021-08-26 stsp return 1
345 f8a36e22 2021-08-26 stsp fi
346 f8a36e22 2021-08-26 stsp
347 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -d refs/heads/branch1 origin \
348 f8a36e22 2021-08-26 stsp > $testroot/stdout 2> $testroot/stderr
349 f8a36e22 2021-08-26 stsp ret="$?"
350 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
351 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
352 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
353 f8a36e22 2021-08-26 stsp return 1
354 f8a36e22 2021-08-26 stsp fi
355 f8a36e22 2021-08-26 stsp
356 1bd76734 2021-08-26 stsp got send -r $testroot/repo -d refs/heads/branch2 origin \
357 27b75514 2021-08-28 stsp > $testroot/stdout 2>$testroot/stderr
358 f8a36e22 2021-08-26 stsp ret="$?"
359 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
360 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
361 1bd76734 2021-08-26 stsp test_done "$testroot" "$ret"
362 1bd76734 2021-08-26 stsp return 1
363 1bd76734 2021-08-26 stsp fi
364 1bd76734 2021-08-26 stsp
365 1bd76734 2021-08-26 stsp echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
366 1bd76734 2021-08-26 stsp echo "Server has deleted refs/heads/branch2" \
367 1bd76734 2021-08-26 stsp >> $testroot/stdout.expected
368 1bd76734 2021-08-26 stsp
369 1bd76734 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
370 1bd76734 2021-08-26 stsp ret="$?"
371 1bd76734 2021-08-26 stsp if [ "$ret" != "0" ]; then
372 1bd76734 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
373 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
374 f8a36e22 2021-08-26 stsp return 1
375 f8a36e22 2021-08-26 stsp fi
376 f8a36e22 2021-08-26 stsp
377 f8a36e22 2021-08-26 stsp # branchX exists in neither repository
378 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -d refs/heads/branchX origin \
379 f8a36e22 2021-08-26 stsp > $testroot/stdout 2> $testroot/stderr
380 f8a36e22 2021-08-26 stsp ret="$?"
381 f9756a57 2021-08-26 stsp if [ "$ret" = "0" ]; then
382 f8a36e22 2021-08-26 stsp echo "got send command succeeded unexpectedly" >&2
383 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
384 f8a36e22 2021-08-26 stsp return 1
385 f8a36e22 2021-08-26 stsp fi
386 f8a36e22 2021-08-26 stsp echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
387 f8a36e22 2021-08-26 stsp > $testroot/stderr.expected
388 f8a36e22 2021-08-26 stsp echo "repository: no such reference found" >> $testroot/stderr.expected
389 f8a36e22 2021-08-26 stsp echo "got: no such reference found" >> $testroot/stderr.expected
390 f8a36e22 2021-08-26 stsp cmp -s $testroot/stderr $testroot/stderr.expected
391 f8a36e22 2021-08-26 stsp ret="$?"
392 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
393 f8a36e22 2021-08-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
394 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
395 f8a36e22 2021-08-26 stsp return 1
396 f8a36e22 2021-08-26 stsp fi
397 f8a36e22 2021-08-26 stsp
398 f8a36e22 2021-08-26 stsp # References outside of refs/heads/ cannot be deleted with 'got send'.
399 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -d refs/tags/1.0 origin \
400 f8a36e22 2021-08-26 stsp > $testroot/stdout 2> $testroot/stderr
401 f8a36e22 2021-08-26 stsp ret="$?"
402 f9756a57 2021-08-26 stsp if [ "$ret" = "0" ]; then
403 f8a36e22 2021-08-26 stsp echo "got send command succeeded unexpectedly" >&2
404 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
405 f8a36e22 2021-08-26 stsp return 1
406 f8a36e22 2021-08-26 stsp fi
407 f8a36e22 2021-08-26 stsp echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
408 f8a36e22 2021-08-26 stsp > $testroot/stderr.expected
409 f8a36e22 2021-08-26 stsp echo "in remote repository: no such reference found" \
410 f8a36e22 2021-08-26 stsp >> $testroot/stderr.expected
411 f8a36e22 2021-08-26 stsp echo "got: no such reference found" >> $testroot/stderr.expected
412 f8a36e22 2021-08-26 stsp cmp -s $testroot/stderr $testroot/stderr.expected
413 f8a36e22 2021-08-26 stsp ret="$?"
414 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
415 f8a36e22 2021-08-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
416 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
417 f8a36e22 2021-08-26 stsp return 1
418 f8a36e22 2021-08-26 stsp fi
419 f8a36e22 2021-08-26 stsp
420 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo > $testroot/stdout
421 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
422 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
423 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
424 f8a36e22 2021-08-26 stsp return 1
425 f8a36e22 2021-08-26 stsp fi
426 f8a36e22 2021-08-26 stsp
427 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
428 f8a36e22 2021-08-26 stsp echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
429 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
430 f8a36e22 2021-08-26 stsp
431 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
432 f8a36e22 2021-08-26 stsp ret="$?"
433 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
434 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
435 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
436 f8a36e22 2021-08-26 stsp return 1
437 f8a36e22 2021-08-26 stsp fi
438 f8a36e22 2021-08-26 stsp
439 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
440 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
441 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
442 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
443 f8a36e22 2021-08-26 stsp return 1
444 f8a36e22 2021-08-26 stsp fi
445 f8a36e22 2021-08-26 stsp
446 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
447 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
448 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
449 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
450 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/branch1: $commit_id" \
451 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
452 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id" \
453 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
454 f8a36e22 2021-08-26 stsp
455 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
456 f8a36e22 2021-08-26 stsp ret="$?"
457 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
458 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
459 f8a36e22 2021-08-26 stsp fi
460 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
461 f8a36e22 2021-08-26 stsp }
462 f8a36e22 2021-08-26 stsp
463 f8a36e22 2021-08-26 stsp test_send_clone_and_send() {
464 f8a36e22 2021-08-26 stsp local testroot=`test_init send_clone_and_send`
465 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
466 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
467 f8a36e22 2021-08-26 stsp
468 f8a36e22 2021-08-26 stsp (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
469 f8a36e22 2021-08-26 stsp
470 f8a36e22 2021-08-26 stsp got clone -q $testurl/repo $testroot/repo-clone
471 f8a36e22 2021-08-26 stsp ret="$?"
472 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
473 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
474 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
475 f8a36e22 2021-08-26 stsp return 1
476 f8a36e22 2021-08-26 stsp fi
477 f8a36e22 2021-08-26 stsp
478 f8a36e22 2021-08-26 stsp got checkout $testroot/repo-clone $testroot/wt >/dev/null
479 f8a36e22 2021-08-26 stsp echo "modified alpha" > $testroot/wt/alpha
480 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
481 f8a36e22 2021-08-26 stsp local commit_id2=`git_show_head $testroot/repo-clone`
482 f8a36e22 2021-08-26 stsp
483 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
484 f8a36e22 2021-08-26 stsp ret="$?"
485 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
486 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
487 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
488 f8a36e22 2021-08-26 stsp return 1
489 f8a36e22 2021-08-26 stsp fi
490 f8a36e22 2021-08-26 stsp
491 f8a36e22 2021-08-26 stsp echo -n > $testroot/stdout.expected
492 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
493 f8a36e22 2021-08-26 stsp ret="$?"
494 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
495 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
496 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
497 f8a36e22 2021-08-26 stsp return 1
498 f8a36e22 2021-08-26 stsp fi
499 f8a36e22 2021-08-26 stsp
500 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo > $testroot/stdout
501 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
502 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
503 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
504 f8a36e22 2021-08-26 stsp return 1
505 f8a36e22 2021-08-26 stsp fi
506 f8a36e22 2021-08-26 stsp
507 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
508 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
509 f8a36e22 2021-08-26 stsp
510 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
511 f8a36e22 2021-08-26 stsp ret="$?"
512 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
513 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
514 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
515 f8a36e22 2021-08-26 stsp return 1
516 f8a36e22 2021-08-26 stsp fi
517 f8a36e22 2021-08-26 stsp
518 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
519 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
520 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
521 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
522 f8a36e22 2021-08-26 stsp return 1
523 f8a36e22 2021-08-26 stsp fi
524 f8a36e22 2021-08-26 stsp
525 f8a36e22 2021-08-26 stsp wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
526 f8a36e22 2021-08-26 stsp cut -d ':' -f 2 | tr -d ' ')`
527 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
528 f8a36e22 2021-08-26 stsp echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
529 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
530 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
531 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
532 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
533 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id2" \
534 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
535 f8a36e22 2021-08-26 stsp
536 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
537 f8a36e22 2021-08-26 stsp ret="$?"
538 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
539 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
540 f8a36e22 2021-08-26 stsp fi
541 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
542 f8a36e22 2021-08-26 stsp }
543 f8a36e22 2021-08-26 stsp
544 f8a36e22 2021-08-26 stsp test_send_tags() {
545 f8a36e22 2021-08-26 stsp local testroot=`test_init send_tags`
546 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
547 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
548 f8a36e22 2021-08-26 stsp
549 f8a36e22 2021-08-26 stsp got clone -q $testurl/repo $testroot/repo-clone
550 f8a36e22 2021-08-26 stsp ret="$?"
551 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
552 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
553 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
554 f8a36e22 2021-08-26 stsp return 1
555 f8a36e22 2021-08-26 stsp fi
556 f8a36e22 2021-08-26 stsp cat > $testroot/repo/.git/got.conf <<EOF
557 f8a36e22 2021-08-26 stsp remote "origin" {
558 f8a36e22 2021-08-26 stsp protocol ssh
559 f8a36e22 2021-08-26 stsp server 127.0.0.1
560 f8a36e22 2021-08-26 stsp repository "$testroot/repo-clone"
561 f8a36e22 2021-08-26 stsp }
562 f8a36e22 2021-08-26 stsp EOF
563 f8a36e22 2021-08-26 stsp got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
564 f8a36e22 2021-08-26 stsp tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
565 f8a36e22 2021-08-26 stsp | tr -d ' ' | cut -d: -f2`
566 f8a36e22 2021-08-26 stsp
567 f8a36e22 2021-08-26 stsp echo "modified alpha" > $testroot/repo/alpha
568 f8a36e22 2021-08-26 stsp git_commit $testroot/repo -m "modified alpha"
569 f8a36e22 2021-08-26 stsp local commit_id2=`git_show_head $testroot/repo`
570 f8a36e22 2021-08-26 stsp
571 f8a36e22 2021-08-26 stsp got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
572 f8a36e22 2021-08-26 stsp tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
573 f8a36e22 2021-08-26 stsp | tr -d ' ' | cut -d: -f2`
574 f8a36e22 2021-08-26 stsp
575 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
576 f8a36e22 2021-08-26 stsp ret="$?"
577 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
578 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
579 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
580 f8a36e22 2021-08-26 stsp return 1
581 f8a36e22 2021-08-26 stsp fi
582 f8a36e22 2021-08-26 stsp
583 f8a36e22 2021-08-26 stsp echo -n > $testroot/stdout.expected
584 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
585 f8a36e22 2021-08-26 stsp ret="$?"
586 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
587 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
588 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
589 f8a36e22 2021-08-26 stsp return 1
590 f8a36e22 2021-08-26 stsp fi
591 f8a36e22 2021-08-26 stsp
592 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo > $testroot/stdout
593 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
594 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
595 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
596 f8a36e22 2021-08-26 stsp return 1
597 f8a36e22 2021-08-26 stsp fi
598 f8a36e22 2021-08-26 stsp
599 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
600 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
601 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id2" \
602 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
603 f8a36e22 2021-08-26 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
604 f8a36e22 2021-08-26 stsp echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
605 f8a36e22 2021-08-26 stsp
606 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
607 f8a36e22 2021-08-26 stsp ret="$?"
608 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
609 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
610 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
611 f8a36e22 2021-08-26 stsp return 1
612 f8a36e22 2021-08-26 stsp fi
613 f8a36e22 2021-08-26 stsp
614 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
615 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
616 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
617 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
618 f8a36e22 2021-08-26 stsp return 1
619 f8a36e22 2021-08-26 stsp fi
620 f8a36e22 2021-08-26 stsp
621 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
622 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
623 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
624 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
625 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id" \
626 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
627 f8a36e22 2021-08-26 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
628 f8a36e22 2021-08-26 stsp echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
629 f8a36e22 2021-08-26 stsp
630 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
631 f8a36e22 2021-08-26 stsp ret="$?"
632 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
633 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
634 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
635 f8a36e22 2021-08-26 stsp return 1
636 f8a36e22 2021-08-26 stsp fi
637 f8a36e22 2021-08-26 stsp
638 f8a36e22 2021-08-26 stsp got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
639 f8a36e22 2021-08-26 stsp echo "tag 1.0 $tag_id" > $testroot/stdout.expected
640 f8a36e22 2021-08-26 stsp echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
641 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
642 f8a36e22 2021-08-26 stsp ret="$?"
643 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
644 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
645 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
646 f8a36e22 2021-08-26 stsp return 1
647 f8a36e22 2021-08-26 stsp fi
648 f8a36e22 2021-08-26 stsp
649 f8a36e22 2021-08-26 stsp # Overwriting an existing tag 'got send -f'.
650 f8a36e22 2021-08-26 stsp got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
651 f8a36e22 2021-08-26 stsp got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
652 f8a36e22 2021-08-26 stsp tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
653 f8a36e22 2021-08-26 stsp | tr -d ' ' | cut -d: -f2`
654 f8a36e22 2021-08-26 stsp
655 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
656 f8a36e22 2021-08-26 stsp 2> $testroot/stderr
657 f8a36e22 2021-08-26 stsp ret="$?"
658 f9756a57 2021-08-26 stsp if [ "$ret" = "0" ]; then
659 f8a36e22 2021-08-26 stsp echo "got send command succeeded unexpectedly" >&2
660 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
661 f8a36e22 2021-08-26 stsp return 1
662 f8a36e22 2021-08-26 stsp fi
663 f8a36e22 2021-08-26 stsp
664 f8a36e22 2021-08-26 stsp echo "got: refs/tags/1.0: tag already exists on server" \
665 f8a36e22 2021-08-26 stsp > $testroot/stderr.expected
666 f8a36e22 2021-08-26 stsp cmp -s $testroot/stderr $testroot/stderr.expected
667 f8a36e22 2021-08-26 stsp ret="$?"
668 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
669 f8a36e22 2021-08-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
670 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
671 f8a36e22 2021-08-26 stsp return 1
672 f8a36e22 2021-08-26 stsp fi
673 f8a36e22 2021-08-26 stsp
674 f8a36e22 2021-08-26 stsp # attempting the same with -T should fail, too
675 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -T > $testroot/stdout \
676 f8a36e22 2021-08-26 stsp 2> $testroot/stderr
677 f8a36e22 2021-08-26 stsp ret="$?"
678 f9756a57 2021-08-26 stsp if [ "$ret" = "0" ]; then
679 f8a36e22 2021-08-26 stsp echo "got send command succeeded unexpectedly" >&2
680 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
681 f8a36e22 2021-08-26 stsp return 1
682 f8a36e22 2021-08-26 stsp fi
683 f8a36e22 2021-08-26 stsp
684 f8a36e22 2021-08-26 stsp echo "got: refs/tags/1.0: tag already exists on server" \
685 f8a36e22 2021-08-26 stsp > $testroot/stderr.expected
686 f8a36e22 2021-08-26 stsp cmp -s $testroot/stderr $testroot/stderr.expected
687 f8a36e22 2021-08-26 stsp ret="$?"
688 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
689 f8a36e22 2021-08-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
690 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
691 f8a36e22 2021-08-26 stsp return 1
692 f8a36e22 2021-08-26 stsp fi
693 f8a36e22 2021-08-26 stsp
694 f8a36e22 2021-08-26 stsp got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
695 f8a36e22 2021-08-26 stsp echo "tag 1.0 $tag_id" > $testroot/stdout.expected
696 f8a36e22 2021-08-26 stsp echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
697 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
698 f8a36e22 2021-08-26 stsp ret="$?"
699 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
700 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
701 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
702 f8a36e22 2021-08-26 stsp return 1
703 f8a36e22 2021-08-26 stsp fi
704 f8a36e22 2021-08-26 stsp
705 f8a36e22 2021-08-26 stsp # overwrite the 1.0 tag only
706 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
707 f8a36e22 2021-08-26 stsp 2> $testroot/stderr
708 f8a36e22 2021-08-26 stsp ret="$?"
709 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
710 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
711 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
712 f8a36e22 2021-08-26 stsp return 1
713 f8a36e22 2021-08-26 stsp fi
714 f8a36e22 2021-08-26 stsp
715 f8a36e22 2021-08-26 stsp got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
716 f8a36e22 2021-08-26 stsp echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
717 f8a36e22 2021-08-26 stsp echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
718 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
719 f8a36e22 2021-08-26 stsp ret="$?"
720 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
721 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
722 f8a36e22 2021-08-26 stsp fi
723 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
724 f8a36e22 2021-08-26 stsp }
725 f8a36e22 2021-08-26 stsp
726 f8a36e22 2021-08-26 stsp test_send_new_branch() {
727 f8a36e22 2021-08-26 stsp local testroot=`test_init send_new_branch`
728 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
729 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
730 f8a36e22 2021-08-26 stsp
731 f8a36e22 2021-08-26 stsp (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
732 f8a36e22 2021-08-26 stsp
733 f8a36e22 2021-08-26 stsp got clone -q $testurl/repo $testroot/repo-clone
734 f8a36e22 2021-08-26 stsp ret="$?"
735 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
736 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
737 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
738 f8a36e22 2021-08-26 stsp return 1
739 f8a36e22 2021-08-26 stsp fi
740 f8a36e22 2021-08-26 stsp
741 f8a36e22 2021-08-26 stsp got branch -r $testroot/repo-clone foo >/dev/null
742 f8a36e22 2021-08-26 stsp got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
743 f8a36e22 2021-08-26 stsp echo "modified alpha" > $testroot/wt/alpha
744 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
745 f8a36e22 2021-08-26 stsp local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
746 f8a36e22 2021-08-26 stsp
747 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
748 f8a36e22 2021-08-26 stsp ret="$?"
749 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
750 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
751 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
752 f8a36e22 2021-08-26 stsp return 1
753 f8a36e22 2021-08-26 stsp fi
754 f8a36e22 2021-08-26 stsp
755 f8a36e22 2021-08-26 stsp echo -n > $testroot/stdout.expected
756 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
757 f8a36e22 2021-08-26 stsp ret="$?"
758 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
759 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
760 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
761 f8a36e22 2021-08-26 stsp return 1
762 f8a36e22 2021-08-26 stsp fi
763 f8a36e22 2021-08-26 stsp
764 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo > $testroot/stdout
765 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
766 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
767 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
768 f8a36e22 2021-08-26 stsp return 1
769 f8a36e22 2021-08-26 stsp fi
770 f8a36e22 2021-08-26 stsp
771 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
772 f8a36e22 2021-08-26 stsp echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
773 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
774 f8a36e22 2021-08-26 stsp
775 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
776 f8a36e22 2021-08-26 stsp ret="$?"
777 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
778 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
779 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
780 f8a36e22 2021-08-26 stsp return 1
781 f8a36e22 2021-08-26 stsp fi
782 f8a36e22 2021-08-26 stsp
783 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
784 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
785 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
786 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
787 f8a36e22 2021-08-26 stsp return 1
788 f8a36e22 2021-08-26 stsp fi
789 f8a36e22 2021-08-26 stsp
790 f8a36e22 2021-08-26 stsp wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
791 f8a36e22 2021-08-26 stsp cut -d ':' -f 2 | tr -d ' ')`
792 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
793 f8a36e22 2021-08-26 stsp echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
794 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
795 f8a36e22 2021-08-26 stsp echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
796 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
797 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
798 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
799 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/foo: $commit_id2" \
800 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
801 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id" \
802 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
803 f8a36e22 2021-08-26 stsp
804 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
805 f8a36e22 2021-08-26 stsp ret="$?"
806 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
807 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
808 f8a36e22 2021-08-26 stsp fi
809 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
810 f8a36e22 2021-08-26 stsp }
811 f8a36e22 2021-08-26 stsp
812 f8a36e22 2021-08-26 stsp test_send_all_branches() {
813 f8a36e22 2021-08-26 stsp local testroot=`test_init send_all_branches`
814 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
815 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
816 f8a36e22 2021-08-26 stsp
817 f8a36e22 2021-08-26 stsp (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
818 f8a36e22 2021-08-26 stsp
819 f8a36e22 2021-08-26 stsp got clone -q $testurl/repo $testroot/repo-clone
820 f8a36e22 2021-08-26 stsp ret="$?"
821 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
822 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
823 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
824 f8a36e22 2021-08-26 stsp return 1
825 f8a36e22 2021-08-26 stsp fi
826 f8a36e22 2021-08-26 stsp
827 f8a36e22 2021-08-26 stsp got checkout $testroot/repo-clone $testroot/wt >/dev/null
828 f8a36e22 2021-08-26 stsp echo "modified alpha" > $testroot/wt/alpha
829 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
830 f8a36e22 2021-08-26 stsp local commit_id2=`git_show_head $testroot/repo-clone`
831 f8a36e22 2021-08-26 stsp
832 f8a36e22 2021-08-26 stsp got branch -r $testroot/repo-clone foo >/dev/null
833 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got update -b foo >/dev/null)
834 f8a36e22 2021-08-26 stsp echo "modified beta on new branch foo" > $testroot/wt/beta
835 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
836 f8a36e22 2021-08-26 stsp local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
837 f8a36e22 2021-08-26 stsp
838 f8a36e22 2021-08-26 stsp got branch -r $testroot/repo-clone bar >/dev/null
839 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got update -b bar >/dev/null)
840 f8a36e22 2021-08-26 stsp echo "modified beta again on new branch bar" > $testroot/wt/beta
841 f8a36e22 2021-08-26 stsp (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
842 f8a36e22 2021-08-26 stsp local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
843 f8a36e22 2021-08-26 stsp
844 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
845 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
846 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
847 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
848 f8a36e22 2021-08-26 stsp return 1
849 f8a36e22 2021-08-26 stsp fi
850 f8a36e22 2021-08-26 stsp
851 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
852 f8a36e22 2021-08-26 stsp echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
853 f8a36e22 2021-08-26 stsp echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
854 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
855 f8a36e22 2021-08-26 stsp
856 f8a36e22 2021-08-26 stsp got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
857 f8a36e22 2021-08-26 stsp 2> $testroot/stderr
858 f8a36e22 2021-08-26 stsp ret="$?"
859 f9756a57 2021-08-26 stsp if [ "$ret" = "0" ]; then
860 f8a36e22 2021-08-26 stsp echo "got send command succeeded unexpectedly" >&2
861 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
862 f8a36e22 2021-08-26 stsp return 1
863 f8a36e22 2021-08-26 stsp fi
864 f8a36e22 2021-08-26 stsp echo "got: -a and -b options are mutually exclusive" \
865 f8a36e22 2021-08-26 stsp > $testroot/stderr.expected
866 f8a36e22 2021-08-26 stsp cmp -s $testroot/stderr $testroot/stderr.expected
867 f8a36e22 2021-08-26 stsp ret="$?"
868 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
869 f8a36e22 2021-08-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
870 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
871 f8a36e22 2021-08-26 stsp return 1
872 f8a36e22 2021-08-26 stsp fi
873 f8a36e22 2021-08-26 stsp
874 f8a36e22 2021-08-26 stsp got send -a -q -r $testroot/repo-clone > $testroot/stdout \
875 f8a36e22 2021-08-26 stsp 2> $testroot/stderr
876 f8a36e22 2021-08-26 stsp ret="$?"
877 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
878 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
879 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
880 f8a36e22 2021-08-26 stsp return 1
881 f8a36e22 2021-08-26 stsp fi
882 f8a36e22 2021-08-26 stsp
883 f8a36e22 2021-08-26 stsp echo -n > $testroot/stdout.expected
884 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
885 f8a36e22 2021-08-26 stsp ret="$?"
886 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
887 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
888 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
889 f8a36e22 2021-08-26 stsp return 1
890 f8a36e22 2021-08-26 stsp fi
891 f8a36e22 2021-08-26 stsp
892 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo > $testroot/stdout
893 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
894 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
895 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
896 f8a36e22 2021-08-26 stsp return 1
897 f8a36e22 2021-08-26 stsp fi
898 f8a36e22 2021-08-26 stsp
899 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
900 f8a36e22 2021-08-26 stsp echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
901 f8a36e22 2021-08-26 stsp echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
902 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
903 f8a36e22 2021-08-26 stsp
904 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
905 f8a36e22 2021-08-26 stsp ret="$?"
906 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
907 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
908 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
909 f8a36e22 2021-08-26 stsp return 1
910 f8a36e22 2021-08-26 stsp fi
911 f8a36e22 2021-08-26 stsp
912 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
913 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
914 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
915 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
916 f8a36e22 2021-08-26 stsp return 1
917 f8a36e22 2021-08-26 stsp fi
918 f8a36e22 2021-08-26 stsp
919 f8a36e22 2021-08-26 stsp wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
920 f8a36e22 2021-08-26 stsp cut -d ':' -f 2 | tr -d ' ')`
921 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
922 f8a36e22 2021-08-26 stsp echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
923 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
924 f8a36e22 2021-08-26 stsp echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
925 f8a36e22 2021-08-26 stsp echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
926 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
927 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
928 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
929 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/bar: $commit_id4" \
930 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
931 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/foo: $commit_id3" \
932 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
933 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id2" \
934 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
935 f8a36e22 2021-08-26 stsp
936 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
937 f8a36e22 2021-08-26 stsp ret="$?"
938 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
939 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
940 f8a36e22 2021-08-26 stsp fi
941 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
942 f8a36e22 2021-08-26 stsp }
943 f8a36e22 2021-08-26 stsp
944 f8a36e22 2021-08-26 stsp test_send_to_empty_repo() {
945 f8a36e22 2021-08-26 stsp local testroot=`test_init send_to_empty_repo`
946 f8a36e22 2021-08-26 stsp local testurl=ssh://127.0.0.1/$testroot
947 f8a36e22 2021-08-26 stsp local commit_id=`git_show_head $testroot/repo`
948 f8a36e22 2021-08-26 stsp
949 f8a36e22 2021-08-26 stsp got init $testroot/repo2
950 f8a36e22 2021-08-26 stsp
951 f8a36e22 2021-08-26 stsp ret="$?"
952 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
953 f8a36e22 2021-08-26 stsp echo "got clone command failed unexpectedly" >&2
954 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
955 f8a36e22 2021-08-26 stsp return 1
956 f8a36e22 2021-08-26 stsp fi
957 f8a36e22 2021-08-26 stsp cat > $testroot/repo/.git/got.conf <<EOF
958 f8a36e22 2021-08-26 stsp remote "origin" {
959 f8a36e22 2021-08-26 stsp protocol ssh
960 f8a36e22 2021-08-26 stsp server 127.0.0.1
961 f8a36e22 2021-08-26 stsp repository "$testroot/repo2"
962 f8a36e22 2021-08-26 stsp }
963 f8a36e22 2021-08-26 stsp EOF
964 f8a36e22 2021-08-26 stsp echo "modified alpha" > $testroot/repo/alpha
965 f8a36e22 2021-08-26 stsp git_commit $testroot/repo -m "modified alpha"
966 f8a36e22 2021-08-26 stsp local commit_id2=`git_show_head $testroot/repo`
967 f8a36e22 2021-08-26 stsp
968 f8a36e22 2021-08-26 stsp got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
969 f8a36e22 2021-08-26 stsp ret="$?"
970 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
971 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
972 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
973 f8a36e22 2021-08-26 stsp return 1
974 f8a36e22 2021-08-26 stsp fi
975 f8a36e22 2021-08-26 stsp
976 f8a36e22 2021-08-26 stsp echo -n > $testroot/stdout.expected
977 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
978 f8a36e22 2021-08-26 stsp ret="$?"
979 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
980 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
981 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
982 f8a36e22 2021-08-26 stsp return 1
983 f8a36e22 2021-08-26 stsp fi
984 f8a36e22 2021-08-26 stsp
985 f8a36e22 2021-08-26 stsp # XXX Workaround: We cannot give the target for HEAD to 'got init'
986 f8a36e22 2021-08-26 stsp got ref -r $testroot/repo2 -s refs/heads/master HEAD
987 f8a36e22 2021-08-26 stsp
988 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo > $testroot/stdout
989 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
990 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
991 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
992 f8a36e22 2021-08-26 stsp return 1
993 f8a36e22 2021-08-26 stsp fi
994 f8a36e22 2021-08-26 stsp
995 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
996 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
997 f8a36e22 2021-08-26 stsp echo "refs/remotes/origin/master: $commit_id2" \
998 f8a36e22 2021-08-26 stsp >> $testroot/stdout.expected
999 f8a36e22 2021-08-26 stsp
1000 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
1001 f8a36e22 2021-08-26 stsp ret="$?"
1002 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
1003 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1004 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
1005 f8a36e22 2021-08-26 stsp return 1
1006 f8a36e22 2021-08-26 stsp fi
1007 f8a36e22 2021-08-26 stsp
1008 f8a36e22 2021-08-26 stsp got ref -l -r $testroot/repo2 > $testroot/stdout
1009 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
1010 f8a36e22 2021-08-26 stsp echo "got ref command failed unexpectedly" >&2
1011 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
1012 f8a36e22 2021-08-26 stsp return 1
1013 f8a36e22 2021-08-26 stsp fi
1014 f8a36e22 2021-08-26 stsp
1015 f8a36e22 2021-08-26 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1016 f8a36e22 2021-08-26 stsp echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1017 f8a36e22 2021-08-26 stsp
1018 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
1019 f8a36e22 2021-08-26 stsp ret="$?"
1020 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
1021 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1022 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
1023 f8a36e22 2021-08-26 stsp return 1
1024 f8a36e22 2021-08-26 stsp fi
1025 f8a36e22 2021-08-26 stsp
1026 f8a36e22 2021-08-26 stsp got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1027 f8a36e22 2021-08-26 stsp ret="$?"
1028 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
1029 f8a36e22 2021-08-26 stsp echo "got send command failed unexpectedly" >&2
1030 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
1031 f8a36e22 2021-08-26 stsp return 1
1032 f8a36e22 2021-08-26 stsp fi
1033 f8a36e22 2021-08-26 stsp
1034 f8a36e22 2021-08-26 stsp echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
1035 f8a36e22 2021-08-26 stsp echo "Already up-to-date" >> $testroot/stdout.expected
1036 f8a36e22 2021-08-26 stsp cmp -s $testroot/stdout $testroot/stdout.expected
1037 f8a36e22 2021-08-26 stsp ret="$?"
1038 f8a36e22 2021-08-26 stsp if [ "$ret" != "0" ]; then
1039 f8a36e22 2021-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1040 f8a36e22 2021-08-26 stsp fi
1041 f8a36e22 2021-08-26 stsp test_done "$testroot" "$ret"
1042 6480c871 2021-08-30 stsp }
1043 6480c871 2021-08-30 stsp
1044 6480c871 2021-08-30 stsp test_send_and_fetch_config() {
1045 6480c871 2021-08-30 stsp local testroot=`test_init send_fetch_conf`
1046 6480c871 2021-08-30 stsp local testurl=ssh://127.0.0.1/$testroot
1047 6480c871 2021-08-30 stsp local commit_id=`git_show_head $testroot/repo`
1048 6480c871 2021-08-30 stsp
1049 6480c871 2021-08-30 stsp got clone -q $testurl/repo $testroot/repo-clone
1050 6480c871 2021-08-30 stsp ret="$?"
1051 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1052 6480c871 2021-08-30 stsp echo "got clone command failed unexpectedly" >&2
1053 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1054 6480c871 2021-08-30 stsp return 1
1055 6480c871 2021-08-30 stsp fi
1056 6480c871 2021-08-30 stsp
1057 6480c871 2021-08-30 stsp got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1058 6480c871 2021-08-30 stsp tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1059 6480c871 2021-08-30 stsp | tr -d ' ' | cut -d: -f2`
1060 6480c871 2021-08-30 stsp
1061 6480c871 2021-08-30 stsp cp -R $testroot/repo-clone $testroot/repo-clone2
1062 6480c871 2021-08-30 stsp got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1063 6480c871 2021-08-30 stsp tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1064 6480c871 2021-08-30 stsp | tr -d ' ' | cut -d: -f2`
1065 6480c871 2021-08-30 stsp
1066 6480c871 2021-08-30 stsp cat > $testroot/repo/.git/got.conf <<EOF
1067 6480c871 2021-08-30 stsp remote "origin" {
1068 6480c871 2021-08-30 stsp protocol ssh
1069 6480c871 2021-08-30 stsp server 127.0.0.1
1070 6480c871 2021-08-30 stsp send {
1071 6480c871 2021-08-30 stsp repository "$testroot/repo-clone"
1072 6480c871 2021-08-30 stsp }
1073 6480c871 2021-08-30 stsp fetch {
1074 6480c871 2021-08-30 stsp repository "$testroot/repo-clone2"
1075 6480c871 2021-08-30 stsp }
1076 f8a36e22 2021-08-26 stsp }
1077 6480c871 2021-08-30 stsp EOF
1078 6480c871 2021-08-30 stsp got ref -l -r $testroot/repo > $testroot/stdout
1079 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1080 6480c871 2021-08-30 stsp echo "got ref command failed unexpectedly" >&2
1081 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1082 6480c871 2021-08-30 stsp return 1
1083 6480c871 2021-08-30 stsp fi
1084 f8a36e22 2021-08-26 stsp
1085 6480c871 2021-08-30 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1086 6480c871 2021-08-30 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1087 6480c871 2021-08-30 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1088 6480c871 2021-08-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
1089 6480c871 2021-08-30 stsp ret="$?"
1090 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1091 6480c871 2021-08-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
1092 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1093 6480c871 2021-08-30 stsp return 1
1094 6480c871 2021-08-30 stsp fi
1095 f8a36e22 2021-08-26 stsp
1096 6480c871 2021-08-30 stsp # fetch tag 2.0 from repo-clone2
1097 6480c871 2021-08-30 stsp got fetch -q -r $testroot/repo > $testroot/stdout
1098 6480c871 2021-08-30 stsp ret="$?"
1099 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1100 6480c871 2021-08-30 stsp echo "got fetch command failed unexpectedly" >&2
1101 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1102 6480c871 2021-08-30 stsp return 1
1103 6480c871 2021-08-30 stsp fi
1104 6480c871 2021-08-30 stsp
1105 6480c871 2021-08-30 stsp got ref -l -r $testroot/repo > $testroot/stdout
1106 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1107 6480c871 2021-08-30 stsp echo "got ref command failed unexpectedly" >&2
1108 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1109 6480c871 2021-08-30 stsp return 1
1110 6480c871 2021-08-30 stsp fi
1111 6480c871 2021-08-30 stsp
1112 6480c871 2021-08-30 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1113 6480c871 2021-08-30 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1114 6480c871 2021-08-30 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1115 6480c871 2021-08-30 stsp >> $testroot/stdout.expected
1116 6480c871 2021-08-30 stsp echo "refs/remotes/origin/master: $commit_id" \
1117 6480c871 2021-08-30 stsp >> $testroot/stdout.expected
1118 6480c871 2021-08-30 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1119 6480c871 2021-08-30 stsp echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1120 6480c871 2021-08-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
1121 6480c871 2021-08-30 stsp ret="$?"
1122 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1123 6480c871 2021-08-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
1124 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1125 6480c871 2021-08-30 stsp return 1
1126 6480c871 2021-08-30 stsp fi
1127 6480c871 2021-08-30 stsp
1128 6480c871 2021-08-30 stsp # send tag 1.0 to repo-clone
1129 6480c871 2021-08-30 stsp got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1130 6480c871 2021-08-30 stsp ret="$?"
1131 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1132 6480c871 2021-08-30 stsp echo "got send command failed unexpectedly" >&2
1133 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1134 6480c871 2021-08-30 stsp return 1
1135 6480c871 2021-08-30 stsp fi
1136 6480c871 2021-08-30 stsp
1137 6480c871 2021-08-30 stsp got ref -l -r $testroot/repo-clone > $testroot/stdout
1138 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1139 6480c871 2021-08-30 stsp echo "got ref command failed unexpectedly" >&2
1140 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1141 6480c871 2021-08-30 stsp return 1
1142 6480c871 2021-08-30 stsp fi
1143 6480c871 2021-08-30 stsp
1144 6480c871 2021-08-30 stsp echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1145 6480c871 2021-08-30 stsp echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1146 6480c871 2021-08-30 stsp echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1147 6480c871 2021-08-30 stsp >> $testroot/stdout.expected
1148 6480c871 2021-08-30 stsp echo "refs/remotes/origin/master: $commit_id" \
1149 6480c871 2021-08-30 stsp >> $testroot/stdout.expected
1150 6480c871 2021-08-30 stsp echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1151 6480c871 2021-08-30 stsp
1152 6480c871 2021-08-30 stsp cmp -s $testroot/stdout $testroot/stdout.expected
1153 6480c871 2021-08-30 stsp ret="$?"
1154 6480c871 2021-08-30 stsp if [ "$ret" != "0" ]; then
1155 6480c871 2021-08-30 stsp diff -u $testroot/stdout.expected $testroot/stdout
1156 6480c871 2021-08-30 stsp fi
1157 6480c871 2021-08-30 stsp
1158 6480c871 2021-08-30 stsp test_done "$testroot" "$ret"
1159 6480c871 2021-08-30 stsp }
1160 6480c871 2021-08-30 stsp
1161 f8a36e22 2021-08-26 stsp test_parseargs "$@"
1162 f8a36e22 2021-08-26 stsp run_test test_send_basic
1163 f8a36e22 2021-08-26 stsp run_test test_send_rebase_required
1164 f8a36e22 2021-08-26 stsp run_test test_send_rebase_required_overwrite
1165 f8a36e22 2021-08-26 stsp run_test test_send_delete
1166 f8a36e22 2021-08-26 stsp run_test test_send_clone_and_send
1167 f8a36e22 2021-08-26 stsp run_test test_send_tags
1168 f8a36e22 2021-08-26 stsp run_test test_send_new_branch
1169 f8a36e22 2021-08-26 stsp run_test test_send_all_branches
1170 f8a36e22 2021-08-26 stsp run_test test_send_to_empty_repo
1171 6480c871 2021-08-30 stsp run_test test_send_and_fetch_config