got: plug a couple leaks in `got import`
[got-portable.git] / regress / cmdline / tree.sh
blob6f82982ad2e1d53c37ba2de0a2ebfaca01a77193
1 #!/bin/sh
3 # Copyright (c) 2020 Tracey Emery <tracey@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 . ./common.sh
19 test_tree_basic() {
20 local testroot=`test_init tree_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 echo "new file" > $testroot/wt/foo
26 (cd $testroot/wt && got add foo > /dev/null)
27 (cd $testroot/wt && got commit -m "add foo" foo > /dev/null)
29 echo 'alpha' > $testroot/stdout.expected
30 echo 'beta' >> $testroot/stdout.expected
31 echo 'epsilon/' >> $testroot/stdout.expected
32 echo 'foo' >> $testroot/stdout.expected
33 echo 'gamma/' >> $testroot/stdout.expected
35 for p in "" "." "/"; do
36 (cd $testroot/wt && got tree $p > $testroot/stdout)
37 cmp -s $testroot/stdout.expected $testroot/stdout
38 ret=$?
39 if [ $ret -ne 0 ]; then
40 diff -u $testroot/stdout.expected $testroot/stdout
41 test_done "$testroot" "$ret"
42 return 1
44 done
46 test_done "$testroot" "0"
49 test_tree_branch() {
50 local testroot=`test_init tree_branch`
52 got checkout $testroot/repo $testroot/wt > /dev/null
53 ret=$?
54 if [ $ret -ne 0 ]; then
55 test_done "$testroot" "$ret"
56 return 1
59 (cd $testroot/wt && got br foo > $testroot/stdout)
61 echo "new file" > $testroot/wt/foo
63 (cd $testroot/wt && got add foo > /dev/null)
64 (cd $testroot/wt && got commit -m "add foo" foo > /dev/null)
66 echo 'alpha' > $testroot/stdout.expected
67 echo 'beta' >> $testroot/stdout.expected
68 echo 'epsilon/' >> $testroot/stdout.expected
69 echo 'foo' >> $testroot/stdout.expected
70 echo 'gamma/' >> $testroot/stdout.expected
72 (cd $testroot/wt && got tree > $testroot/stdout)
74 cmp -s $testroot/stdout.expected $testroot/stdout
75 ret=$?
76 if [ $ret -ne 0 ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
83 test_tree_submodule() {
84 local testroot=`test_init tree_submodule`
86 make_single_file_repo $testroot/repo2 foo
87 git -C $testroot/repo -c protocol.file.allow=always \
88 submodule -q add ../repo2
89 git -C $testroot/repo commit -q -m 'adding submodule'
91 local submodule_id=$(got tree -r $testroot/repo -i | \
92 grep 'repo2\$$' | cut -d ' ' -f1)
94 got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
95 ret=$?
96 if [ $ret -eq 0 ]; then
97 echo "tree command succeeded unexpectedly" >&2
98 test_done "$testroot" "1"
99 return 1
101 echo "got: object $submodule_id not found" > $testroot/stderr.expected
103 cmp -s $testroot/stderr.expected $testroot/stderr
104 ret=$?
105 if [ $ret -ne 0 ]; then
106 diff -u $testroot/stderr.expected $testroot/stderr
107 return 1
109 test_done "$testroot" "$ret"
112 test_tree_submodule_of_same_repo() {
113 local testroot=`test_init tree_submodule_of_same_repo`
115 git -C $testroot clone -q repo repo2 >/dev/null
116 git -C $testroot/repo -c protocol.file.allow=always \
117 submodule -q add ../repo2
118 git -C $testroot/repo commit -q -m 'adding submodule'
120 # Currently fails with "bad object data"
121 got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
122 ret=$?
123 if [ $ret -eq 0 ]; then
124 echo "tree command succeeded unexpectedly" >&2
125 test_done "$testroot" "1"
126 return 1
128 if [ -n "$GOT_TEST_PACK" ]; then
129 echo "got-read-pack: bad object data" \
130 > $testroot/stderr.expected
131 else
132 echo "got-read-tree: bad object data" \
133 > $testroot/stderr.expected
135 echo "got: bad object data" >> $testroot/stderr.expected
137 cmp -s $testroot/stderr.expected $testroot/stderr
138 ret=$?
139 if [ $ret -ne 0 ]; then
140 diff -u $testroot/stderr.expected $testroot/stderr
141 return 1
143 test_done "$testroot" "$ret"
146 test_tree_commit_keywords() {
147 local testroot=$(test_init tree_commit_keywords)
148 local wt="$testroot/wt"
150 # :base requires work tree
151 echo "got: '-c :base' requires work tree" > "$testroot/stderr.expected"
152 got tree -r "$testroot/repo" -c:base 2> "$testroot/stderr"
153 ret=$?
154 if [ $ret -eq 0 ]; then
155 echo "tree command succeeded unexpectedly" >&2
156 test_done "$testroot" "1"
157 return 1
160 cmp -s "$testroot/stderr.expected" "$testroot/stderr"
161 ret=$?
162 if [ $ret -ne 0 ]; then
163 diff -u "$testroot/stderr.expected" "$testroot/stderr"
164 test_done "$testroot" "$ret"
165 return 1
168 echo 'alpha' > $testroot/stdout.expected
169 echo 'beta' >> $testroot/stdout.expected
170 echo 'epsilon/' >> $testroot/stdout.expected
171 echo 'gamma/' >> $testroot/stdout.expected
173 got tree -r "$testroot/repo" -c:head > "$testroot/stdout"
174 cmp -s $testroot/stdout.expected $testroot/stdout
175 ret=$?
176 if [ $ret -ne 0 ]; then
177 diff -u $testroot/stdout.expected $testroot/stdout
178 test_done "$testroot" "$ret"
179 return 1
182 got checkout "$testroot/repo" "$wt" > /dev/null
185 cd "$wt"
186 mkdir bing
187 echo "foo" > foo
188 echo "bar" > bar
189 echo "baz" > baz
190 echo "bob" > bing/bob
191 got add foo bar baz bing/bob > /dev/null
192 got commit -m "add foo" foo > /dev/null
193 got commit -m "add bar" bar > /dev/null
194 got commit -m "add baz" baz > /dev/null
195 got commit -m "add bing/bob" > /dev/null
198 echo 'alpha' > $testroot/stdout.expected
199 echo 'beta' >> $testroot/stdout.expected
200 echo 'epsilon/' >> $testroot/stdout.expected
201 echo 'foo' >> $testroot/stdout.expected
202 echo 'gamma/' >> $testroot/stdout.expected
204 (cd "$wt" && got tree -c:base:-3 > $testroot/stdout)
205 cmp -s $testroot/stdout.expected $testroot/stdout
206 ret=$?
207 if [ $ret -ne 0 ]; then
208 diff -u $testroot/stdout.expected $testroot/stdout
209 test_done "$testroot" "$ret"
210 return 1
213 echo 'alpha' > $testroot/stdout.expected
214 echo 'bar' >> $testroot/stdout.expected
215 echo 'beta' >> $testroot/stdout.expected
216 echo 'epsilon/' >> $testroot/stdout.expected
217 echo 'foo' >> $testroot/stdout.expected
218 echo 'gamma/' >> $testroot/stdout.expected
220 (cd "$wt" && got tree -cmaster:-2 > $testroot/stdout)
221 cmp -s $testroot/stdout.expected $testroot/stdout
222 ret=$?
223 if [ $ret -ne 0 ]; then
224 diff -u $testroot/stdout.expected $testroot/stdout
225 test_done "$testroot" "$ret"
226 return 1
229 echo 'alpha' > $testroot/stdout.expected
230 echo 'bar' >> $testroot/stdout.expected
231 echo 'baz' >> $testroot/stdout.expected
232 echo 'beta' >> $testroot/stdout.expected
233 echo 'epsilon/' >> $testroot/stdout.expected
234 echo 'foo' >> $testroot/stdout.expected
235 echo 'gamma/' >> $testroot/stdout.expected
237 (cd "$wt" && got tree -c:head:- > $testroot/stdout)
238 cmp -s $testroot/stdout.expected $testroot/stdout
239 ret=$?
240 if [ $ret -ne 0 ]; then
241 diff -u $testroot/stdout.expected $testroot/stdout
242 test_done "$testroot" "$ret"
243 return 1
246 echo 'alpha' > $testroot/stdout.expected
247 echo 'bar' >> $testroot/stdout.expected
248 echo 'baz' >> $testroot/stdout.expected
249 echo 'beta' >> $testroot/stdout.expected
250 echo 'bing/' >> $testroot/stdout.expected
251 echo 'epsilon/' >> $testroot/stdout.expected
252 echo 'foo' >> $testroot/stdout.expected
253 echo 'gamma/' >> $testroot/stdout.expected
255 (cd "$wt" && got up -c:base:-4 > $testroot/stdout)
256 (cd "$wt" && got tree -c:base:+4 > $testroot/stdout)
257 cmp -s $testroot/stdout.expected $testroot/stdout
258 ret=$?
259 if [ $ret -ne 0 ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 test_done "$testroot" "$ret"
262 return 1
265 test_done "$testroot" "0"
268 test_parseargs "$@"
269 run_test test_tree_basic
270 run_test test_tree_branch
271 run_test test_tree_submodule
272 run_test test_tree_submodule_of_same_repo
273 run_test test_tree_commit_keywords