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 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
96 if [ $ret -eq 0 ]; then
97 echo "tree command succeeded unexpectedly" >&2
98 test_done
"$testroot" "1"
101 echo "got: object $submodule_id not found" > $testroot/stderr.expected
103 cmp -s $testroot/stderr.expected
$testroot/stderr
105 if [ $ret -ne 0 ]; then
106 diff -u $testroot/stderr.expected
$testroot/stderr
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
123 if [ $ret -eq 0 ]; then
124 echo "tree command succeeded unexpectedly" >&2
125 test_done
"$testroot" "1"
128 if [ -n "$GOT_TEST_PACK" ]; then
129 echo "got-read-pack: bad object data" \
130 > $testroot/stderr.expected
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
139 if [ $ret -ne 0 ]; then
140 diff -u $testroot/stderr.expected
$testroot/stderr
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"
154 if [ $ret -eq 0 ]; then
155 echo "tree command succeeded unexpectedly" >&2
156 test_done
"$testroot" "1"
160 cmp -s "$testroot/stderr.expected" "$testroot/stderr"
162 if [ $ret -ne 0 ]; then
163 diff -u "$testroot/stderr.expected" "$testroot/stderr"
164 test_done
"$testroot" "$ret"
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
176 if [ $ret -ne 0 ]; then
177 diff -u $testroot/stdout.expected
$testroot/stdout
178 test_done
"$testroot" "$ret"
182 got checkout
"$testroot/repo" "$wt" > /dev
/null
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
207 if [ $ret -ne 0 ]; then
208 diff -u $testroot/stdout.expected
$testroot/stdout
209 test_done
"$testroot" "$ret"
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
223 if [ $ret -ne 0 ]; then
224 diff -u $testroot/stdout.expected
$testroot/stdout
225 test_done
"$testroot" "$ret"
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
240 if [ $ret -ne 0 ]; then
241 diff -u $testroot/stdout.expected
$testroot/stdout
242 test_done
"$testroot" "$ret"
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
259 if [ $ret -ne 0 ]; then
260 diff -u $testroot/stdout.expected
$testroot/stdout
261 test_done
"$testroot" "$ret"
265 test_done
"$testroot" "0"
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