Blame


1 b3d68e7f 2021-07-03 stsp #!/bin/sh
2 b3d68e7f 2021-07-03 stsp #
3 b3d68e7f 2021-07-03 stsp # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 b3d68e7f 2021-07-03 stsp #
5 b3d68e7f 2021-07-03 stsp # Permission to use, copy, modify, and distribute this software for any
6 b3d68e7f 2021-07-03 stsp # purpose with or without fee is hereby granted, provided that the above
7 b3d68e7f 2021-07-03 stsp # copyright notice and this permission notice appear in all copies.
8 b3d68e7f 2021-07-03 stsp #
9 b3d68e7f 2021-07-03 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 b3d68e7f 2021-07-03 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 b3d68e7f 2021-07-03 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 b3d68e7f 2021-07-03 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 b3d68e7f 2021-07-03 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 b3d68e7f 2021-07-03 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 b3d68e7f 2021-07-03 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 b3d68e7f 2021-07-03 stsp
17 b3d68e7f 2021-07-03 stsp . ./common.sh
18 b3d68e7f 2021-07-03 stsp
19 c294a758 2021-07-04 stsp # disable automatic packing for these tests
20 c294a758 2021-07-04 stsp export GOT_TEST_PACK=""
21 c294a758 2021-07-04 stsp
22 b3d68e7f 2021-07-03 stsp test_cleanup_unreferenced_loose_objects() {
23 b3d68e7f 2021-07-03 stsp local testroot=`test_init cleanup_unreferenced_loose_objects`
24 b3d68e7f 2021-07-03 stsp
25 b3d68e7f 2021-07-03 stsp nloose0=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
26 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
27 b3d68e7f 2021-07-03 stsp if [ "$nloose0" != "8" ]; then
28 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose0" >&2
29 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
30 b3d68e7f 2021-07-03 stsp return 1
31 b3d68e7f 2021-07-03 stsp fi
32 b3d68e7f 2021-07-03 stsp
33 b3d68e7f 2021-07-03 stsp # create a branch with some changes
34 b3d68e7f 2021-07-03 stsp got branch -r $testroot/repo newbranch >/dev/null
35 b3d68e7f 2021-07-03 stsp
36 b3d68e7f 2021-07-03 stsp got checkout -b newbranch $testroot/repo $testroot/wt >/dev/null
37 b3d68e7f 2021-07-03 stsp ret="$?"
38 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
39 b3d68e7f 2021-07-03 stsp echo "got checkout command failed unexpectedly"
40 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
41 b3d68e7f 2021-07-03 stsp return 1
42 b3d68e7f 2021-07-03 stsp fi
43 b3d68e7f 2021-07-03 stsp
44 b3d68e7f 2021-07-03 stsp echo 'foo' > $testroot/wt/foo
45 b3d68e7f 2021-07-03 stsp (cd $testroot/wt && got add foo > /dev/null)
46 b3d68e7f 2021-07-03 stsp echo 'modified alpha' > $testroot/wt/alpha
47 b3d68e7f 2021-07-03 stsp (cd $testroot/wt && got commit -m 'newbranch commit' > /dev/null)
48 b3d68e7f 2021-07-03 stsp local commit1=`git_show_branch_head $testroot/repo newbranch`
49 b3d68e7f 2021-07-03 stsp local tree1=`got cat -r $testroot/repo $newbranch_commit | \
50 b3d68e7f 2021-07-03 stsp grep ^tree | cut -d ' ' -f2`
51 b3d68e7f 2021-07-03 stsp local alpha1=`got tree -r $testroot/repo -i -c $commit1 | \
52 b3d68e7f 2021-07-03 stsp grep "[0-9a-f] alpha$" | cut -d' ' -f 1`
53 b3d68e7f 2021-07-03 stsp local foo1=`got tree -r $testroot/repo -i -c $commit1 | \
54 b3d68e7f 2021-07-03 stsp grep "[0-9a-f] foo$" | cut -d' ' -f 1`
55 b3d68e7f 2021-07-03 stsp
56 b3d68e7f 2021-07-03 stsp nloose1=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
57 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
58 b3d68e7f 2021-07-03 stsp if [ "$nloose1" != "12" ]; then
59 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose1" >&2
60 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
61 b3d68e7f 2021-07-03 stsp return 1
62 b3d68e7f 2021-07-03 stsp fi
63 b3d68e7f 2021-07-03 stsp
64 b3d68e7f 2021-07-03 stsp # delete the branch
65 b3d68e7f 2021-07-03 stsp got branch -r $testroot/repo -d newbranch >/dev/null
66 b3d68e7f 2021-07-03 stsp
67 b3d68e7f 2021-07-03 stsp # remove worktree's base commit reference, which points at the branch
68 b3d68e7f 2021-07-03 stsp wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
69 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' ')`
70 b3d68e7f 2021-07-03 stsp got ref -r $testroot/repo -d "refs/got/worktree/base-$wt_uuid"
71 b3d68e7f 2021-07-03 stsp
72 b3d68e7f 2021-07-03 stsp # cleanup -n should not remove any objects
73 88ba8483 2021-07-03 stsp ls -R $testroot/repo/.git/objects > $testroot/objects-before
74 b3d68e7f 2021-07-03 stsp gotadmin cleanup -n -q -r $testroot/repo > $testroot/stdout
75 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
76 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
77 b3d68e7f 2021-07-03 stsp ret="$?"
78 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
79 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
80 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
81 b3d68e7f 2021-07-03 stsp return 1
82 b3d68e7f 2021-07-03 stsp fi
83 88ba8483 2021-07-03 stsp ls -R $testroot/repo/.git/objects > $testroot/objects-after
84 b3d68e7f 2021-07-03 stsp cmp -s $testroot/objects-before $testroot/objects-after
85 b3d68e7f 2021-07-03 stsp ret="$?"
86 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
87 b3d68e7f 2021-07-03 stsp diff -u $testroot/objects-before $testroot/objects-after
88 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
89 b3d68e7f 2021-07-03 stsp return 1
90 b3d68e7f 2021-07-03 stsp fi
91 b3d68e7f 2021-07-03 stsp
92 b3d68e7f 2021-07-03 stsp # cleanup should remove loose objects that belonged to the branch
93 b3d68e7f 2021-07-03 stsp gotadmin cleanup -q -r $testroot/repo > $testroot/stdout
94 b3d68e7f 2021-07-03 stsp ret="$?"
95 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
96 b3d68e7f 2021-07-03 stsp echo "gotadmin cleanup failed unexpectedly" >&2
97 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
98 b3d68e7f 2021-07-03 stsp return 1
99 b3d68e7f 2021-07-03 stsp fi
100 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
101 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
102 b3d68e7f 2021-07-03 stsp ret="$?"
103 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
104 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
105 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
106 b3d68e7f 2021-07-03 stsp return 1
107 b3d68e7f 2021-07-03 stsp fi
108 b3d68e7f 2021-07-03 stsp
109 b3d68e7f 2021-07-03 stsp nloose2=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
110 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
111 b3d68e7f 2021-07-03 stsp if [ "$nloose2" != "$nloose0" ]; then
112 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose2" >&2
113 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
114 b3d68e7f 2021-07-03 stsp return 1
115 b3d68e7f 2021-07-03 stsp fi
116 b3d68e7f 2021-07-03 stsp
117 b3d68e7f 2021-07-03 stsp for id in $commit1 $tree1 $alpha1 $foo1; do
118 b3d68e7f 2021-07-03 stsp path=`get_loose_object_path $testroot/repo $id`
119 b3d68e7f 2021-07-03 stsp if [ -e "$path" ]; then
120 b3d68e7f 2021-07-03 stsp echo "loose object $path was not purged" >&2
121 b3d68e7f 2021-07-03 stsp ret=1
122 b3d68e7f 2021-07-03 stsp break
123 b3d68e7f 2021-07-03 stsp fi
124 b3d68e7f 2021-07-03 stsp done
125 b3d68e7f 2021-07-03 stsp
126 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
127 b3d68e7f 2021-07-03 stsp }
128 b3d68e7f 2021-07-03 stsp
129 b3d68e7f 2021-07-03 stsp test_cleanup_redundant_loose_objects() {
130 b3d68e7f 2021-07-03 stsp local testroot=`test_init cleanup_redundant_loose_objects`
131 b3d68e7f 2021-07-03 stsp
132 b3d68e7f 2021-07-03 stsp # tags should also be packed
133 b3d68e7f 2021-07-03 stsp got tag -r $testroot/repo -m 1.0 1.0 >/dev/null
134 b3d68e7f 2021-07-03 stsp
135 b3d68e7f 2021-07-03 stsp nloose0=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
136 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
137 b3d68e7f 2021-07-03 stsp if [ "$nloose0" != "9" ]; then
138 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose0" >&2
139 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
140 b3d68e7f 2021-07-03 stsp return 1
141 b3d68e7f 2021-07-03 stsp fi
142 b3d68e7f 2021-07-03 stsp
143 b3d68e7f 2021-07-03 stsp # no pack files should exist yet
144 b3d68e7f 2021-07-03 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
145 b3d68e7f 2021-07-03 stsp ret="$?"
146 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
147 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
148 b3d68e7f 2021-07-03 stsp return 1
149 b3d68e7f 2021-07-03 stsp fi
150 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
151 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
152 b3d68e7f 2021-07-03 stsp ret="$?"
153 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
154 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
155 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
156 b3d68e7f 2021-07-03 stsp return 1
157 b3d68e7f 2021-07-03 stsp fi
158 b3d68e7f 2021-07-03 stsp
159 b3d68e7f 2021-07-03 stsp gotadmin pack -r $testroot/repo > /dev/null
160 b3d68e7f 2021-07-03 stsp
161 b3d68e7f 2021-07-03 stsp npacked0=`gotadmin info -r $testroot/repo | grep '^packed objects:' | \
162 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
163 b3d68e7f 2021-07-03 stsp if [ "$npacked0" != "9" ]; then
164 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $npacked0" >&2
165 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
166 b3d68e7f 2021-07-03 stsp return 1
167 b3d68e7f 2021-07-03 stsp fi
168 b3d68e7f 2021-07-03 stsp
169 b3d68e7f 2021-07-03 stsp # cleanup -n should not remove any objects
170 88ba8483 2021-07-03 stsp ls -R $testroot/repo/.git/objects > $testroot/objects-before
171 b3d68e7f 2021-07-03 stsp gotadmin cleanup -n -q -r $testroot/repo > $testroot/stdout
172 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
173 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
174 b3d68e7f 2021-07-03 stsp ret="$?"
175 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
176 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
177 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
178 b3d68e7f 2021-07-03 stsp return 1
179 b3d68e7f 2021-07-03 stsp fi
180 88ba8483 2021-07-03 stsp ls -R $testroot/repo/.git/objects > $testroot/objects-after
181 b3d68e7f 2021-07-03 stsp cmp -s $testroot/objects-before $testroot/objects-after
182 b3d68e7f 2021-07-03 stsp ret="$?"
183 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
184 b3d68e7f 2021-07-03 stsp diff -u $testroot/objects-before $testroot/objects-after
185 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
186 b3d68e7f 2021-07-03 stsp return 1
187 b3d68e7f 2021-07-03 stsp fi
188 b3d68e7f 2021-07-03 stsp
189 b3d68e7f 2021-07-03 stsp nloose1=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
190 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
191 b3d68e7f 2021-07-03 stsp if [ "$nloose1" != "$nloose0" ]; then
192 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose1" >&2
193 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
194 b3d68e7f 2021-07-03 stsp return 1
195 b3d68e7f 2021-07-03 stsp fi
196 b3d68e7f 2021-07-03 stsp
197 b3d68e7f 2021-07-03 stsp # cleanup should remove all loose objects
198 b3d68e7f 2021-07-03 stsp gotadmin cleanup -q -r $testroot/repo > $testroot/stdout
199 b3d68e7f 2021-07-03 stsp ret="$?"
200 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
201 b3d68e7f 2021-07-03 stsp echo "gotadmin cleanup failed unexpectedly" >&2
202 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
203 b3d68e7f 2021-07-03 stsp return 1
204 b3d68e7f 2021-07-03 stsp fi
205 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
206 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
207 b3d68e7f 2021-07-03 stsp ret="$?"
208 b3d68e7f 2021-07-03 stsp if [ "$ret" != "0" ]; then
209 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
210 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
211 b3d68e7f 2021-07-03 stsp return 1
212 b3d68e7f 2021-07-03 stsp fi
213 b3d68e7f 2021-07-03 stsp
214 b3d68e7f 2021-07-03 stsp nloose2=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
215 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
216 b3d68e7f 2021-07-03 stsp if [ "$nloose2" != "0" ]; then
217 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose2" >&2
218 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
219 b3d68e7f 2021-07-03 stsp return 1
220 b3d68e7f 2021-07-03 stsp fi
221 b3d68e7f 2021-07-03 stsp
222 b3d68e7f 2021-07-03 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
223 b3d68e7f 2021-07-03 stsp id0=`basename $d`
224 b3d68e7f 2021-07-03 stsp ret=0
225 b3d68e7f 2021-07-03 stsp for e in `ls $d`; do
226 b3d68e7f 2021-07-03 stsp obj_id=${id0}${e}
227 b3d68e7f 2021-07-03 stsp echo "loose object $obj_id was not purged" >&2
228 b3d68e7f 2021-07-03 stsp ret=1
229 b3d68e7f 2021-07-03 stsp break
230 b3d68e7f 2021-07-03 stsp done
231 854ca8a0 2021-07-03 stsp if [ "$ret" = "1" ]; then
232 b3d68e7f 2021-07-03 stsp break
233 b3d68e7f 2021-07-03 stsp fi
234 b3d68e7f 2021-07-03 stsp done
235 b3d68e7f 2021-07-03 stsp
236 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
237 b3d68e7f 2021-07-03 stsp }
238 b3d68e7f 2021-07-03 stsp
239 9188bd78 2021-07-03 stsp test_cleanup_precious_objects() {
240 9188bd78 2021-07-03 stsp local testroot=`test_init cleanup_precious_objects`
241 9188bd78 2021-07-03 stsp
242 9188bd78 2021-07-03 stsp # enable Git's preciousObjects extension
243 9188bd78 2021-07-03 stsp (cd $testroot/repo && git config extensions.preciousObjects true)
244 9188bd78 2021-07-03 stsp
245 9188bd78 2021-07-03 stsp # cleanup should now refuse to purge objects
246 9188bd78 2021-07-03 stsp gotadmin cleanup -q -r $testroot/repo > $testroot/stdout \
247 9188bd78 2021-07-03 stsp 2> $testroot/stderr
248 9188bd78 2021-07-03 stsp ret="$?"
249 9188bd78 2021-07-03 stsp if [ "$ret" == "0" ]; then
250 9188bd78 2021-07-03 stsp echo "gotadmin cleanup succeeded unexpectedly" >&2
251 9188bd78 2021-07-03 stsp test_done "$testroot" "1"
252 9188bd78 2021-07-03 stsp return 1
253 9188bd78 2021-07-03 stsp fi
254 9188bd78 2021-07-03 stsp
255 9188bd78 2021-07-03 stsp echo -n "gotadmin: the preciousObjects Git extension is enabled; " \
256 9188bd78 2021-07-03 stsp > $testroot/stderr.expected
257 9188bd78 2021-07-03 stsp echo "this implies that objects must not be deleted" \
258 1124fe40 2021-07-07 stsp >> $testroot/stderr.expected
259 1124fe40 2021-07-07 stsp cmp -s $testroot/stderr.expected $testroot/stderr
260 1124fe40 2021-07-07 stsp ret="$?"
261 1124fe40 2021-07-07 stsp if [ "$ret" != "0" ]; then
262 1124fe40 2021-07-07 stsp diff -u $testroot/stderr.expected $testroot/stderr
263 1124fe40 2021-07-07 stsp fi
264 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
265 1124fe40 2021-07-07 stsp }
266 1124fe40 2021-07-07 stsp
267 1124fe40 2021-07-07 stsp test_cleanup_missing_pack_file() {
268 1124fe40 2021-07-07 stsp local testroot=`test_init cleanup_missing_pack_file`
269 1124fe40 2021-07-07 stsp
270 1124fe40 2021-07-07 stsp # no pack files should exist yet
271 1124fe40 2021-07-07 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
272 1124fe40 2021-07-07 stsp ret="$?"
273 1124fe40 2021-07-07 stsp if [ "$ret" != "0" ]; then
274 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
275 1124fe40 2021-07-07 stsp return 1
276 1124fe40 2021-07-07 stsp fi
277 1124fe40 2021-07-07 stsp echo -n > $testroot/stdout.expected
278 1124fe40 2021-07-07 stsp cmp -s $testroot/stdout.expected $testroot/stdout
279 1124fe40 2021-07-07 stsp ret="$?"
280 1124fe40 2021-07-07 stsp if [ "$ret" != "0" ]; then
281 1124fe40 2021-07-07 stsp diff -u $testroot/stdout.expected $testroot/stdout
282 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
283 1124fe40 2021-07-07 stsp return 1
284 1124fe40 2021-07-07 stsp fi
285 1124fe40 2021-07-07 stsp
286 1124fe40 2021-07-07 stsp gotadmin pack -r $testroot/repo > $testroot/stdout
287 1124fe40 2021-07-07 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
288 1124fe40 2021-07-07 stsp packhash=`echo $packname | sed -e 's:^objects/pack/pack-::' \
289 1124fe40 2021-07-07 stsp -e 's/.pack$//'`
290 1124fe40 2021-07-07 stsp
291 1124fe40 2021-07-07 stsp # Some freshly cloned Git repositories suffer from lonely pack index
292 1124fe40 2021-07-07 stsp # files. Remove the pack file we just wrote to simulate this issue.
293 1124fe40 2021-07-07 stsp rm $testroot/repo/.git/objects/pack/pack-$packname
294 1124fe40 2021-07-07 stsp
295 1124fe40 2021-07-07 stsp # cleanup should now refuse to purge objects
296 1124fe40 2021-07-07 stsp gotadmin cleanup -q -r $testroot/repo > $testroot/stdout \
297 1124fe40 2021-07-07 stsp 2> $testroot/stderr
298 1124fe40 2021-07-07 stsp ret="$?"
299 1124fe40 2021-07-07 stsp if [ "$ret" == "0" ]; then
300 1124fe40 2021-07-07 stsp echo "gotadmin cleanup succeeded unexpectedly" >&2
301 1124fe40 2021-07-07 stsp test_done "$testroot" "1"
302 1124fe40 2021-07-07 stsp return 1
303 1124fe40 2021-07-07 stsp fi
304 1124fe40 2021-07-07 stsp
305 1124fe40 2021-07-07 stsp echo -n "gotadmin: objects/pack/pack-${packhash}.idx: " \
306 1124fe40 2021-07-07 stsp > $testroot/stderr.expected
307 1124fe40 2021-07-07 stsp echo "pack index has no corresponding pack file" \
308 9188bd78 2021-07-03 stsp >> $testroot/stderr.expected
309 9188bd78 2021-07-03 stsp cmp -s $testroot/stderr.expected $testroot/stderr
310 9188bd78 2021-07-03 stsp ret="$?"
311 9188bd78 2021-07-03 stsp if [ "$ret" != "0" ]; then
312 9188bd78 2021-07-03 stsp diff -u $testroot/stderr.expected $testroot/stderr
313 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
314 1124fe40 2021-07-07 stsp return 1
315 9188bd78 2021-07-03 stsp fi
316 1124fe40 2021-07-07 stsp
317 1124fe40 2021-07-07 stsp gotadmin cleanup -r $testroot/repo -p -n > $testroot/stdout
318 1124fe40 2021-07-07 stsp ret="$?"
319 1124fe40 2021-07-07 stsp if [ "$ret" != "0" ]; then
320 1124fe40 2021-07-07 stsp echo "gotadmin cleanup failed unexpectedly" >&2
321 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
322 1124fe40 2021-07-07 stsp return 1
323 1124fe40 2021-07-07 stsp fi
324 1124fe40 2021-07-07 stsp packidx_path=$testroot/repo/.git/objects/pack/pack-${packhash}.idx
325 1124fe40 2021-07-07 stsp echo "$packidx_path could be removed" > $testroot/stdout.expected
326 1124fe40 2021-07-07 stsp cmp -s $testroot/stdout.expected $testroot/stdout
327 1124fe40 2021-07-07 stsp ret="$?"
328 1124fe40 2021-07-07 stsp if [ "$ret" != "0" ]; then
329 1124fe40 2021-07-07 stsp diff -u $testroot/stdout.expected $testroot/stdout
330 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
331 1124fe40 2021-07-07 stsp return 1
332 1124fe40 2021-07-07 stsp fi
333 1124fe40 2021-07-07 stsp
334 1124fe40 2021-07-07 stsp gotadmin cleanup -r $testroot/repo -p > $testroot/stdout
335 1124fe40 2021-07-07 stsp ret="$?"
336 1124fe40 2021-07-07 stsp if [ "$ret" != "0" ]; then
337 1124fe40 2021-07-07 stsp echo "gotadmin cleanup failed unexpectedly" >&2
338 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
339 1124fe40 2021-07-07 stsp return 1
340 1124fe40 2021-07-07 stsp fi
341 1124fe40 2021-07-07 stsp echo "$packidx_path removed" > $testroot/stdout.expected
342 1124fe40 2021-07-07 stsp cmp -s $testroot/stdout.expected $testroot/stdout
343 1124fe40 2021-07-07 stsp ret="$?"
344 1124fe40 2021-07-07 stsp if [ "$ret" != "0" ]; then
345 1124fe40 2021-07-07 stsp diff -u $testroot/stdout.expected $testroot/stdout
346 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
347 1124fe40 2021-07-07 stsp return 1
348 1124fe40 2021-07-07 stsp fi
349 1124fe40 2021-07-07 stsp
350 1124fe40 2021-07-07 stsp # cleanup should now attempt to purge objects
351 1124fe40 2021-07-07 stsp gotadmin cleanup -q -r $testroot/repo > $testroot/stdout \
352 1124fe40 2021-07-07 stsp 2> $testroot/stderr
353 1124fe40 2021-07-07 stsp ret="$?"
354 1124fe40 2021-07-07 stsp if [ "$ret" != "0" ]; then
355 1124fe40 2021-07-07 stsp echo "gotadmin cleanup failed unexpectedly" >&2
356 1124fe40 2021-07-07 stsp test_done "$testroot" "1"
357 1124fe40 2021-07-07 stsp return 1
358 1124fe40 2021-07-07 stsp fi
359 9188bd78 2021-07-03 stsp test_done "$testroot" "$ret"
360 9188bd78 2021-07-03 stsp }
361 9188bd78 2021-07-03 stsp
362 b3d68e7f 2021-07-03 stsp test_parseargs "$@"
363 b3d68e7f 2021-07-03 stsp run_test test_cleanup_unreferenced_loose_objects
364 b3d68e7f 2021-07-03 stsp run_test test_cleanup_redundant_loose_objects
365 9188bd78 2021-07-03 stsp run_test test_cleanup_precious_objects
366 1124fe40 2021-07-07 stsp run_test test_cleanup_missing_pack_file