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 9fecc8d0 2023-06-22 thomas for p in "" "." "/"; do
36 9fecc8d0 2023-06-22 thomas (cd $testroot/wt && got tree $p > $testroot/stdout)
37 9fecc8d0 2023-06-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
38 9fecc8d0 2023-06-22 thomas ret=$?
39 9fecc8d0 2023-06-22 thomas if [ $ret -ne 0 ]; then
40 9fecc8d0 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
41 9fecc8d0 2023-06-22 thomas test_done "$testroot" "$ret"
42 9fecc8d0 2023-06-22 thomas return 1
43 9fecc8d0 2023-06-22 thomas fi
44 9fecc8d0 2023-06-22 thomas done
45 4e0a20a4 2020-03-23 tracey
46 9fecc8d0 2023-06-22 thomas 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 fc414659 2022-04-16 thomas ret=$?
54 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
76 fc414659 2022-04-16 thomas 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 d1e03b8c 2023-10-08 thomas git -C $testroot/repo -c protocol.file.allow=always \
88 d1e03b8c 2023-10-08 thomas submodule -q add ../repo2
89 d1e03b8c 2023-10-08 thomas 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 fc414659 2022-04-16 thomas ret=$?
98 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
108 fc414659 2022-04-16 thomas 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 d1e03b8c 2023-10-08 thomas git -C $testroot clone -q repo repo2 >/dev/null
119 d1e03b8c 2023-10-08 thomas git -C $testroot/repo -c protocol.file.allow=always \
120 d1e03b8c 2023-10-08 thomas submodule -q add ../repo2
121 d1e03b8c 2023-10-08 thomas 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 fc414659 2022-04-16 thomas ret=$?
126 fc414659 2022-04-16 thomas 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 fc414659 2022-04-16 thomas ret=$?
142 fc414659 2022-04-16 thomas 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 3795e2b6 2023-07-19 thomas test_tree_commit_keywords() {
150 3795e2b6 2023-07-19 thomas local testroot=$(test_init tree_commit_keywords)
151 3795e2b6 2023-07-19 thomas local wt="$testroot/wt"
152 3795e2b6 2023-07-19 thomas
153 3795e2b6 2023-07-19 thomas # :base requires work tree
154 3795e2b6 2023-07-19 thomas echo "got: '-c :base' requires work tree" > "$testroot/stderr.expected"
155 3795e2b6 2023-07-19 thomas got tree -r "$testroot/repo" -c:base 2> "$testroot/stderr"
156 3795e2b6 2023-07-19 thomas ret=$?
157 3795e2b6 2023-07-19 thomas if [ $ret -eq 0 ]; then
158 3795e2b6 2023-07-19 thomas echo "tree command succeeded unexpectedly" >&2
159 3795e2b6 2023-07-19 thomas test_done "$testroot" "1"
160 3795e2b6 2023-07-19 thomas return 1
161 3795e2b6 2023-07-19 thomas fi
162 3795e2b6 2023-07-19 thomas
163 3795e2b6 2023-07-19 thomas cmp -s "$testroot/stderr.expected" "$testroot/stderr"
164 3795e2b6 2023-07-19 thomas ret=$?
165 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
166 3795e2b6 2023-07-19 thomas diff -u "$testroot/stderr.expected" "$testroot/stderr"
167 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
168 3795e2b6 2023-07-19 thomas return 1
169 3795e2b6 2023-07-19 thomas fi
170 3795e2b6 2023-07-19 thomas
171 3795e2b6 2023-07-19 thomas echo 'alpha' > $testroot/stdout.expected
172 3795e2b6 2023-07-19 thomas echo 'beta' >> $testroot/stdout.expected
173 3795e2b6 2023-07-19 thomas echo 'epsilon/' >> $testroot/stdout.expected
174 3795e2b6 2023-07-19 thomas echo 'gamma/' >> $testroot/stdout.expected
175 3795e2b6 2023-07-19 thomas
176 3795e2b6 2023-07-19 thomas got tree -r "$testroot/repo" -c:head > "$testroot/stdout"
177 3795e2b6 2023-07-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
178 3795e2b6 2023-07-19 thomas ret=$?
179 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
180 3795e2b6 2023-07-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
181 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
182 3795e2b6 2023-07-19 thomas return 1
183 3795e2b6 2023-07-19 thomas fi
184 3795e2b6 2023-07-19 thomas
185 3795e2b6 2023-07-19 thomas got checkout "$testroot/repo" "$wt" > /dev/null
186 3795e2b6 2023-07-19 thomas
187 3795e2b6 2023-07-19 thomas (
188 3795e2b6 2023-07-19 thomas cd "$wt"
189 3795e2b6 2023-07-19 thomas mkdir bing
190 3795e2b6 2023-07-19 thomas echo "foo" > foo
191 3795e2b6 2023-07-19 thomas echo "bar" > bar
192 3795e2b6 2023-07-19 thomas echo "baz" > baz
193 3795e2b6 2023-07-19 thomas echo "bob" > bing/bob
194 3795e2b6 2023-07-19 thomas got add foo bar baz bing/bob > /dev/null
195 3795e2b6 2023-07-19 thomas got commit -m "add foo" foo > /dev/null
196 3795e2b6 2023-07-19 thomas got commit -m "add bar" bar > /dev/null
197 3795e2b6 2023-07-19 thomas got commit -m "add baz" baz > /dev/null
198 3795e2b6 2023-07-19 thomas got commit -m "add bing/bob" > /dev/null
199 3795e2b6 2023-07-19 thomas )
200 3795e2b6 2023-07-19 thomas
201 3795e2b6 2023-07-19 thomas echo 'alpha' > $testroot/stdout.expected
202 3795e2b6 2023-07-19 thomas echo 'beta' >> $testroot/stdout.expected
203 3795e2b6 2023-07-19 thomas echo 'epsilon/' >> $testroot/stdout.expected
204 3795e2b6 2023-07-19 thomas echo 'foo' >> $testroot/stdout.expected
205 3795e2b6 2023-07-19 thomas echo 'gamma/' >> $testroot/stdout.expected
206 3795e2b6 2023-07-19 thomas
207 3795e2b6 2023-07-19 thomas (cd "$wt" && got tree -c:base:-3 > $testroot/stdout)
208 3795e2b6 2023-07-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
209 3795e2b6 2023-07-19 thomas ret=$?
210 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
211 3795e2b6 2023-07-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
212 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
213 3795e2b6 2023-07-19 thomas return 1
214 3795e2b6 2023-07-19 thomas fi
215 3795e2b6 2023-07-19 thomas
216 3795e2b6 2023-07-19 thomas echo 'alpha' > $testroot/stdout.expected
217 3795e2b6 2023-07-19 thomas echo 'bar' >> $testroot/stdout.expected
218 3795e2b6 2023-07-19 thomas echo 'beta' >> $testroot/stdout.expected
219 3795e2b6 2023-07-19 thomas echo 'epsilon/' >> $testroot/stdout.expected
220 3795e2b6 2023-07-19 thomas echo 'foo' >> $testroot/stdout.expected
221 3795e2b6 2023-07-19 thomas echo 'gamma/' >> $testroot/stdout.expected
222 3795e2b6 2023-07-19 thomas
223 3795e2b6 2023-07-19 thomas (cd "$wt" && got tree -cmaster:-2 > $testroot/stdout)
224 3795e2b6 2023-07-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
225 3795e2b6 2023-07-19 thomas ret=$?
226 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
227 3795e2b6 2023-07-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
228 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
229 3795e2b6 2023-07-19 thomas return 1
230 3795e2b6 2023-07-19 thomas fi
231 3795e2b6 2023-07-19 thomas
232 3795e2b6 2023-07-19 thomas echo 'alpha' > $testroot/stdout.expected
233 3795e2b6 2023-07-19 thomas echo 'bar' >> $testroot/stdout.expected
234 3795e2b6 2023-07-19 thomas echo 'baz' >> $testroot/stdout.expected
235 3795e2b6 2023-07-19 thomas echo 'beta' >> $testroot/stdout.expected
236 3795e2b6 2023-07-19 thomas echo 'epsilon/' >> $testroot/stdout.expected
237 3795e2b6 2023-07-19 thomas echo 'foo' >> $testroot/stdout.expected
238 3795e2b6 2023-07-19 thomas echo 'gamma/' >> $testroot/stdout.expected
239 3795e2b6 2023-07-19 thomas
240 3795e2b6 2023-07-19 thomas (cd "$wt" && got tree -c:head:- > $testroot/stdout)
241 3795e2b6 2023-07-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
242 3795e2b6 2023-07-19 thomas ret=$?
243 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
244 3795e2b6 2023-07-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
245 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
246 3795e2b6 2023-07-19 thomas return 1
247 3795e2b6 2023-07-19 thomas fi
248 3795e2b6 2023-07-19 thomas
249 3795e2b6 2023-07-19 thomas echo 'alpha' > $testroot/stdout.expected
250 3795e2b6 2023-07-19 thomas echo 'bar' >> $testroot/stdout.expected
251 3795e2b6 2023-07-19 thomas echo 'baz' >> $testroot/stdout.expected
252 3795e2b6 2023-07-19 thomas echo 'beta' >> $testroot/stdout.expected
253 3795e2b6 2023-07-19 thomas echo 'bing/' >> $testroot/stdout.expected
254 3795e2b6 2023-07-19 thomas echo 'epsilon/' >> $testroot/stdout.expected
255 3795e2b6 2023-07-19 thomas echo 'foo' >> $testroot/stdout.expected
256 3795e2b6 2023-07-19 thomas echo 'gamma/' >> $testroot/stdout.expected
257 3795e2b6 2023-07-19 thomas
258 3795e2b6 2023-07-19 thomas (cd "$wt" && got up -c:base:-4 > $testroot/stdout)
259 3795e2b6 2023-07-19 thomas (cd "$wt" && got tree -c:base:+4 > $testroot/stdout)
260 3795e2b6 2023-07-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
261 3795e2b6 2023-07-19 thomas ret=$?
262 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
263 3795e2b6 2023-07-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
264 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
265 3795e2b6 2023-07-19 thomas return 1
266 3795e2b6 2023-07-19 thomas fi
267 3795e2b6 2023-07-19 thomas
268 3795e2b6 2023-07-19 thomas test_done "$testroot" "0"
269 3795e2b6 2023-07-19 thomas }
270 3795e2b6 2023-07-19 thomas
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 3795e2b6 2023-07-19 thomas run_test test_tree_commit_keywords