3 4e0a20a4 2020-03-23 tracey # Copyright (c) 2020 Tracey Emery <tracey@openbsd.org>
5 4e0a20a4 2020-03-23 tracey # Permission to use, copy, modify, and distribute this software for any
6 4e0a20a4 2020-03-23 tracey # purpose with or without fee is hereby granted, provided that the above
7 4e0a20a4 2020-03-23 tracey # copyright notice and this permission notice appear in all copies.
9 4e0a20a4 2020-03-23 tracey # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 4e0a20a4 2020-03-23 tracey # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 4e0a20a4 2020-03-23 tracey # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 4e0a20a4 2020-03-23 tracey # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 4e0a20a4 2020-03-23 tracey # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 4e0a20a4 2020-03-23 tracey # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 4e0a20a4 2020-03-23 tracey # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 4e0a20a4 2020-03-23 tracey . ./common.sh
19 f6cae3ed 2020-09-13 naddy test_tree_basic() {
20 4e0a20a4 2020-03-23 tracey local testroot=`test_init tree_basic`
22 4e0a20a4 2020-03-23 tracey got checkout $testroot/repo $testroot/wt > /dev/null
24 4e0a20a4 2020-03-23 tracey echo "new file" > $testroot/wt/foo
26 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got add foo > /dev/null)
27 810a850e 2020-03-23 tracey (cd $testroot/wt && got commit -m "add foo" foo > /dev/null)
29 4e0a20a4 2020-03-23 tracey echo 'alpha' > $testroot/stdout.expected
30 4e0a20a4 2020-03-23 tracey echo 'beta' >> $testroot/stdout.expected
31 4e0a20a4 2020-03-23 tracey echo 'epsilon/' >> $testroot/stdout.expected
32 4e0a20a4 2020-03-23 tracey echo 'foo' >> $testroot/stdout.expected
33 4e0a20a4 2020-03-23 tracey echo 'gamma/' >> $testroot/stdout.expected
35 9628f36d 2023-06-19 stsp for p in "" "." "/"; do
36 9628f36d 2023-06-19 stsp (cd $testroot/wt && got tree $p > $testroot/stdout)
37 9628f36d 2023-06-19 stsp cmp -s $testroot/stdout.expected $testroot/stdout
39 9628f36d 2023-06-19 stsp if [ $ret -ne 0 ]; then
40 9628f36d 2023-06-19 stsp diff -u $testroot/stdout.expected $testroot/stdout
41 9628f36d 2023-06-19 stsp test_done "$testroot" "$ret"
46 9628f36d 2023-06-19 stsp test_done "$testroot" "0"
49 f6cae3ed 2020-09-13 naddy test_tree_branch() {
50 4e0a20a4 2020-03-23 tracey local testroot=`test_init tree_branch`
52 4e0a20a4 2020-03-23 tracey got checkout $testroot/repo $testroot/wt > /dev/null
54 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
55 4e0a20a4 2020-03-23 tracey test_done "$testroot" "$ret"
59 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got br foo > $testroot/stdout)
61 4e0a20a4 2020-03-23 tracey echo "new file" > $testroot/wt/foo
63 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got add foo > /dev/null)
64 810a850e 2020-03-23 tracey (cd $testroot/wt && got commit -m "add foo" foo > /dev/null)
66 4e0a20a4 2020-03-23 tracey echo 'alpha' > $testroot/stdout.expected
67 4e0a20a4 2020-03-23 tracey echo 'beta' >> $testroot/stdout.expected
68 4e0a20a4 2020-03-23 tracey echo 'epsilon/' >> $testroot/stdout.expected
69 4e0a20a4 2020-03-23 tracey echo 'foo' >> $testroot/stdout.expected
70 4e0a20a4 2020-03-23 tracey echo 'gamma/' >> $testroot/stdout.expected
72 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got tree > $testroot/stdout)
74 4e0a20a4 2020-03-23 tracey cmp -s $testroot/stdout.expected $testroot/stdout
76 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
77 4e0a20a4 2020-03-23 tracey diff -u $testroot/stdout.expected $testroot/stdout
80 4e0a20a4 2020-03-23 tracey test_done "$testroot" "$ret"
83 f6cae3ed 2020-09-13 naddy test_tree_submodule() {
84 e7303626 2020-05-14 stsp local testroot=`test_init tree_submodule`
86 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
87 f73bf5bd 2023-10-01 naddy git -C $testroot/repo -c protocol.file.allow=always \
88 f73bf5bd 2023-10-01 naddy submodule -q add ../repo2
89 f73bf5bd 2023-10-01 naddy git -C $testroot/repo commit -q -m 'adding submodule'
91 e7303626 2020-05-14 stsp local submodule_id=$(got tree -r $testroot/repo -i | \
92 e7303626 2020-05-14 stsp grep 'repo2\$$' | cut -d ' ' -f1)
93 e7303626 2020-05-14 stsp local objpath=`get_loose_object_path $testroot/repo $submodule_id`
95 e7303626 2020-05-14 stsp # Currently fails in open(2)
96 e7303626 2020-05-14 stsp got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
98 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
99 e7303626 2020-05-14 stsp echo "tree command succeeded unexpectedly" >&2
100 e7303626 2020-05-14 stsp test_done "$testroot" "1"
103 e7303626 2020-05-14 stsp echo "got: open: $objpath: No such file or directory" \
104 e7303626 2020-05-14 stsp > $testroot/stderr.expected
106 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
108 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
109 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
112 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
115 f6cae3ed 2020-09-13 naddy test_tree_submodule_of_same_repo() {
116 e7303626 2020-05-14 stsp local testroot=`test_init tree_submodule_of_same_repo`
118 f73bf5bd 2023-10-01 naddy git -C $testroot clone -q repo repo2 >/dev/null
119 f73bf5bd 2023-10-01 naddy git -C $testroot/repo -c protocol.file.allow=always \
120 f73bf5bd 2023-10-01 naddy submodule -q add ../repo2
121 f73bf5bd 2023-10-01 naddy git -C $testroot/repo commit -q -m 'adding submodule'
123 e7303626 2020-05-14 stsp # Currently fails with "bad object data"
124 e7303626 2020-05-14 stsp got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
126 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
127 e7303626 2020-05-14 stsp echo "tree command succeeded unexpectedly" >&2
128 e7303626 2020-05-14 stsp test_done "$testroot" "1"
131 c5fdccbf 2020-12-10 yzhong if [ -n "$GOT_TEST_PACK" ]; then
132 c5fdccbf 2020-12-10 yzhong echo "got-read-pack: bad object data" \
133 c5fdccbf 2020-12-10 yzhong > $testroot/stderr.expected
135 c5fdccbf 2020-12-10 yzhong echo "got-read-tree: bad object data" \
136 c5fdccbf 2020-12-10 yzhong > $testroot/stderr.expected
138 e7303626 2020-05-14 stsp echo "got: bad object data" >> $testroot/stderr.expected
140 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
142 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
143 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
146 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
149 4390d6c1 2023-07-18 mark test_tree_commit_keywords() {
150 4390d6c1 2023-07-18 mark local testroot=$(test_init tree_commit_keywords)
151 4390d6c1 2023-07-18 mark local wt="$testroot/wt"
153 4390d6c1 2023-07-18 mark # :base requires work tree
154 4390d6c1 2023-07-18 mark echo "got: '-c :base' requires work tree" > "$testroot/stderr.expected"
155 4390d6c1 2023-07-18 mark got tree -r "$testroot/repo" -c:base 2> "$testroot/stderr"
157 4390d6c1 2023-07-18 mark if [ $ret -eq 0 ]; then
158 4390d6c1 2023-07-18 mark echo "tree command succeeded unexpectedly" >&2
159 4390d6c1 2023-07-18 mark test_done "$testroot" "1"
163 4390d6c1 2023-07-18 mark cmp -s "$testroot/stderr.expected" "$testroot/stderr"
165 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
166 4390d6c1 2023-07-18 mark diff -u "$testroot/stderr.expected" "$testroot/stderr"
167 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
171 4390d6c1 2023-07-18 mark echo 'alpha' > $testroot/stdout.expected
172 4390d6c1 2023-07-18 mark echo 'beta' >> $testroot/stdout.expected
173 4390d6c1 2023-07-18 mark echo 'epsilon/' >> $testroot/stdout.expected
174 4390d6c1 2023-07-18 mark echo 'gamma/' >> $testroot/stdout.expected
176 4390d6c1 2023-07-18 mark got tree -r "$testroot/repo" -c:head > "$testroot/stdout"
177 4390d6c1 2023-07-18 mark cmp -s $testroot/stdout.expected $testroot/stdout
179 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
180 4390d6c1 2023-07-18 mark diff -u $testroot/stdout.expected $testroot/stdout
181 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
185 4390d6c1 2023-07-18 mark got checkout "$testroot/repo" "$wt" > /dev/null
190 4390d6c1 2023-07-18 mark echo "foo" > foo
191 4390d6c1 2023-07-18 mark echo "bar" > bar
192 4390d6c1 2023-07-18 mark echo "baz" > baz
193 4390d6c1 2023-07-18 mark echo "bob" > bing/bob
194 4390d6c1 2023-07-18 mark got add foo bar baz bing/bob > /dev/null
195 4390d6c1 2023-07-18 mark got commit -m "add foo" foo > /dev/null
196 4390d6c1 2023-07-18 mark got commit -m "add bar" bar > /dev/null
197 4390d6c1 2023-07-18 mark got commit -m "add baz" baz > /dev/null
198 4390d6c1 2023-07-18 mark got commit -m "add bing/bob" > /dev/null
201 4390d6c1 2023-07-18 mark echo 'alpha' > $testroot/stdout.expected
202 4390d6c1 2023-07-18 mark echo 'beta' >> $testroot/stdout.expected
203 4390d6c1 2023-07-18 mark echo 'epsilon/' >> $testroot/stdout.expected
204 4390d6c1 2023-07-18 mark echo 'foo' >> $testroot/stdout.expected
205 4390d6c1 2023-07-18 mark echo 'gamma/' >> $testroot/stdout.expected
207 4390d6c1 2023-07-18 mark (cd "$wt" && got tree -c:base:-3 > $testroot/stdout)
208 4390d6c1 2023-07-18 mark cmp -s $testroot/stdout.expected $testroot/stdout
210 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
211 4390d6c1 2023-07-18 mark diff -u $testroot/stdout.expected $testroot/stdout
212 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
216 4390d6c1 2023-07-18 mark echo 'alpha' > $testroot/stdout.expected
217 4390d6c1 2023-07-18 mark echo 'bar' >> $testroot/stdout.expected
218 4390d6c1 2023-07-18 mark echo 'beta' >> $testroot/stdout.expected
219 4390d6c1 2023-07-18 mark echo 'epsilon/' >> $testroot/stdout.expected
220 4390d6c1 2023-07-18 mark echo 'foo' >> $testroot/stdout.expected
221 4390d6c1 2023-07-18 mark echo 'gamma/' >> $testroot/stdout.expected
223 4390d6c1 2023-07-18 mark (cd "$wt" && got tree -cmaster:-2 > $testroot/stdout)
224 4390d6c1 2023-07-18 mark cmp -s $testroot/stdout.expected $testroot/stdout
226 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
227 4390d6c1 2023-07-18 mark diff -u $testroot/stdout.expected $testroot/stdout
228 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
232 4390d6c1 2023-07-18 mark echo 'alpha' > $testroot/stdout.expected
233 4390d6c1 2023-07-18 mark echo 'bar' >> $testroot/stdout.expected
234 4390d6c1 2023-07-18 mark echo 'baz' >> $testroot/stdout.expected
235 4390d6c1 2023-07-18 mark echo 'beta' >> $testroot/stdout.expected
236 4390d6c1 2023-07-18 mark echo 'epsilon/' >> $testroot/stdout.expected
237 4390d6c1 2023-07-18 mark echo 'foo' >> $testroot/stdout.expected
238 4390d6c1 2023-07-18 mark echo 'gamma/' >> $testroot/stdout.expected
240 4390d6c1 2023-07-18 mark (cd "$wt" && got tree -c:head:- > $testroot/stdout)
241 4390d6c1 2023-07-18 mark cmp -s $testroot/stdout.expected $testroot/stdout
243 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
244 4390d6c1 2023-07-18 mark diff -u $testroot/stdout.expected $testroot/stdout
245 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
249 4390d6c1 2023-07-18 mark echo 'alpha' > $testroot/stdout.expected
250 4390d6c1 2023-07-18 mark echo 'bar' >> $testroot/stdout.expected
251 4390d6c1 2023-07-18 mark echo 'baz' >> $testroot/stdout.expected
252 4390d6c1 2023-07-18 mark echo 'beta' >> $testroot/stdout.expected
253 4390d6c1 2023-07-18 mark echo 'bing/' >> $testroot/stdout.expected
254 4390d6c1 2023-07-18 mark echo 'epsilon/' >> $testroot/stdout.expected
255 4390d6c1 2023-07-18 mark echo 'foo' >> $testroot/stdout.expected
256 4390d6c1 2023-07-18 mark echo 'gamma/' >> $testroot/stdout.expected
258 4390d6c1 2023-07-18 mark (cd "$wt" && got up -c:base:-4 > $testroot/stdout)
259 4390d6c1 2023-07-18 mark (cd "$wt" && got tree -c:base:+4 > $testroot/stdout)
260 4390d6c1 2023-07-18 mark cmp -s $testroot/stdout.expected $testroot/stdout
262 4390d6c1 2023-07-18 mark if [ $ret -ne 0 ]; then
263 4390d6c1 2023-07-18 mark diff -u $testroot/stdout.expected $testroot/stdout
264 4390d6c1 2023-07-18 mark test_done "$testroot" "$ret"
268 4390d6c1 2023-07-18 mark test_done "$testroot" "0"
271 7fb414ae 2020-08-08 stsp test_parseargs "$@"
272 4e0a20a4 2020-03-23 tracey run_test test_tree_basic
273 4e0a20a4 2020-03-23 tracey run_test test_tree_branch
274 e7303626 2020-05-14 stsp run_test test_tree_submodule
275 e7303626 2020-05-14 stsp run_test test_tree_submodule_of_same_repo
276 4390d6c1 2023-07-18 mark run_test test_tree_commit_keywords