3 test_description
='git repack works correctly'
8 test_commit
"$@" 1>&2 &&
9 SHA1
=$
(git pack-objects
--all --unpacked --incremental .git
/objects
/pack
/pack
</dev
/null
) &&
10 echo pack-
${SHA1}.pack
13 test_no_missing_in_packs
() {
14 myidx
=$
(ls -1 .git
/objects
/pack
/*.idx
) &&
15 test_path_is_file
"$myidx" &&
16 git verify-pack
-v alt_objects
/pack
/*.idx
>orig.raw
&&
17 sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw |
sort >orig
&&
18 git verify-pack
-v $myidx >dest.raw
&&
19 cut
-d" " -f1 dest.raw |
sort >dest
&&
20 comm -23 orig dest
>missing
&&
21 test_must_be_empty missing
24 test_expect_success
'objects in packs marked .keep are not repacked' '
25 echo content1 >file1 &&
26 echo content2 >file2 &&
29 git commit -m initial_commit &&
31 # The first pack will contain all of the objects except one
32 git rev-list --objects --all | grep -v file2 |
33 git pack-objects pack &&
34 # The second pack will contain the excluded object
35 packsha1=$(git rev-list --objects --all | grep file2 |
36 git pack-objects pack) &&
37 >pack-$packsha1.keep &&
38 objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 |
39 sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
40 mv pack-* .git/objects/pack/ &&
41 git repack -A -d -l &&
43 for p in .git/objects/pack/*.idx
46 test "pack-$packsha1.idx" = "$idx" && continue
47 if git verify-pack -v $p | egrep "^$objsha1"
49 found_duplicate_object=1
50 echo "DUPLICATE OBJECT FOUND"
54 test -z "$found_duplicate_object"
57 test_expect_success
'writing bitmaps via command-line can duplicate .keep objects' '
58 # build on $objsha1, $packsha1, and .keep state from previous
60 test_when_finished "found_duplicate_object=" &&
61 for p in .git/objects/pack/*.idx
64 test "pack-$packsha1.idx" = "$idx" && continue
65 if git verify-pack -v $p | egrep "^$objsha1"
67 found_duplicate_object=1
68 echo "DUPLICATE OBJECT FOUND"
72 test "$found_duplicate_object" = 1
75 test_expect_success
'writing bitmaps via config can duplicate .keep objects' '
76 # build on $objsha1, $packsha1, and .keep state from previous
77 git -c repack.writebitmaps=true repack -Adl &&
78 test_when_finished "found_duplicate_object=" &&
79 for p in .git/objects/pack/*.idx
82 test "pack-$packsha1.idx" = "$idx" && continue
83 if git verify-pack -v $p | egrep "^$objsha1"
85 found_duplicate_object=1
86 echo "DUPLICATE OBJECT FOUND"
90 test "$found_duplicate_object" = 1
93 test_expect_success
'loose objects in alternate ODB are not repacked' '
95 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
96 echo content3 >file3 &&
97 objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
100 git commit -m commit_file3 &&
101 git repack -a -d -l &&
103 for p in .git/objects/pack/*.idx
105 if git verify-pack -v $p | egrep "^$objsha1"
107 found_duplicate_object=1
108 echo "DUPLICATE OBJECT FOUND"
112 test -z "$found_duplicate_object"
115 test_expect_success
'packed obs in alt ODB are repacked even when local repo is packless' '
116 mkdir alt_objects/pack &&
117 mv .git/objects/pack/* alt_objects/pack &&
119 test_no_missing_in_packs
122 test_expect_success
'packed obs in alt ODB are repacked when local repo has packs' '
123 rm -f .git/objects/pack/* &&
124 echo new_content >>file1 &&
127 git commit -m more_content &&
130 test_no_missing_in_packs
133 test_expect_success
'packed obs in alternate ODB kept pack are repacked' '
134 # swap the .keep so the commit object is in the pack with .keep
135 for p in alt_objects/pack/*.pack
137 base_name=$(basename $p .pack) &&
138 if test_path_is_file alt_objects/pack/$base_name.keep
140 rm alt_objects/pack/$base_name.keep
142 touch alt_objects/pack/$base_name.keep
146 test_no_missing_in_packs
149 test_expect_success
'packed unreachable obs in alternate ODB are not loosened' '
150 rm -f alt_objects/pack/*.keep &&
151 mv .git/objects/pack/* alt_objects/pack/ &&
152 csha1=$(git rev-parse HEAD^{commit}) &&
153 git reset --hard HEAD^ &&
155 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
156 # The pack-objects call on the next line is equivalent to
157 # git repack -A -d without the call to prune-packed
158 git pack-objects --honor-pack-keep --non-empty --all --reflog \
159 --unpack-unreachable </dev/null pack &&
160 rm -f .git/objects/pack/* &&
161 mv pack-* .git/objects/pack/ &&
162 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
163 egrep "^$csha1 " | sort | uniq | wc -l) &&
164 echo >.git/objects/info/alternates &&
165 test_must_fail git show $csha1
168 test_expect_success
'local packed unreachable obs that exist in alternate ODB are not loosened' '
169 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
170 echo "$csha1" | git pack-objects --non-empty --all --reflog pack &&
171 rm -f .git/objects/pack/* &&
172 mv pack-* .git/objects/pack/ &&
173 # The pack-objects call on the next line is equivalent to
174 # git repack -A -d without the call to prune-packed
175 git pack-objects --honor-pack-keep --non-empty --all --reflog \
176 --unpack-unreachable </dev/null pack &&
177 rm -f .git/objects/pack/* &&
178 mv pack-* .git/objects/pack/ &&
179 test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx |
180 egrep "^$csha1 " | sort | uniq | wc -l) &&
181 echo >.git/objects/info/alternates &&
182 test_must_fail git show $csha1
185 test_expect_success
'objects made unreachable by grafts only are kept' '
187 git commit --allow-empty -m "commit 4" &&
188 H0=$(git rev-parse HEAD) &&
189 H1=$(git rev-parse HEAD^) &&
190 H2=$(git rev-parse HEAD^^) &&
191 echo "$H0 $H2" >.git/info/grafts &&
192 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
197 test_expect_success
'repack --keep-pack' '
198 test_create_repo keep-pack &&
201 P1=$(commit_and_pack 1) &&
202 P2=$(commit_and_pack 2) &&
203 P3=$(commit_and_pack 3) &&
204 P4=$(commit_and_pack 4) &&
205 ls .git/objects/pack/*.pack >old-counts &&
206 test_line_count = 4 old-counts &&
207 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
208 ls .git/objects/pack/*.pack >new-counts &&
209 grep -q $P1 new-counts &&
210 grep -q $P4 new-counts &&
211 test_line_count = 3 new-counts &&
216 test_expect_success
'bitmaps are created by default in bare repos' '
217 git clone --bare .git bare.git &&
218 git -C bare.git repack -ad &&
219 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
220 test_path_is_file "$bitmap"
223 test_expect_success
'incremental repack does not complain' '
224 git -C bare.git repack -q 2>repack.err &&
225 test_must_be_empty repack.err
228 test_expect_success
'bitmaps can be disabled on bare repos' '
229 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
230 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
234 test_expect_success
'no bitmaps created if .keep files present' '
235 pack=$(ls bare.git/objects/pack/*.pack) &&
236 test_path_is_file "$pack" &&
237 keep=${pack%.pack}.keep &&
238 test_when_finished "rm -f \"\$keep\"" &&
240 git -C bare.git repack -ad 2>stderr &&
241 test_must_be_empty stderr &&
242 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
243 test_must_be_empty actual
246 test_expect_success
'auto-bitmaps do not complain if unavailable' '
247 test_config -C bare.git pack.packSizeLimit 1M &&
248 blob=$(test-tool genrandom big $((1024*1024)) |
249 git -C bare.git hash-object -w --stdin) &&
250 git -C bare.git update-ref refs/tags/big $blob &&
251 git -C bare.git repack -ad 2>stderr &&
252 test_must_be_empty stderr &&
253 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
254 test_must_be_empty actual