]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7700-repack.sh
Merge branch 'sg/t5310-jgit-wants-sha1'
[thirdparty/git.git] / t / t7700-repack.sh
CommitLineData
9245ddd5
BC
1#!/bin/sh
2
3test_description='git repack works correctly'
4
5. ./test-lib.sh
6
ae475afc 7commit_and_pack () {
09279086 8 test_commit "$@" 1>&2 &&
3699d69d
DL
9 incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
10 echo pack-${incrpackid}.pack
ed7e5fc3
NTND
11}
12
ae475afc
DL
13test_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 &&
3699d69d 17 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
ae475afc
DL
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
22}
23
3699d69d 24# we expect $packid and $oid to be defined
cfe5eda0
DL
25test_has_duplicate_object () {
26 want_duplicate_object="$1"
27 found_duplicate_object=false
28 for p in .git/objects/pack/*.idx
29 do
30 idx=$(basename $p)
3699d69d 31 test "pack-$packid.idx" = "$idx" && continue
cfe5eda0 32 git verify-pack -v $p >packlist || return $?
3699d69d 33 if grep "^$oid" packlist
cfe5eda0
DL
34 then
35 found_duplicate_object=true
36 echo "DUPLICATE OBJECT FOUND"
37 break
38 fi
39 done &&
40 test "$want_duplicate_object" = "$found_duplicate_object"
41}
42
dd718365 43test_expect_success 'objects in packs marked .keep are not repacked' '
7a1c8c23
DL
44 echo content1 >file1 &&
45 echo content2 >file2 &&
9245ddd5 46 git add . &&
713c79e8 47 test_tick &&
9245ddd5
BC
48 git commit -m initial_commit &&
49 # Create two packs
50 # The first pack will contain all of the objects except one
d9b31db2
DL
51 git rev-list --objects --all >objs &&
52 grep -v file2 objs | git pack-objects pack &&
9245ddd5 53 # The second pack will contain the excluded object
d9b31db2 54 packid=$(grep file2 objs | git pack-objects pack) &&
3699d69d 55 >pack-$packid.keep &&
d9b31db2
DL
56 git verify-pack -v pack-$packid.idx >packlist &&
57 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
9245ddd5 58 mv pack-* .git/objects/pack/ &&
2d0174e3 59 git repack -A -d -l &&
9245ddd5 60 git prune-packed &&
cfe5eda0 61 test_has_duplicate_object false
9245ddd5
BC
62'
63
3198b89f 64test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
3699d69d 65 # build on $oid, $packid, and .keep state from previous
64d3dc94 66 git repack -Adbl &&
cfe5eda0 67 test_has_duplicate_object true
ee34a2be
JK
68'
69
3198b89f 70test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
3699d69d 71 # build on $oid, $packid, and .keep state from previous
71d76cb4 72 git -c repack.writebitmaps=true repack -Adl &&
cfe5eda0 73 test_has_duplicate_object true
ee34a2be
JK
74'
75
daae0625 76test_expect_success 'loose objects in alternate ODB are not repacked' '
3c3df429 77 mkdir alt_objects &&
7a1c8c23
DL
78 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
79 echo content3 >file3 &&
3699d69d 80 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
3c3df429 81 git add file3 &&
713c79e8 82 test_tick &&
3c3df429
BC
83 git commit -m commit_file3 &&
84 git repack -a -d -l &&
85 git prune-packed &&
cfe5eda0 86 test_has_duplicate_object false
3c3df429
BC
87'
88
3289b9de 89test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
2dec68cf 90 mkdir alt_objects/pack &&
3289b9de
BC
91 mv .git/objects/pack/* alt_objects/pack &&
92 git repack -a &&
ae475afc 93 test_no_missing_in_packs
3289b9de
BC
94'
95
1ef2d5a6 96test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
a83c8852 97 rm -f .git/objects/pack/* &&
7a1c8c23 98 echo new_content >>file1 &&
a83c8852 99 git add file1 &&
713c79e8 100 test_tick &&
a83c8852
BC
101 git commit -m more_content &&
102 git repack &&
103 git repack -a -d &&
ae475afc 104 test_no_missing_in_packs
a83c8852
BC
105'
106
171110a4 107test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
92cd8722
BC
108 # swap the .keep so the commit object is in the pack with .keep
109 for p in alt_objects/pack/*.pack
110 do
2dec68cf 111 base_name=$(basename $p .pack) &&
17a4ae92 112 if test_path_is_file alt_objects/pack/$base_name.keep
92cd8722
BC
113 then
114 rm alt_objects/pack/$base_name.keep
115 else
116 touch alt_objects/pack/$base_name.keep
117 fi
2dec68cf 118 done &&
92cd8722 119 git repack -a -d &&
ae475afc 120 test_no_missing_in_packs
92cd8722
BC
121'
122
79bc4c71 123test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
92cd8722
BC
124 rm -f alt_objects/pack/*.keep &&
125 mv .git/objects/pack/* alt_objects/pack/ &&
3699d69d 126 coid=$(git rev-parse HEAD^{commit}) &&
92cd8722 127 git reset --hard HEAD^ &&
713c79e8
JH
128 test_tick &&
129 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
92cd8722
BC
130 # The pack-objects call on the next line is equivalent to
131 # git repack -A -d without the call to prune-packed
132 git pack-objects --honor-pack-keep --non-empty --all --reflog \
133 --unpack-unreachable </dev/null pack &&
134 rm -f .git/objects/pack/* &&
135 mv pack-* .git/objects/pack/ &&
d9b31db2
DL
136 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
137 ! grep "^$coid " packlist &&
7a1c8c23 138 echo >.git/objects/info/alternates &&
3699d69d 139 test_must_fail git show $coid
92cd8722
BC
140'
141
094085e3 142test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
7a1c8c23 143 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
3699d69d 144 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
869a3d34
BC
145 rm -f .git/objects/pack/* &&
146 mv pack-* .git/objects/pack/ &&
147 # The pack-objects call on the next line is equivalent to
148 # git repack -A -d without the call to prune-packed
149 git pack-objects --honor-pack-keep --non-empty --all --reflog \
150 --unpack-unreachable </dev/null pack &&
151 rm -f .git/objects/pack/* &&
152 mv pack-* .git/objects/pack/ &&
d9b31db2
DL
153 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
154 ! grep "^$coid " &&
7a1c8c23 155 echo >.git/objects/info/alternates &&
3699d69d 156 test_must_fail git show $coid
869a3d34
BC
157'
158
7f3140cd 159test_expect_success 'objects made unreachable by grafts only are kept' '
1ec64827
BS
160 test_tick &&
161 git commit --allow-empty -m "commit 4" &&
162 H0=$(git rev-parse HEAD) &&
163 H1=$(git rev-parse HEAD^) &&
164 H2=$(git rev-parse HEAD^^) &&
7a1c8c23 165 echo "$H0 $H2" >.git/info/grafts &&
713c79e8 166 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
1ec64827
BS
167 git repack -a -d &&
168 git cat-file -t $H1
e9e33ab0 169'
1ec64827 170
ed7e5fc3
NTND
171test_expect_success 'repack --keep-pack' '
172 test_create_repo keep-pack &&
173 (
174 cd keep-pack &&
175 P1=$(commit_and_pack 1) &&
176 P2=$(commit_and_pack 2) &&
177 P3=$(commit_and_pack 3) &&
178 P4=$(commit_and_pack 4) &&
179 ls .git/objects/pack/*.pack >old-counts &&
180 test_line_count = 4 old-counts &&
181 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
182 ls .git/objects/pack/*.pack >new-counts &&
183 grep -q $P1 new-counts &&
184 grep -q $P4 new-counts &&
185 test_line_count = 3 new-counts &&
186 git fsck
187 )
188'
189
36eba032
EW
190test_expect_success 'bitmaps are created by default in bare repos' '
191 git clone --bare .git bare.git &&
192 git -C bare.git repack -ad &&
193 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
194 test_path_is_file "$bitmap"
195'
196
197test_expect_success 'incremental repack does not complain' '
198 git -C bare.git repack -q 2>repack.err &&
199 test_must_be_empty repack.err
200'
9245ddd5 201
36eba032
EW
202test_expect_success 'bitmaps can be disabled on bare repos' '
203 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
09279086 204 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
36eba032
EW
205 test -z "$bitmap"
206'
207
73284822
EW
208test_expect_success 'no bitmaps created if .keep files present' '
209 pack=$(ls bare.git/objects/pack/*.pack) &&
210 test_path_is_file "$pack" &&
211 keep=${pack%.pack}.keep &&
cc2649ae 212 test_when_finished "rm -f \"\$keep\"" &&
73284822 213 >"$keep" &&
7ff024e7
JK
214 git -C bare.git repack -ad 2>stderr &&
215 test_must_be_empty stderr &&
73284822
EW
216 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
217 test_must_be_empty actual
218'
219
25575015
JK
220test_expect_success 'auto-bitmaps do not complain if unavailable' '
221 test_config -C bare.git pack.packSizeLimit 1M &&
222 blob=$(test-tool genrandom big $((1024*1024)) |
223 git -C bare.git hash-object -w --stdin) &&
224 git -C bare.git update-ref refs/tags/big $blob &&
225 git -C bare.git repack -ad 2>stderr &&
226 test_must_be_empty stderr &&
227 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
228 test_must_be_empty actual
229'
230
36eba032 231test_done