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.
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
39 if [ $ret -ne 0 ]; then
40 diff -u $testroot/stdout.expected
$testroot/stdout
41 test_done
"$testroot" "$ret"
46 test_done
"$testroot" "0"
50 local testroot
=`test_init tree_branch`
52 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
54 if [ $ret -ne 0 ]; then
55 test_done
"$testroot" "$ret"
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
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
98 if [ $ret -eq 0 ]; then
99 echo "tree command succeeded unexpectedly" >&2
100 test_done
"$testroot" "1"
103 echo "got: open: $objpath: No such file or directory" \
104 > $testroot/stderr.expected
106 cmp -s $testroot/stderr.expected
$testroot/stderr
108 if [ $ret -ne 0 ]; then
109 diff -u $testroot/stderr.expected
$testroot/stderr
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
126 if [ $ret -eq 0 ]; then
127 echo "tree command succeeded unexpectedly" >&2
128 test_done
"$testroot" "1"
131 if [ -n "$GOT_TEST_PACK" ]; then
132 echo "got-read-pack: bad object data" \
133 > $testroot/stderr.expected
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
142 if [ $ret -ne 0 ]; then
143 diff -u $testroot/stderr.expected
$testroot/stderr
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"
157 if [ $ret -eq 0 ]; then
158 echo "tree command succeeded unexpectedly" >&2
159 test_done
"$testroot" "1"
163 cmp -s "$testroot/stderr.expected" "$testroot/stderr"
165 if [ $ret -ne 0 ]; then
166 diff -u "$testroot/stderr.expected" "$testroot/stderr"
167 test_done
"$testroot" "$ret"
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
179 if [ $ret -ne 0 ]; then
180 diff -u $testroot/stdout.expected
$testroot/stdout
181 test_done
"$testroot" "$ret"
185 got checkout
"$testroot/repo" "$wt" > /dev
/null
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
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected
$testroot/stdout
212 test_done
"$testroot" "$ret"
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
226 if [ $ret -ne 0 ]; then
227 diff -u $testroot/stdout.expected
$testroot/stdout
228 test_done
"$testroot" "$ret"
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
243 if [ $ret -ne 0 ]; then
244 diff -u $testroot/stdout.expected
$testroot/stdout
245 test_done
"$testroot" "$ret"
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
262 if [ $ret -ne 0 ]; then
263 diff -u $testroot/stdout.expected
$testroot/stdout
264 test_done
"$testroot" "$ret"
268 test_done
"$testroot" "0"
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