portable: release 0.93
[got-portable.git] / regress / cmdline / tree.sh
blob62eb987ba62876f4026cd0d830472dd2a3060c20
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 (cd $testroot/repo && git -c protocol.file.allow=always \
88 submodule -q add ../repo2)
89 (cd $testroot/repo && git commit -q -m 'adding submodule')
91 local submodule_id=$(got tree -r $testroot/repo -i | \
92 grep 'repo2\$$' | cut -d ' ' -f1)
93 local objpath=`get_loose_object_path $testroot/repo $submodule_id`
95 # Currently fails in open(2)
96 got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
97 ret=$?
98 if [ $ret -eq 0 ]; then
99 echo "tree command succeeded unexpectedly" >&2
100 test_done "$testroot" "1"
101 return 1
103 echo "got: open: $objpath: No such file or directory" \
104 > $testroot/stderr.expected
106 cmp -s $testroot/stderr.expected $testroot/stderr
107 ret=$?
108 if [ $ret -ne 0 ]; then
109 diff -u $testroot/stderr.expected $testroot/stderr
110 return 1
112 test_done "$testroot" "$ret"
115 test_tree_submodule_of_same_repo() {
116 local testroot=`test_init tree_submodule_of_same_repo`
118 (cd $testroot && git clone -q repo repo2 >/dev/null)
119 (cd $testroot/repo && git -c protocol.file.allow=always \
120 submodule -q add ../repo2)
121 (cd $testroot/repo && git commit -q -m 'adding submodule')
123 # Currently fails with "bad object data"
124 got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
125 ret=$?
126 if [ $ret -eq 0 ]; then
127 echo "tree command succeeded unexpectedly" >&2
128 test_done "$testroot" "1"
129 return 1
131 if [ -n "$GOT_TEST_PACK" ]; then
132 echo "got-read-pack: bad object data" \
133 > $testroot/stderr.expected
134 else
135 echo "got-read-tree: bad object data" \
136 > $testroot/stderr.expected
138 echo "got: bad object data" >> $testroot/stderr.expected
140 cmp -s $testroot/stderr.expected $testroot/stderr
141 ret=$?
142 if [ $ret -ne 0 ]; then
143 diff -u $testroot/stderr.expected $testroot/stderr
144 return 1
146 test_done "$testroot" "$ret"
149 test_tree_commit_keywords() {
150 local testroot=$(test_init tree_commit_keywords)
151 local wt="$testroot/wt"
153 # :base requires work tree
154 echo "got: '-c :base' requires work tree" > "$testroot/stderr.expected"
155 got tree -r "$testroot/repo" -c:base 2> "$testroot/stderr"
156 ret=$?
157 if [ $ret -eq 0 ]; then
158 echo "tree command succeeded unexpectedly" >&2
159 test_done "$testroot" "1"
160 return 1
163 cmp -s "$testroot/stderr.expected" "$testroot/stderr"
164 ret=$?
165 if [ $ret -ne 0 ]; then
166 diff -u "$testroot/stderr.expected" "$testroot/stderr"
167 test_done "$testroot" "$ret"
168 return 1
171 echo 'alpha' > $testroot/stdout.expected
172 echo 'beta' >> $testroot/stdout.expected
173 echo 'epsilon/' >> $testroot/stdout.expected
174 echo 'gamma/' >> $testroot/stdout.expected
176 got tree -r "$testroot/repo" -c:head > "$testroot/stdout"
177 cmp -s $testroot/stdout.expected $testroot/stdout
178 ret=$?
179 if [ $ret -ne 0 ]; then
180 diff -u $testroot/stdout.expected $testroot/stdout
181 test_done "$testroot" "$ret"
182 return 1
185 got checkout "$testroot/repo" "$wt" > /dev/null
188 cd "$wt"
189 mkdir bing
190 echo "foo" > foo
191 echo "bar" > bar
192 echo "baz" > baz
193 echo "bob" > bing/bob
194 got add foo bar baz bing/bob > /dev/null
195 got commit -m "add foo" foo > /dev/null
196 got commit -m "add bar" bar > /dev/null
197 got commit -m "add baz" baz > /dev/null
198 got commit -m "add bing/bob" > /dev/null
201 echo 'alpha' > $testroot/stdout.expected
202 echo 'beta' >> $testroot/stdout.expected
203 echo 'epsilon/' >> $testroot/stdout.expected
204 echo 'foo' >> $testroot/stdout.expected
205 echo 'gamma/' >> $testroot/stdout.expected
207 (cd "$wt" && got tree -c:base:-3 > $testroot/stdout)
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret=$?
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
213 return 1
216 echo 'alpha' > $testroot/stdout.expected
217 echo 'bar' >> $testroot/stdout.expected
218 echo 'beta' >> $testroot/stdout.expected
219 echo 'epsilon/' >> $testroot/stdout.expected
220 echo 'foo' >> $testroot/stdout.expected
221 echo 'gamma/' >> $testroot/stdout.expected
223 (cd "$wt" && got tree -cmaster:-2 > $testroot/stdout)
224 cmp -s $testroot/stdout.expected $testroot/stdout
225 ret=$?
226 if [ $ret -ne 0 ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
228 test_done "$testroot" "$ret"
229 return 1
232 echo 'alpha' > $testroot/stdout.expected
233 echo 'bar' >> $testroot/stdout.expected
234 echo 'baz' >> $testroot/stdout.expected
235 echo 'beta' >> $testroot/stdout.expected
236 echo 'epsilon/' >> $testroot/stdout.expected
237 echo 'foo' >> $testroot/stdout.expected
238 echo 'gamma/' >> $testroot/stdout.expected
240 (cd "$wt" && got tree -c:head:- > $testroot/stdout)
241 cmp -s $testroot/stdout.expected $testroot/stdout
242 ret=$?
243 if [ $ret -ne 0 ]; then
244 diff -u $testroot/stdout.expected $testroot/stdout
245 test_done "$testroot" "$ret"
246 return 1
249 echo 'alpha' > $testroot/stdout.expected
250 echo 'bar' >> $testroot/stdout.expected
251 echo 'baz' >> $testroot/stdout.expected
252 echo 'beta' >> $testroot/stdout.expected
253 echo 'bing/' >> $testroot/stdout.expected
254 echo 'epsilon/' >> $testroot/stdout.expected
255 echo 'foo' >> $testroot/stdout.expected
256 echo 'gamma/' >> $testroot/stdout.expected
258 (cd "$wt" && got up -c:base:-4 > $testroot/stdout)
259 (cd "$wt" && got tree -c:base:+4 > $testroot/stdout)
260 cmp -s $testroot/stdout.expected $testroot/stdout
261 ret=$?
262 if [ $ret -ne 0 ]; then
263 diff -u $testroot/stdout.expected $testroot/stdout
264 test_done "$testroot" "$ret"
265 return 1
268 test_done "$testroot" "0"
271 test_parseargs "$@"
272 run_test test_tree_basic
273 run_test test_tree_branch
274 run_test test_tree_submodule
275 run_test test_tree_submodule_of_same_repo
276 run_test test_tree_commit_keywords