Blame


1 4e0a20a4 2020-03-23 tracey #!/bin/sh
2 4e0a20a4 2020-03-23 tracey #
3 4e0a20a4 2020-03-23 tracey # Copyright (c) 2020 Tracey Emery <tracey@openbsd.org>
4 4e0a20a4 2020-03-23 tracey #
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.
8 4e0a20a4 2020-03-23 tracey #
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.
16 4e0a20a4 2020-03-23 tracey
17 4e0a20a4 2020-03-23 tracey . ./common.sh
18 4e0a20a4 2020-03-23 tracey
19 f6cae3ed 2020-09-13 naddy test_tree_basic() {
20 4e0a20a4 2020-03-23 tracey local testroot=`test_init tree_basic`
21 4e0a20a4 2020-03-23 tracey
22 4e0a20a4 2020-03-23 tracey got checkout $testroot/repo $testroot/wt > /dev/null
23 4e0a20a4 2020-03-23 tracey
24 4e0a20a4 2020-03-23 tracey echo "new file" > $testroot/wt/foo
25 4e0a20a4 2020-03-23 tracey
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)
28 4e0a20a4 2020-03-23 tracey
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
34 4e0a20a4 2020-03-23 tracey
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
38 9628f36d 2023-06-19 stsp ret=$?
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"
42 9628f36d 2023-06-19 stsp return 1
43 9628f36d 2023-06-19 stsp fi
44 9628f36d 2023-06-19 stsp done
45 4e0a20a4 2020-03-23 tracey
46 9628f36d 2023-06-19 stsp test_done "$testroot" "0"
47 4e0a20a4 2020-03-23 tracey }
48 4e0a20a4 2020-03-23 tracey
49 f6cae3ed 2020-09-13 naddy test_tree_branch() {
50 4e0a20a4 2020-03-23 tracey local testroot=`test_init tree_branch`
51 4e0a20a4 2020-03-23 tracey
52 4e0a20a4 2020-03-23 tracey got checkout $testroot/repo $testroot/wt > /dev/null
53 49c543a6 2022-03-31 naddy ret=$?
54 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
55 4e0a20a4 2020-03-23 tracey test_done "$testroot" "$ret"
56 4e0a20a4 2020-03-23 tracey return 1
57 4e0a20a4 2020-03-23 tracey fi
58 4e0a20a4 2020-03-23 tracey
59 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got br foo > $testroot/stdout)
60 4e0a20a4 2020-03-23 tracey
61 4e0a20a4 2020-03-23 tracey echo "new file" > $testroot/wt/foo
62 4e0a20a4 2020-03-23 tracey
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)
65 4e0a20a4 2020-03-23 tracey
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
71 4e0a20a4 2020-03-23 tracey
72 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got tree > $testroot/stdout)
73 4e0a20a4 2020-03-23 tracey
74 4e0a20a4 2020-03-23 tracey cmp -s $testroot/stdout.expected $testroot/stdout
75 49c543a6 2022-03-31 naddy ret=$?
76 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
77 4e0a20a4 2020-03-23 tracey diff -u $testroot/stdout.expected $testroot/stdout
78 4e0a20a4 2020-03-23 tracey fi
79 4e0a20a4 2020-03-23 tracey
80 4e0a20a4 2020-03-23 tracey test_done "$testroot" "$ret"
81 4e0a20a4 2020-03-23 tracey }
82 4e0a20a4 2020-03-23 tracey
83 f6cae3ed 2020-09-13 naddy test_tree_submodule() {
84 e7303626 2020-05-14 stsp local testroot=`test_init tree_submodule`
85 e7303626 2020-05-14 stsp
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'
90 e7303626 2020-05-14 stsp
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`
94 e7303626 2020-05-14 stsp
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
97 49c543a6 2022-03-31 naddy ret=$?
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"
101 e7303626 2020-05-14 stsp return 1
102 e7303626 2020-05-14 stsp fi
103 e7303626 2020-05-14 stsp echo "got: open: $objpath: No such file or directory" \
104 e7303626 2020-05-14 stsp > $testroot/stderr.expected
105 e7303626 2020-05-14 stsp
106 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
107 49c543a6 2022-03-31 naddy ret=$?
108 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
109 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
110 e7303626 2020-05-14 stsp return 1
111 e7303626 2020-05-14 stsp fi
112 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
113 e7303626 2020-05-14 stsp }
114 e7303626 2020-05-14 stsp
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`
117 e7303626 2020-05-14 stsp
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'
122 e7303626 2020-05-14 stsp
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
125 49c543a6 2022-03-31 naddy ret=$?
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"
129 e7303626 2020-05-14 stsp return 1
130 e7303626 2020-05-14 stsp fi
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
134 c5fdccbf 2020-12-10 yzhong else
135 c5fdccbf 2020-12-10 yzhong echo "got-read-tree: bad object data" \
136 c5fdccbf 2020-12-10 yzhong > $testroot/stderr.expected
137 c5fdccbf 2020-12-10 yzhong fi
138 e7303626 2020-05-14 stsp echo "got: bad object data" >> $testroot/stderr.expected
139 e7303626 2020-05-14 stsp
140 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
141 49c543a6 2022-03-31 naddy ret=$?
142 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
143 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
144 e7303626 2020-05-14 stsp return 1
145 e7303626 2020-05-14 stsp fi
146 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
147 e7303626 2020-05-14 stsp }
148 e7303626 2020-05-14 stsp
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"
152 4390d6c1 2023-07-18 mark
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"
156 4390d6c1 2023-07-18 mark ret=$?
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"
160 4390d6c1 2023-07-18 mark return 1
161 4390d6c1 2023-07-18 mark fi
162 4390d6c1 2023-07-18 mark
163 4390d6c1 2023-07-18 mark cmp -s "$testroot/stderr.expected" "$testroot/stderr"
164 4390d6c1 2023-07-18 mark ret=$?
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"
168 4390d6c1 2023-07-18 mark return 1
169 4390d6c1 2023-07-18 mark fi
170 4390d6c1 2023-07-18 mark
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
175 4390d6c1 2023-07-18 mark
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
178 4390d6c1 2023-07-18 mark ret=$?
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"
182 4390d6c1 2023-07-18 mark return 1
183 4390d6c1 2023-07-18 mark fi
184 4390d6c1 2023-07-18 mark
185 4390d6c1 2023-07-18 mark got checkout "$testroot/repo" "$wt" > /dev/null
186 4390d6c1 2023-07-18 mark
187 4390d6c1 2023-07-18 mark (
188 4390d6c1 2023-07-18 mark cd "$wt"
189 4390d6c1 2023-07-18 mark mkdir bing
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
199 4390d6c1 2023-07-18 mark )
200 4390d6c1 2023-07-18 mark
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
206 4390d6c1 2023-07-18 mark
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
209 4390d6c1 2023-07-18 mark ret=$?
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"
213 4390d6c1 2023-07-18 mark return 1
214 4390d6c1 2023-07-18 mark fi
215 4390d6c1 2023-07-18 mark
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
222 4390d6c1 2023-07-18 mark
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
225 4390d6c1 2023-07-18 mark ret=$?
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"
229 4390d6c1 2023-07-18 mark return 1
230 4390d6c1 2023-07-18 mark fi
231 4390d6c1 2023-07-18 mark
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
239 4390d6c1 2023-07-18 mark
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
242 4390d6c1 2023-07-18 mark ret=$?
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"
246 4390d6c1 2023-07-18 mark return 1
247 4390d6c1 2023-07-18 mark fi
248 4390d6c1 2023-07-18 mark
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
257 4390d6c1 2023-07-18 mark
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
261 4390d6c1 2023-07-18 mark ret=$?
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"
265 4390d6c1 2023-07-18 mark return 1
266 4390d6c1 2023-07-18 mark fi
267 4390d6c1 2023-07-18 mark
268 4390d6c1 2023-07-18 mark test_done "$testroot" "0"
269 4390d6c1 2023-07-18 mark }
270 4390d6c1 2023-07-18 mark
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