Blame


1 01073a5d 2019-08-22 stsp #!/bin/sh
2 01073a5d 2019-08-22 stsp #
3 01073a5d 2019-08-22 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 01073a5d 2019-08-22 stsp #
5 01073a5d 2019-08-22 stsp # Permission to use, copy, modify, and distribute this software for any
6 01073a5d 2019-08-22 stsp # purpose with or without fee is hereby granted, provided that the above
7 01073a5d 2019-08-22 stsp # copyright notice and this permission notice appear in all copies.
8 01073a5d 2019-08-22 stsp #
9 01073a5d 2019-08-22 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 01073a5d 2019-08-22 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 01073a5d 2019-08-22 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 01073a5d 2019-08-22 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 01073a5d 2019-08-22 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 01073a5d 2019-08-22 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 01073a5d 2019-08-22 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 01073a5d 2019-08-22 stsp
17 01073a5d 2019-08-22 stsp . ./common.sh
18 01073a5d 2019-08-22 stsp
19 f6cae3ed 2020-09-13 naddy test_cat_basic() {
20 01073a5d 2019-08-22 stsp local testroot=`test_init cat_basic`
21 01073a5d 2019-08-22 stsp local commit_id=`git_show_head $testroot/repo`
22 01073a5d 2019-08-22 stsp local author_time=`git_show_author_time $testroot/repo`
23 d356bf75 2022-02-16 thomas local gmtoff=`date +%z`
24 01073a5d 2019-08-22 stsp local alpha_id=`got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1`
25 01073a5d 2019-08-22 stsp local gamma_id=`got tree -r $testroot/repo -i | grep 'gamma/$' | cut -d' ' -f 1`
26 01073a5d 2019-08-22 stsp local delta_id=`got tree -r $testroot/repo -i gamma | grep 'delta$' | cut -d' ' -f 1`
27 01073a5d 2019-08-22 stsp
28 01073a5d 2019-08-22 stsp # cat blob
29 01073a5d 2019-08-22 stsp echo "alpha" > $testroot/stdout.expected
30 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $alpha_id > $testroot/stdout
31 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
32 fc414659 2022-04-16 thomas ret=$?
33 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
34 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
35 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
36 01073a5d 2019-08-22 stsp return 1
37 01073a5d 2019-08-22 stsp fi
38 01073a5d 2019-08-22 stsp
39 01073a5d 2019-08-22 stsp # cat tree
40 01073a5d 2019-08-22 stsp echo "$delta_id 0100644 delta" > $testroot/stdout.expected
41 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $gamma_id > $testroot/stdout
42 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
43 fc414659 2022-04-16 thomas ret=$?
44 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
45 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
46 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
47 01073a5d 2019-08-22 stsp return 1
48 01073a5d 2019-08-22 stsp fi
49 01073a5d 2019-08-22 stsp
50 01073a5d 2019-08-22 stsp # cat commit
51 8aa93786 2019-08-22 stsp echo -n "tree " > $testroot/stdout.expected
52 01073a5d 2019-08-22 stsp git_show_tree $testroot/repo >> $testroot/stdout.expected
53 01073a5d 2019-08-22 stsp echo >> $testroot/stdout.expected
54 8aa93786 2019-08-22 stsp echo "numparents 0" >> $testroot/stdout.expected
55 d356bf75 2022-02-16 thomas echo "author $GOT_AUTHOR $author_time $gmtoff" >> $testroot/stdout.expected
56 d356bf75 2022-02-16 thomas echo "committer $GOT_AUTHOR $author_time $gmtoff" \
57 896e9b6f 2019-08-26 stsp >> $testroot/stdout.expected
58 8aa93786 2019-08-22 stsp echo "messagelen 22" >> $testroot/stdout.expected
59 01073a5d 2019-08-22 stsp printf "\nadding the test tree\n" >> $testroot/stdout.expected
60 01073a5d 2019-08-22 stsp
61 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $commit_id > $testroot/stdout
62 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
63 fc414659 2022-04-16 thomas ret=$?
64 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
65 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
66 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
67 01073a5d 2019-08-22 stsp return 1
68 01073a5d 2019-08-22 stsp fi
69 01073a5d 2019-08-22 stsp
70 01073a5d 2019-08-22 stsp # TODO: test cat tag
71 01073a5d 2019-08-22 stsp
72 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
73 01073a5d 2019-08-22 stsp }
74 01073a5d 2019-08-22 stsp
75 f6cae3ed 2020-09-13 naddy test_cat_path() {
76 896e9b6f 2019-08-26 stsp local testroot=`test_init cat_path`
77 896e9b6f 2019-08-26 stsp local commit_id=`git_show_head $testroot/repo`
78 896e9b6f 2019-08-26 stsp local author_time=`git_show_author_time $testroot/repo`
79 896e9b6f 2019-08-26 stsp local alpha_id=`got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1`
80 896e9b6f 2019-08-26 stsp local gamma_id=`got tree -r $testroot/repo -i | grep 'gamma/$' | cut -d' ' -f 1`
81 896e9b6f 2019-08-26 stsp local delta_id=`got tree -r $testroot/repo -i gamma | grep 'delta$' | cut -d' ' -f 1`
82 896e9b6f 2019-08-26 stsp
83 896e9b6f 2019-08-26 stsp # cat blob by path
84 896e9b6f 2019-08-26 stsp echo "alpha" > $testroot/stdout.expected
85 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo alpha > $testroot/stdout
86 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
87 fc414659 2022-04-16 thomas ret=$?
88 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
89 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
90 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
91 896e9b6f 2019-08-26 stsp return 1
92 896e9b6f 2019-08-26 stsp fi
93 896e9b6f 2019-08-26 stsp
94 896e9b6f 2019-08-26 stsp # cat tree by path
95 896e9b6f 2019-08-26 stsp echo "$delta_id 0100644 delta" > $testroot/stdout.expected
96 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo gamma > $testroot/stdout
97 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
98 fc414659 2022-04-16 thomas ret=$?
99 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
100 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
101 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
102 896e9b6f 2019-08-26 stsp return 1
103 896e9b6f 2019-08-26 stsp fi
104 896e9b6f 2019-08-26 stsp
105 896e9b6f 2019-08-26 stsp (cd $testroot && got checkout repo wt > /dev/null)
106 896e9b6f 2019-08-26 stsp echo "modified alpha" > $testroot/wt/alpha
107 896e9b6f 2019-08-26 stsp (cd $testroot/wt && got commit -m "changed alpha" > /dev/null)
108 896e9b6f 2019-08-26 stsp local commit_id2=`git_show_head $testroot/repo`
109 896e9b6f 2019-08-26 stsp local author_time2=`git_show_author_time $testroot/repo`
110 896e9b6f 2019-08-26 stsp local tree_commit2=`git_show_tree $testroot/repo`
111 896e9b6f 2019-08-26 stsp
112 896e9b6f 2019-08-26 stsp # cat blob by path in specific commit
113 896e9b6f 2019-08-26 stsp echo "alpha" > $testroot/stdout.expected
114 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo -c $commit_id alpha > $testroot/stdout
115 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
116 fc414659 2022-04-16 thomas ret=$?
117 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
118 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
119 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
120 896e9b6f 2019-08-26 stsp return 1
121 896e9b6f 2019-08-26 stsp fi
122 896e9b6f 2019-08-26 stsp echo "modified alpha" > $testroot/stdout.expected
123 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo -c $commit_id2 alpha > $testroot/stdout
124 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
125 fc414659 2022-04-16 thomas ret=$?
126 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
127 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
128 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
129 896e9b6f 2019-08-26 stsp return 1
130 896e9b6f 2019-08-26 stsp fi
131 896e9b6f 2019-08-26 stsp
132 896e9b6f 2019-08-26 stsp # resolve ambiguities between paths and other arguments
133 896e9b6f 2019-08-26 stsp echo "new file called master" > $testroot/wt/master
134 896e9b6f 2019-08-26 stsp echo "new file called $commit_id2" > $testroot/wt/$commit_id2
135 896e9b6f 2019-08-26 stsp (cd $testroot/wt && got add master $commit_id2 > /dev/null)
136 896e9b6f 2019-08-26 stsp (cd $testroot/wt && got commit -m "added clashing paths" > /dev/null)
137 896e9b6f 2019-08-26 stsp local commit_id3=`git_show_head $testroot/repo`
138 896e9b6f 2019-08-26 stsp local author_time3=`git_show_author_time $testroot/repo`
139 896e9b6f 2019-08-26 stsp
140 896e9b6f 2019-08-26 stsp # references and object IDs override paths:
141 896e9b6f 2019-08-26 stsp echo -n "tree " > $testroot/stdout.expected
142 896e9b6f 2019-08-26 stsp git_show_tree $testroot/repo >> $testroot/stdout.expected
143 896e9b6f 2019-08-26 stsp echo >> $testroot/stdout.expected
144 896e9b6f 2019-08-26 stsp echo "numparents 1" >> $testroot/stdout.expected
145 896e9b6f 2019-08-26 stsp echo "parent $commit_id2" >> $testroot/stdout.expected
146 896e9b6f 2019-08-26 stsp echo "author $GOT_AUTHOR $author_time3 +0000" >> $testroot/stdout.expected
147 896e9b6f 2019-08-26 stsp echo "committer $GOT_AUTHOR $author_time3 +0000" \
148 896e9b6f 2019-08-26 stsp >> $testroot/stdout.expected
149 896e9b6f 2019-08-26 stsp echo "messagelen 22" >> $testroot/stdout.expected
150 896e9b6f 2019-08-26 stsp printf "\nadded clashing paths\n" >> $testroot/stdout.expected
151 896e9b6f 2019-08-26 stsp
152 896e9b6f 2019-08-26 stsp for arg in master $commit_id3; do
153 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo $arg > $testroot/stdout
154 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
155 fc414659 2022-04-16 thomas ret=$?
156 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
157 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
158 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
159 896e9b6f 2019-08-26 stsp return 1
160 896e9b6f 2019-08-26 stsp fi
161 896e9b6f 2019-08-26 stsp done
162 896e9b6f 2019-08-26 stsp
163 896e9b6f 2019-08-26 stsp echo "tree $tree_commit2" > $testroot/stdout.expected
164 896e9b6f 2019-08-26 stsp echo "numparents 1" >> $testroot/stdout.expected
165 896e9b6f 2019-08-26 stsp echo "parent $commit_id" >> $testroot/stdout.expected
166 896e9b6f 2019-08-26 stsp echo "author $GOT_AUTHOR $author_time2 +0000" >> $testroot/stdout.expected
167 896e9b6f 2019-08-26 stsp echo "committer $GOT_AUTHOR $author_time2 +0000" \
168 896e9b6f 2019-08-26 stsp >> $testroot/stdout.expected
169 896e9b6f 2019-08-26 stsp echo "messagelen 15" >> $testroot/stdout.expected
170 896e9b6f 2019-08-26 stsp printf "\nchanged alpha\n" >> $testroot/stdout.expected
171 896e9b6f 2019-08-26 stsp
172 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo $commit_id2 > $testroot/stdout
173 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
174 fc414659 2022-04-16 thomas ret=$?
175 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
176 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
177 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
178 896e9b6f 2019-08-26 stsp return 1
179 896e9b6f 2019-08-26 stsp fi
180 896e9b6f 2019-08-26 stsp
181 896e9b6f 2019-08-26 stsp # force resolution of path 'master'
182 896e9b6f 2019-08-26 stsp echo "new file called master" > $testroot/stdout.expected
183 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo -P master > $testroot/stdout
184 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
185 fc414659 2022-04-16 thomas ret=$?
186 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
187 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
188 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
189 896e9b6f 2019-08-26 stsp return 1
190 896e9b6f 2019-08-26 stsp fi
191 896e9b6f 2019-08-26 stsp
192 896e9b6f 2019-08-26 stsp # force resolution of path "$commit_id2"
193 896e9b6f 2019-08-26 stsp echo "new file called $commit_id2" > $testroot/stdout.expected
194 896e9b6f 2019-08-26 stsp got cat -r $testroot/repo -P $commit_id2 > $testroot/stdout
195 896e9b6f 2019-08-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
196 fc414659 2022-04-16 thomas ret=$?
197 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
198 896e9b6f 2019-08-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
199 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
200 896e9b6f 2019-08-26 stsp return 1
201 896e9b6f 2019-08-26 stsp fi
202 896e9b6f 2019-08-26 stsp test_done "$testroot" "$ret"
203 896e9b6f 2019-08-26 stsp }
204 896e9b6f 2019-08-26 stsp
205 f6cae3ed 2020-09-13 naddy test_cat_submodule() {
206 e7303626 2020-05-14 stsp local testroot=`test_init cat_submodule`
207 e7303626 2020-05-14 stsp
208 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
209 e7303626 2020-05-14 stsp
210 d1e03b8c 2023-10-08 thomas git -C $testroot/repo -c protocol.file.allow=always \
211 d1e03b8c 2023-10-08 thomas submodule -q add ../repo2
212 d1e03b8c 2023-10-08 thomas git -C $testroot/repo commit -q -m 'adding submodule'
213 e7303626 2020-05-14 stsp
214 e7303626 2020-05-14 stsp got cat -r $testroot/repo repo2 > $testroot/stdout \
215 e7303626 2020-05-14 stsp > $testroot/stdout 2> $testroot/stderr
216 fc414659 2022-04-16 thomas ret=$?
217 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
218 e7303626 2020-05-14 stsp echo "cat command succeeded unexpectedly" >&2
219 e7303626 2020-05-14 stsp test_done "$testroot" "1"
220 e7303626 2020-05-14 stsp return 1
221 e7303626 2020-05-14 stsp fi
222 e7303626 2020-05-14 stsp local submodule_id=$(got tree -r $testroot/repo -i | \
223 e7303626 2020-05-14 stsp grep 'repo2\$$' | cut -d ' ' -f1)
224 e7303626 2020-05-14 stsp echo "got: object $submodule_id not found" > $testroot/stderr.expected
225 e7303626 2020-05-14 stsp
226 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
227 fc414659 2022-04-16 thomas ret=$?
228 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
229 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
230 e7303626 2020-05-14 stsp fi
231 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
232 e7303626 2020-05-14 stsp }
233 e7303626 2020-05-14 stsp
234 f6cae3ed 2020-09-13 naddy test_cat_submodule_of_same_repo() {
235 e7303626 2020-05-14 stsp local testroot=`test_init cat_submodule_of_same_repo`
236 e7303626 2020-05-14 stsp local commit_id0=`git_show_head $testroot/repo`
237 e7303626 2020-05-14 stsp local author_time=`git_show_author_time $testroot/repo`
238 d356bf75 2022-02-16 thomas local gmtoff=`date +%z`
239 e7303626 2020-05-14 stsp
240 d1e03b8c 2023-10-08 thomas git -C $testroot clone -q repo repo2 >/dev/null
241 d1e03b8c 2023-10-08 thomas git -C $testroot/repo -c protocol.file.allow=always \
242 d1e03b8c 2023-10-08 thomas submodule -q add ../repo2
243 d1e03b8c 2023-10-08 thomas git -C $testroot/repo commit -q -m 'adding submodule'
244 e7303626 2020-05-14 stsp
245 e7303626 2020-05-14 stsp # 'got cat' shows the commit object which the submodule points to
246 e7303626 2020-05-14 stsp # because a commit with the same ID exists in the outer repository
247 e7303626 2020-05-14 stsp got cat -r $testroot/repo $commit_id0 | grep ^tree > $testroot/stdout.expected
248 e7303626 2020-05-14 stsp echo "numparents 0" >> $testroot/stdout.expected
249 d356bf75 2022-02-16 thomas echo "author $GOT_AUTHOR $author_time $gmtoff" >> $testroot/stdout.expected
250 d356bf75 2022-02-16 thomas echo "committer $GOT_AUTHOR $author_time $gmtoff" \
251 e7303626 2020-05-14 stsp >> $testroot/stdout.expected
252 e7303626 2020-05-14 stsp echo "messagelen 22" >> $testroot/stdout.expected
253 e7303626 2020-05-14 stsp printf "\nadding the test tree\n" >> $testroot/stdout.expected
254 e7303626 2020-05-14 stsp
255 e7303626 2020-05-14 stsp got cat -r $testroot/repo repo2 > $testroot/stdout
256 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
257 fc414659 2022-04-16 thomas ret=$?
258 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
259 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
260 e7303626 2020-05-14 stsp fi
261 e7303626 2020-05-14 stsp
262 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
263 e7303626 2020-05-14 stsp }
264 e7303626 2020-05-14 stsp
265 f6cae3ed 2020-09-13 naddy test_cat_symlink() {
266 73259b37 2020-07-23 stsp local testroot=`test_init cat_symlink`
267 73259b37 2020-07-23 stsp local commit_id=`git_show_head $testroot/repo`
268 73259b37 2020-07-23 stsp local author_time=`git_show_author_time $testroot/repo`
269 73259b37 2020-07-23 stsp
270 73259b37 2020-07-23 stsp (cd $testroot/repo && ln -s alpha alpha.link)
271 73259b37 2020-07-23 stsp (cd $testroot/repo && ln -s epsilon epsilon.link)
272 73259b37 2020-07-23 stsp (cd $testroot/repo && ln -s /etc/passwd passwd.link)
273 73259b37 2020-07-23 stsp (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
274 73259b37 2020-07-23 stsp (cd $testroot/repo && ln -s nonexistent nonexistent.link)
275 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add .
276 73259b37 2020-07-23 stsp git_commit $testroot/repo -m "add symlinks"
277 73259b37 2020-07-23 stsp
278 73259b37 2020-07-23 stsp local alpha_link_id=`got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | cut -d' ' -f 1`
279 73259b37 2020-07-23 stsp local epsilon_link_id=`got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | cut -d' ' -f 1`
280 73259b37 2020-07-23 stsp local passwd_link_id=`got tree -r $testroot/repo -i | grep 'passwd.link@ -> /etc/passwd$' | cut -d' ' -f 1`
281 73259b37 2020-07-23 stsp local epsilon_beta_link_id=`got tree -r $testroot/repo -i epsilon | grep 'beta.link@ -> ../beta$' | cut -d' ' -f 1`
282 73259b37 2020-07-23 stsp local nonexistent_link_id=`got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | cut -d' ' -f 1`
283 73259b37 2020-07-23 stsp
284 73259b37 2020-07-23 stsp # cat symlink to regular file
285 73259b37 2020-07-23 stsp echo -n "alpha" > $testroot/stdout.expected
286 73259b37 2020-07-23 stsp got cat -r $testroot/repo $alpha_link_id > $testroot/stdout
287 73259b37 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
288 fc414659 2022-04-16 thomas ret=$?
289 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
290 73259b37 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
291 73259b37 2020-07-23 stsp test_done "$testroot" "$ret"
292 73259b37 2020-07-23 stsp return 1
293 73259b37 2020-07-23 stsp fi
294 73259b37 2020-07-23 stsp
295 73259b37 2020-07-23 stsp # cat symlink with relative path to regular file
296 73259b37 2020-07-23 stsp echo -n "../beta" > $testroot/stdout.expected
297 73259b37 2020-07-23 stsp got cat -r $testroot/repo $epsilon_beta_link_id > $testroot/stdout
298 73259b37 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
299 fc414659 2022-04-16 thomas ret=$?
300 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
301 73259b37 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
302 73259b37 2020-07-23 stsp test_done "$testroot" "$ret"
303 73259b37 2020-07-23 stsp return 1
304 73259b37 2020-07-23 stsp fi
305 73259b37 2020-07-23 stsp
306 73259b37 2020-07-23 stsp # cat symlink to a tree
307 73259b37 2020-07-23 stsp echo -n "epsilon" > $testroot/stdout.expected
308 73259b37 2020-07-23 stsp got cat -r $testroot/repo $epsilon_link_id > $testroot/stdout
309 73259b37 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
310 fc414659 2022-04-16 thomas ret=$?
311 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
312 73259b37 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
313 73259b37 2020-07-23 stsp test_done "$testroot" "$ret"
314 73259b37 2020-07-23 stsp return 1
315 73259b37 2020-07-23 stsp fi
316 73259b37 2020-07-23 stsp
317 73259b37 2020-07-23 stsp # cat symlink to paths which don't exist in repository
318 73259b37 2020-07-23 stsp echo -n "/etc/passwd" > $testroot/stdout.expected
319 73259b37 2020-07-23 stsp got cat -r $testroot/repo $passwd_link_id > $testroot/stdout
320 73259b37 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
321 fc414659 2022-04-16 thomas ret=$?
322 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
323 73259b37 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
324 73259b37 2020-07-23 stsp test_done "$testroot" "$ret"
325 73259b37 2020-07-23 stsp return 1
326 73259b37 2020-07-23 stsp fi
327 73259b37 2020-07-23 stsp
328 73259b37 2020-07-23 stsp echo -n "nonexistent" > $testroot/stdout.expected
329 73259b37 2020-07-23 stsp got cat -r $testroot/repo $nonexistent_link_id > $testroot/stdout
330 73259b37 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
331 fc414659 2022-04-16 thomas ret=$?
332 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
333 73259b37 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
334 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
335 3795e2b6 2023-07-19 thomas return 1
336 3795e2b6 2023-07-19 thomas fi
337 3795e2b6 2023-07-19 thomas
338 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
339 3795e2b6 2023-07-19 thomas }
340 3795e2b6 2023-07-19 thomas
341 3795e2b6 2023-07-19 thomas test_cat_commit_keywords() {
342 3795e2b6 2023-07-19 thomas local testroot=$(test_init cat_commit_keywords)
343 3795e2b6 2023-07-19 thomas local repo="$testroot/repo"
344 3795e2b6 2023-07-19 thomas local wt="$testroot/wt"
345 3795e2b6 2023-07-19 thomas
346 3795e2b6 2023-07-19 thomas # :base requires work tree
347 3795e2b6 2023-07-19 thomas echo "got: '-c :base' requires work tree" > "$testroot/stderr.expected"
348 3795e2b6 2023-07-19 thomas got cat -r "$repo" -c:base alpha 2> "$testroot/stderr"
349 3795e2b6 2023-07-19 thomas ret=$?
350 3795e2b6 2023-07-19 thomas if [ $ret -eq 0 ]; then
351 3795e2b6 2023-07-19 thomas echo "cat command succeeded unexpectedly" >&2
352 3795e2b6 2023-07-19 thomas test_done "$testroot" "1"
353 3795e2b6 2023-07-19 thomas return 1
354 3795e2b6 2023-07-19 thomas fi
355 3795e2b6 2023-07-19 thomas
356 3795e2b6 2023-07-19 thomas cmp -s "$testroot/stderr.expected" "$testroot/stderr"
357 3795e2b6 2023-07-19 thomas ret=$?
358 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
359 3795e2b6 2023-07-19 thomas diff -u "$testroot/stderr.expected" "$testroot/stderr"
360 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
361 3795e2b6 2023-07-19 thomas return 1
362 3795e2b6 2023-07-19 thomas fi
363 3795e2b6 2023-07-19 thomas
364 3795e2b6 2023-07-19 thomas got checkout "$repo" "$wt" > /dev/null
365 3795e2b6 2023-07-19 thomas ret=$?
366 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
367 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
368 3795e2b6 2023-07-19 thomas return 1
369 3795e2b6 2023-07-19 thomas fi
370 3795e2b6 2023-07-19 thomas
371 3795e2b6 2023-07-19 thomas for i in $(seq 8); do
372 3795e2b6 2023-07-19 thomas echo "change $i" > "$wt/alpha"
373 3795e2b6 2023-07-19 thomas echo "delta $i" > "$wt/gamma/delta"
374 3795e2b6 2023-07-19 thomas
375 3795e2b6 2023-07-19 thomas (cd "$wt" && got ci -m "commit $i" > /dev/null)
376 3795e2b6 2023-07-19 thomas ret=$?
377 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
378 3795e2b6 2023-07-19 thomas echo "commit failed unexpectedly" >&2
379 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
380 3795e2b6 2023-07-19 thomas return 1
381 3795e2b6 2023-07-19 thomas fi
382 3795e2b6 2023-07-19 thomas
383 3795e2b6 2023-07-19 thomas local delta_id=$(got tree -r "$repo" -i gamma | \
384 3795e2b6 2023-07-19 thomas grep 'delta$' | cut -d' ' -f 1)
385 8642913b 2023-07-26 thomas set -- "$@" "$delta_id"
386 3795e2b6 2023-07-19 thomas done
387 3795e2b6 2023-07-19 thomas
388 3795e2b6 2023-07-19 thomas # cat blob by path
389 3795e2b6 2023-07-19 thomas echo "change 6" > "$testroot/stdout.expected"
390 3795e2b6 2023-07-19 thomas (cd "$wt" && got cat -c:head:-2 alpha > "$testroot/stdout")
391 3795e2b6 2023-07-19 thomas cmp -s "$testroot/stdout.expected" "$testroot/stdout"
392 3795e2b6 2023-07-19 thomas ret=$?
393 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
394 3795e2b6 2023-07-19 thomas diff -u "$testroot/stdout.expected" "$testroot/stdout"
395 73259b37 2020-07-23 stsp test_done "$testroot" "$ret"
396 73259b37 2020-07-23 stsp return 1
397 73259b37 2020-07-23 stsp fi
398 73259b37 2020-07-23 stsp
399 3795e2b6 2023-07-19 thomas # cat blob by path with -r repo
400 3795e2b6 2023-07-19 thomas echo "delta 7" > "$testroot/stdout.expected"
401 3795e2b6 2023-07-19 thomas got cat -r "$repo" -c:head:- gamma/delta > "$testroot/stdout"
402 3795e2b6 2023-07-19 thomas cmp -s "$testroot/stdout.expected" "$testroot/stdout"
403 3795e2b6 2023-07-19 thomas ret=$?
404 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
405 3795e2b6 2023-07-19 thomas diff -u "$testroot/stdout.expected" "$testroot/stdout"
406 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
407 3795e2b6 2023-07-19 thomas return 1
408 3795e2b6 2023-07-19 thomas fi
409 3795e2b6 2023-07-19 thomas
410 3795e2b6 2023-07-19 thomas # cat tree by path
411 8642913b 2023-07-26 thomas echo "$(pop_idx 4 $@) 0100644 delta" > \
412 3795e2b6 2023-07-19 thomas "$testroot/stdout.expected"
413 3795e2b6 2023-07-19 thomas (cd "$wt" && got cat -c:base:-4 gamma > "$testroot/stdout")
414 3795e2b6 2023-07-19 thomas cmp -s "$testroot/stdout.expected" "$testroot/stdout"
415 3795e2b6 2023-07-19 thomas ret=$?
416 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
417 3795e2b6 2023-07-19 thomas diff -u "$testroot/stdout.expected" "$testroot/stdout"
418 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
419 3795e2b6 2023-07-19 thomas return 1
420 3795e2b6 2023-07-19 thomas fi
421 3795e2b6 2023-07-19 thomas
422 3795e2b6 2023-07-19 thomas # cat blob by path with -P
423 3795e2b6 2023-07-19 thomas echo "delta 4" > "$testroot/stdout.expected"
424 3795e2b6 2023-07-19 thomas (cd "$wt" && got up -c:base:-8 > /dev/null)
425 3795e2b6 2023-07-19 thomas (cd "$wt" && got cat -c:base:+4 -P gamma/delta > "$testroot/stdout")
426 3795e2b6 2023-07-19 thomas cmp -s "$testroot/stdout.expected" "$testroot/stdout"
427 3795e2b6 2023-07-19 thomas ret=$?
428 3795e2b6 2023-07-19 thomas if [ $ret -ne 0 ]; then
429 3795e2b6 2023-07-19 thomas diff -u "$testroot/stdout.expected" "$testroot/stdout"
430 3795e2b6 2023-07-19 thomas test_done "$testroot" "$ret"
431 3795e2b6 2023-07-19 thomas return 1
432 3795e2b6 2023-07-19 thomas fi
433 3795e2b6 2023-07-19 thomas
434 73259b37 2020-07-23 stsp test_done "$testroot" "$ret"
435 73259b37 2020-07-23 stsp }
436 73259b37 2020-07-23 stsp
437 7fb414ae 2020-08-08 stsp test_parseargs "$@"
438 01073a5d 2019-08-22 stsp run_test test_cat_basic
439 896e9b6f 2019-08-26 stsp run_test test_cat_path
440 e7303626 2020-05-14 stsp run_test test_cat_submodule
441 e7303626 2020-05-14 stsp run_test test_cat_submodule_of_same_repo
442 73259b37 2020-07-23 stsp run_test test_cat_symlink
443 3795e2b6 2023-07-19 thomas run_test test_cat_commit_keywords