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 fc414659 2022-04-16 thomas ret=$?
38 fc414659 2022-04-16 thomas if [ $ret -ne 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 993f033b 2021-07-16 stsp got ref -r $testroot/repo -d "refs/got/worktree/base-$wt_uuid" \
71 993f033b 2021-07-16 stsp > /dev/null
72 b3d68e7f 2021-07-03 stsp
73 b3d68e7f 2021-07-03 stsp # cleanup -n should not remove any objects
74 88ba8483 2021-07-03 stsp ls -R $testroot/repo/.git/objects > $testroot/objects-before
75 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -n -q -r $testroot/repo > $testroot/stdout
76 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
77 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
78 fc414659 2022-04-16 thomas ret=$?
79 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
80 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
81 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
82 b3d68e7f 2021-07-03 stsp return 1
83 b3d68e7f 2021-07-03 stsp fi
84 88ba8483 2021-07-03 stsp ls -R $testroot/repo/.git/objects > $testroot/objects-after
85 b3d68e7f 2021-07-03 stsp cmp -s $testroot/objects-before $testroot/objects-after
86 fc414659 2022-04-16 thomas ret=$?
87 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
88 b3d68e7f 2021-07-03 stsp diff -u $testroot/objects-before $testroot/objects-after
89 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
90 b3d68e7f 2021-07-03 stsp return 1
91 b3d68e7f 2021-07-03 stsp fi
92 b3d68e7f 2021-07-03 stsp
93 b3d68e7f 2021-07-03 stsp # cleanup should remove loose objects that belonged to the branch
94 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -q -r $testroot/repo > $testroot/stdout
95 fc414659 2022-04-16 thomas ret=$?
96 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
97 b3d68e7f 2021-07-03 stsp echo "gotadmin cleanup failed unexpectedly" >&2
98 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
99 b3d68e7f 2021-07-03 stsp return 1
100 b3d68e7f 2021-07-03 stsp fi
101 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
102 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
103 fc414659 2022-04-16 thomas ret=$?
104 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
105 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
106 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
107 b3d68e7f 2021-07-03 stsp return 1
108 b3d68e7f 2021-07-03 stsp fi
109 b3d68e7f 2021-07-03 stsp
110 b3d68e7f 2021-07-03 stsp nloose2=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
111 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
112 b3d68e7f 2021-07-03 stsp if [ "$nloose2" != "$nloose0" ]; then
113 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose2" >&2
114 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
115 b3d68e7f 2021-07-03 stsp return 1
116 b3d68e7f 2021-07-03 stsp fi
117 b3d68e7f 2021-07-03 stsp
118 b3d68e7f 2021-07-03 stsp for id in $commit1 $tree1 $alpha1 $foo1; do
119 b3d68e7f 2021-07-03 stsp path=`get_loose_object_path $testroot/repo $id`
120 b3d68e7f 2021-07-03 stsp if [ -e "$path" ]; then
121 b3d68e7f 2021-07-03 stsp echo "loose object $path was not purged" >&2
122 b3d68e7f 2021-07-03 stsp ret=1
123 b3d68e7f 2021-07-03 stsp break
124 b3d68e7f 2021-07-03 stsp fi
125 b3d68e7f 2021-07-03 stsp done
126 b3d68e7f 2021-07-03 stsp
127 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
128 b3d68e7f 2021-07-03 stsp }
129 b3d68e7f 2021-07-03 stsp
130 b3d68e7f 2021-07-03 stsp test_cleanup_redundant_loose_objects() {
131 b3d68e7f 2021-07-03 stsp local testroot=`test_init cleanup_redundant_loose_objects`
132 b3d68e7f 2021-07-03 stsp
133 b3d68e7f 2021-07-03 stsp # tags should also be packed
134 b3d68e7f 2021-07-03 stsp got tag -r $testroot/repo -m 1.0 1.0 >/dev/null
135 b3d68e7f 2021-07-03 stsp
136 b3d68e7f 2021-07-03 stsp nloose0=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
137 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
138 b3d68e7f 2021-07-03 stsp if [ "$nloose0" != "9" ]; then
139 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose0" >&2
140 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
141 b3d68e7f 2021-07-03 stsp return 1
142 b3d68e7f 2021-07-03 stsp fi
143 b3d68e7f 2021-07-03 stsp
144 b3d68e7f 2021-07-03 stsp # no pack files should exist yet
145 b3d68e7f 2021-07-03 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
146 fc414659 2022-04-16 thomas ret=$?
147 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
148 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
149 b3d68e7f 2021-07-03 stsp return 1
150 b3d68e7f 2021-07-03 stsp fi
151 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
152 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
153 fc414659 2022-04-16 thomas ret=$?
154 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
155 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
156 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
157 b3d68e7f 2021-07-03 stsp return 1
158 b3d68e7f 2021-07-03 stsp fi
159 b3d68e7f 2021-07-03 stsp
160 b3d68e7f 2021-07-03 stsp gotadmin pack -r $testroot/repo > /dev/null
161 b3d68e7f 2021-07-03 stsp
162 b3d68e7f 2021-07-03 stsp npacked0=`gotadmin info -r $testroot/repo | grep '^packed objects:' | \
163 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
164 b3d68e7f 2021-07-03 stsp if [ "$npacked0" != "9" ]; then
165 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $npacked0" >&2
166 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
167 b3d68e7f 2021-07-03 stsp return 1
168 b3d68e7f 2021-07-03 stsp fi
169 b3d68e7f 2021-07-03 stsp
170 b3d68e7f 2021-07-03 stsp # cleanup -n should not remove any objects
171 88ba8483 2021-07-03 stsp ls -R $testroot/repo/.git/objects > $testroot/objects-before
172 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -n -q -r $testroot/repo > $testroot/stdout
173 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
174 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
175 fc414659 2022-04-16 thomas ret=$?
176 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
177 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
178 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
179 b3d68e7f 2021-07-03 stsp return 1
180 b3d68e7f 2021-07-03 stsp fi
181 88ba8483 2021-07-03 stsp ls -R $testroot/repo/.git/objects > $testroot/objects-after
182 b3d68e7f 2021-07-03 stsp cmp -s $testroot/objects-before $testroot/objects-after
183 fc414659 2022-04-16 thomas ret=$?
184 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
185 b3d68e7f 2021-07-03 stsp diff -u $testroot/objects-before $testroot/objects-after
186 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
187 b3d68e7f 2021-07-03 stsp return 1
188 b3d68e7f 2021-07-03 stsp fi
189 b3d68e7f 2021-07-03 stsp
190 b3d68e7f 2021-07-03 stsp nloose1=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
191 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
192 b3d68e7f 2021-07-03 stsp if [ "$nloose1" != "$nloose0" ]; then
193 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose1" >&2
194 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
195 b3d68e7f 2021-07-03 stsp return 1
196 b3d68e7f 2021-07-03 stsp fi
197 b3d68e7f 2021-07-03 stsp
198 b3d68e7f 2021-07-03 stsp # cleanup should remove all loose objects
199 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -q -r $testroot/repo > $testroot/stdout
200 fc414659 2022-04-16 thomas ret=$?
201 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
202 b3d68e7f 2021-07-03 stsp echo "gotadmin cleanup failed unexpectedly" >&2
203 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
204 b3d68e7f 2021-07-03 stsp return 1
205 b3d68e7f 2021-07-03 stsp fi
206 b3d68e7f 2021-07-03 stsp echo -n > $testroot/stdout.expected
207 b3d68e7f 2021-07-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
208 fc414659 2022-04-16 thomas ret=$?
209 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
210 b3d68e7f 2021-07-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
211 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
212 b3d68e7f 2021-07-03 stsp return 1
213 b3d68e7f 2021-07-03 stsp fi
214 b3d68e7f 2021-07-03 stsp
215 b3d68e7f 2021-07-03 stsp nloose2=`gotadmin info -r $testroot/repo | grep '^loose objects:' | \
216 b3d68e7f 2021-07-03 stsp cut -d ':' -f 2 | tr -d ' '`
217 b3d68e7f 2021-07-03 stsp if [ "$nloose2" != "0" ]; then
218 b3d68e7f 2021-07-03 stsp echo "unexpected number of loose objects: $nloose2" >&2
219 b3d68e7f 2021-07-03 stsp test_done "$testroot" "1"
220 b3d68e7f 2021-07-03 stsp return 1
221 b3d68e7f 2021-07-03 stsp fi
222 b3d68e7f 2021-07-03 stsp
223 b3d68e7f 2021-07-03 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
224 b3d68e7f 2021-07-03 stsp id0=`basename $d`
225 b3d68e7f 2021-07-03 stsp ret=0
226 b3d68e7f 2021-07-03 stsp for e in `ls $d`; do
227 b3d68e7f 2021-07-03 stsp obj_id=${id0}${e}
228 b3d68e7f 2021-07-03 stsp echo "loose object $obj_id was not purged" >&2
229 b3d68e7f 2021-07-03 stsp ret=1
230 b3d68e7f 2021-07-03 stsp break
231 b3d68e7f 2021-07-03 stsp done
232 fc414659 2022-04-16 thomas if [ $ret -eq 1 ]; then
233 b3d68e7f 2021-07-03 stsp break
234 b3d68e7f 2021-07-03 stsp fi
235 b3d68e7f 2021-07-03 stsp done
236 b3d68e7f 2021-07-03 stsp
237 b3d68e7f 2021-07-03 stsp test_done "$testroot" "$ret"
238 b3d68e7f 2021-07-03 stsp }
239 afd0da38 2023-06-22 thomas
240 afd0da38 2023-06-22 thomas test_cleanup_redundant_pack_files() {
241 afd0da38 2023-06-22 thomas local testroot=`test_init cleanup_redundant_pack_files`
242 afd0da38 2023-06-22 thomas
243 afd0da38 2023-06-22 thomas # no pack files should exist yet
244 afd0da38 2023-06-22 thomas
245 afd0da38 2023-06-22 thomas n=$(gotadmin info -r "$testroot/repo" | awk '/^pack files/{print $3}')
246 afd0da38 2023-06-22 thomas if [ "$n" -ne 0 ]; then
247 afd0da38 2023-06-22 thomas echo "expected no pack file to exists, $n found" >&2
248 afd0da38 2023-06-22 thomas test_done "$testroot" 1
249 afd0da38 2023-06-22 thomas return 1
250 afd0da38 2023-06-22 thomas fi
251 afd0da38 2023-06-22 thomas
252 afd0da38 2023-06-22 thomas # create a redundant pack with an associated .keep file
253 afd0da38 2023-06-22 thomas hash=$(gotadmin pack -a -r "$testroot/repo" \
254 afd0da38 2023-06-22 thomas | awk '/^Indexed/{print $2}')
255 afd0da38 2023-06-22 thomas kpack="$testroot/repo/.git/objects/pack/pack-$hash"
256 afd0da38 2023-06-22 thomas touch "${kpack%.pack}.keep"
257 afd0da38 2023-06-22 thomas
258 afd0da38 2023-06-22 thomas # create a few pack files with different objects
259 cf85a643 2024-04-09 thomas for i in `seq 5`; do
260 afd0da38 2023-06-22 thomas echo "alpha $i" > $testroot/repo/alpha
261 afd0da38 2023-06-22 thomas git_commit "$testroot/repo" -m "edit #$i"
262 afd0da38 2023-06-22 thomas gotadmin pack -r "$testroot/repo" >/dev/null
263 afd0da38 2023-06-22 thomas done
264 afd0da38 2023-06-22 thomas
265 afd0da38 2023-06-22 thomas # create two packs with all the objects
266 afd0da38 2023-06-22 thomas gotadmin pack -a -r "$testroot/repo" >/dev/null
267 afd0da38 2023-06-22 thomas gotadmin pack -a -r "$testroot/repo" >/dev/null
268 b3d68e7f 2021-07-03 stsp
269 6322ae43 2023-07-11 thomas # create another one with unreachable objects
270 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" checkout -q -b tempbranch
271 6322ae43 2023-07-11 thomas echo "modified alpha on tempbranch" >$testroot/repo/alpha
272 6322ae43 2023-07-11 thomas git_commit "$testroot/repo" -m "edit alpha on tempbranch"
273 6322ae43 2023-07-11 thomas gotadmin pack -a -r "$testroot/repo" >/dev/null
274 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" checkout -q master
275 6322ae43 2023-07-11 thomas (cd "$testroot/repo" && got branch -d tempbranch) >/dev/null
276 afd0da38 2023-06-22 thomas
277 344dbe90 2023-07-11 thomas gotadmin cleanup -a -q -r "$testroot/repo"
278 afd0da38 2023-06-22 thomas n=$(gotadmin info -r "$testroot/repo" | awk '/^pack files/{print $3}')
279 afd0da38 2023-06-22 thomas if [ "$n" -ne 2 ]; then
280 afd0da38 2023-06-22 thomas echo "expected 2 pack files left, $n found instead" >&2
281 afd0da38 2023-06-22 thomas test_done "$testroot" 1
282 afd0da38 2023-06-22 thomas return 1
283 afd0da38 2023-06-22 thomas fi
284 afd0da38 2023-06-22 thomas
285 afd0da38 2023-06-22 thomas if [ ! -f "$kpack" ]; then
286 afd0da38 2023-06-22 thomas echo "$kpack disappeared unexpectedly" >&2
287 afd0da38 2023-06-22 thomas test_done "$testroot" 1
288 afd0da38 2023-06-22 thomas return 1
289 afd0da38 2023-06-22 thomas fi
290 afd0da38 2023-06-22 thomas
291 afd0da38 2023-06-22 thomas if [ ! -f "${kpack%.pack}.keep" ]; then
292 afd0da38 2023-06-22 thomas echo "${kpack%.pack}.keep disappeared unexpectedly" >&2
293 afd0da38 2023-06-22 thomas test_done "$testroot" 1
294 afd0da38 2023-06-22 thomas return 1
295 afd0da38 2023-06-22 thomas fi
296 afd0da38 2023-06-22 thomas
297 afd0da38 2023-06-22 thomas # create one more non-redundant pack
298 cf85a643 2024-04-09 thomas for i in `seq 5`; do
299 afd0da38 2023-06-22 thomas echo "alpha again $i" > $testroot/repo/alpha
300 afd0da38 2023-06-22 thomas git_commit "$testroot/repo" -m "edit $i"
301 afd0da38 2023-06-22 thomas done
302 afd0da38 2023-06-22 thomas gotadmin pack -r "$testroot/repo" >/dev/null
303 afd0da38 2023-06-22 thomas
304 344dbe90 2023-07-11 thomas gotadmin cleanup -a -q -r "$testroot/repo"
305 afd0da38 2023-06-22 thomas
306 afd0da38 2023-06-22 thomas n=$(gotadmin info -r "$testroot/repo" | awk '/^pack files/{print $3}')
307 afd0da38 2023-06-22 thomas if [ "$n" -ne 3 ]; then
308 afd0da38 2023-06-22 thomas echo "expected 3 pack files left, $n found instead" >&2
309 afd0da38 2023-06-22 thomas test_done "$testroot" 1
310 afd0da38 2023-06-22 thomas return 1
311 afd0da38 2023-06-22 thomas fi
312 afd0da38 2023-06-22 thomas
313 afd0da38 2023-06-22 thomas # remove the .keep file
314 afd0da38 2023-06-22 thomas rm "${kpack%.pack}.keep"
315 afd0da38 2023-06-22 thomas
316 afd0da38 2023-06-22 thomas # create some commits on a separate branch
317 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" checkout -q -b newbranch
318 afd0da38 2023-06-22 thomas
319 cf85a643 2024-04-09 thomas for i in `seq 5`; do
320 afd0da38 2023-06-22 thomas echo "alpha $i" > $testroot/repo/alpha
321 afd0da38 2023-06-22 thomas git_commit "$testroot/repo" -m "edit #$i"
322 afd0da38 2023-06-22 thomas gotadmin pack -r "$testroot/repo" >/dev/null
323 afd0da38 2023-06-22 thomas done
324 afd0da38 2023-06-22 thomas
325 afd0da38 2023-06-22 thomas gotadmin pack -a -x master -r "$testroot/repo" >/dev/null
326 afd0da38 2023-06-22 thomas
327 344dbe90 2023-07-11 thomas gotadmin cleanup -a -q -r "$testroot/repo"
328 afd0da38 2023-06-22 thomas n=$(gotadmin info -r "$testroot/repo" | awk '/^pack files/{print $3}')
329 afd0da38 2023-06-22 thomas if [ "$n" -ne 3 ]; then
330 afd0da38 2023-06-22 thomas echo "expected 3 pack files left, $n found instead" >&2
331 afd0da38 2023-06-22 thomas test_done "$testroot" 1
332 afd0da38 2023-06-22 thomas return 1
333 afd0da38 2023-06-22 thomas fi
334 afd0da38 2023-06-22 thomas
335 afd0da38 2023-06-22 thomas test_done "$testroot" 0
336 afd0da38 2023-06-22 thomas }
337 afd0da38 2023-06-22 thomas
338 9188bd78 2021-07-03 stsp test_cleanup_precious_objects() {
339 9188bd78 2021-07-03 stsp local testroot=`test_init cleanup_precious_objects`
340 9188bd78 2021-07-03 stsp
341 9188bd78 2021-07-03 stsp # enable Git's preciousObjects extension
342 d1e03b8c 2023-10-08 thomas git -C $testroot/repo config extensions.preciousObjects true
343 9188bd78 2021-07-03 stsp
344 9188bd78 2021-07-03 stsp # cleanup should now refuse to purge objects
345 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -q -r $testroot/repo > $testroot/stdout \
346 9188bd78 2021-07-03 stsp 2> $testroot/stderr
347 fc414659 2022-04-16 thomas ret=$?
348 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
349 9188bd78 2021-07-03 stsp echo "gotadmin cleanup succeeded unexpectedly" >&2
350 9188bd78 2021-07-03 stsp test_done "$testroot" "1"
351 9188bd78 2021-07-03 stsp return 1
352 9188bd78 2021-07-03 stsp fi
353 9188bd78 2021-07-03 stsp
354 9188bd78 2021-07-03 stsp echo -n "gotadmin: the preciousObjects Git extension is enabled; " \
355 9188bd78 2021-07-03 stsp > $testroot/stderr.expected
356 9188bd78 2021-07-03 stsp echo "this implies that objects must not be deleted" \
357 1124fe40 2021-07-07 stsp >> $testroot/stderr.expected
358 1124fe40 2021-07-07 stsp cmp -s $testroot/stderr.expected $testroot/stderr
359 fc414659 2022-04-16 thomas ret=$?
360 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
361 1124fe40 2021-07-07 stsp diff -u $testroot/stderr.expected $testroot/stderr
362 1124fe40 2021-07-07 stsp fi
363 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
364 1124fe40 2021-07-07 stsp }
365 1124fe40 2021-07-07 stsp
366 1124fe40 2021-07-07 stsp test_cleanup_missing_pack_file() {
367 1124fe40 2021-07-07 stsp local testroot=`test_init cleanup_missing_pack_file`
368 1124fe40 2021-07-07 stsp
369 1124fe40 2021-07-07 stsp # no pack files should exist yet
370 1124fe40 2021-07-07 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
371 fc414659 2022-04-16 thomas ret=$?
372 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
373 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
374 1124fe40 2021-07-07 stsp return 1
375 1124fe40 2021-07-07 stsp fi
376 1124fe40 2021-07-07 stsp echo -n > $testroot/stdout.expected
377 1124fe40 2021-07-07 stsp cmp -s $testroot/stdout.expected $testroot/stdout
378 fc414659 2022-04-16 thomas ret=$?
379 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
380 1124fe40 2021-07-07 stsp diff -u $testroot/stdout.expected $testroot/stdout
381 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
382 1124fe40 2021-07-07 stsp return 1
383 1124fe40 2021-07-07 stsp fi
384 1124fe40 2021-07-07 stsp
385 1124fe40 2021-07-07 stsp gotadmin pack -r $testroot/repo > $testroot/stdout
386 1124fe40 2021-07-07 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
387 ff1048fe 2023-03-05 thomas packhash=`echo $packname | sed -e 's:^objects/pack/pack-::' \
388 1124fe40 2021-07-07 stsp -e 's/.pack$//'`
389 1124fe40 2021-07-07 stsp
390 1124fe40 2021-07-07 stsp # Some freshly cloned Git repositories suffer from lonely pack index
391 1124fe40 2021-07-07 stsp # files. Remove the pack file we just wrote to simulate this issue.
392 3fa67434 2023-02-03 thomas rm -f $testroot/repo/.git/objects/pack/pack-$packname
393 1124fe40 2021-07-07 stsp
394 1124fe40 2021-07-07 stsp # cleanup should now refuse to purge objects
395 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -q -r $testroot/repo > $testroot/stdout \
396 1124fe40 2021-07-07 stsp 2> $testroot/stderr
397 fc414659 2022-04-16 thomas ret=$?
398 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
399 1124fe40 2021-07-07 stsp echo "gotadmin cleanup succeeded unexpectedly" >&2
400 1124fe40 2021-07-07 stsp test_done "$testroot" "1"
401 1124fe40 2021-07-07 stsp return 1
402 1124fe40 2021-07-07 stsp fi
403 1124fe40 2021-07-07 stsp
404 1124fe40 2021-07-07 stsp echo -n "gotadmin: objects/pack/pack-${packhash}.idx: " \
405 1124fe40 2021-07-07 stsp > $testroot/stderr.expected
406 6843859a 2021-07-09 stsp echo -n "pack index has no corresponding pack file; pack file must " \
407 6843859a 2021-07-09 stsp >> $testroot/stderr.expected
408 6843859a 2021-07-09 stsp echo "be restored or 'gotadmin cleanup -p' must be run" \
409 9188bd78 2021-07-03 stsp >> $testroot/stderr.expected
410 9188bd78 2021-07-03 stsp cmp -s $testroot/stderr.expected $testroot/stderr
411 fc414659 2022-04-16 thomas ret=$?
412 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
413 9188bd78 2021-07-03 stsp diff -u $testroot/stderr.expected $testroot/stderr
414 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
415 1124fe40 2021-07-07 stsp return 1
416 9188bd78 2021-07-03 stsp fi
417 1124fe40 2021-07-07 stsp
418 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -r $testroot/repo -p -n > $testroot/stdout
419 fc414659 2022-04-16 thomas ret=$?
420 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
421 1124fe40 2021-07-07 stsp echo "gotadmin cleanup failed unexpectedly" >&2
422 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
423 1124fe40 2021-07-07 stsp return 1
424 1124fe40 2021-07-07 stsp fi
425 1124fe40 2021-07-07 stsp packidx_path=$testroot/repo/.git/objects/pack/pack-${packhash}.idx
426 1124fe40 2021-07-07 stsp echo "$packidx_path could be removed" > $testroot/stdout.expected
427 1124fe40 2021-07-07 stsp cmp -s $testroot/stdout.expected $testroot/stdout
428 fc414659 2022-04-16 thomas ret=$?
429 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
430 1124fe40 2021-07-07 stsp diff -u $testroot/stdout.expected $testroot/stdout
431 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
432 1124fe40 2021-07-07 stsp return 1
433 1124fe40 2021-07-07 stsp fi
434 1124fe40 2021-07-07 stsp
435 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -r $testroot/repo -p > $testroot/stdout
436 fc414659 2022-04-16 thomas ret=$?
437 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
438 1124fe40 2021-07-07 stsp echo "gotadmin cleanup failed unexpectedly" >&2
439 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
440 1124fe40 2021-07-07 stsp return 1
441 1124fe40 2021-07-07 stsp fi
442 1124fe40 2021-07-07 stsp echo "$packidx_path removed" > $testroot/stdout.expected
443 1124fe40 2021-07-07 stsp cmp -s $testroot/stdout.expected $testroot/stdout
444 fc414659 2022-04-16 thomas ret=$?
445 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
446 1124fe40 2021-07-07 stsp diff -u $testroot/stdout.expected $testroot/stdout
447 1124fe40 2021-07-07 stsp test_done "$testroot" "$ret"
448 1124fe40 2021-07-07 stsp return 1
449 1124fe40 2021-07-07 stsp fi
450 1124fe40 2021-07-07 stsp
451 1124fe40 2021-07-07 stsp # cleanup should now attempt to purge objects
452 ef8ec606 2021-07-27 stsp gotadmin cleanup -a -q -r $testroot/repo > $testroot/stdout \
453 1124fe40 2021-07-07 stsp 2> $testroot/stderr
454 fc414659 2022-04-16 thomas ret=$?
455 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
456 1124fe40 2021-07-07 stsp echo "gotadmin cleanup failed unexpectedly" >&2
457 1124fe40 2021-07-07 stsp test_done "$testroot" "1"
458 1124fe40 2021-07-07 stsp return 1
459 1124fe40 2021-07-07 stsp fi
460 9188bd78 2021-07-03 stsp test_done "$testroot" "$ret"
461 9188bd78 2021-07-03 stsp }
462 9188bd78 2021-07-03 stsp
463 b3d68e7f 2021-07-03 stsp test_parseargs "$@"
464 b3d68e7f 2021-07-03 stsp run_test test_cleanup_unreferenced_loose_objects
465 b3d68e7f 2021-07-03 stsp run_test test_cleanup_redundant_loose_objects
466 afd0da38 2023-06-22 thomas run_test test_cleanup_redundant_pack_files
467 9188bd78 2021-07-03 stsp run_test test_cleanup_precious_objects
468 1124fe40 2021-07-07 stsp run_test test_cleanup_missing_pack_file