Skip to content

Commit d2be401

Browse files
committed
repack: point out a bug handling stale shallow info
A `git fetch --prune` can turn previously-reachable objects unreachable, even commits that are in the `shallow` list. A subsequent `git repack -ad` will then unceremoniously drop those unreachable commits, and the `shallow` list will become stale. This means that when we try to fetch with a larger `--depth` the next time, we may end up with: fatal: error in object: unshallow <commit-hash> Reported by Alejandro Pauly. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e333175 commit d2be401

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

t/t5537-fetch-shallow.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,31 @@ EOF
186186
test_cmp expect actual
187187
'
188188

189+
test_expect_failure '.git/shallow is edited by repack' '
190+
git init shallow-server &&
191+
test_commit -C shallow-server A &&
192+
test_commit -C shallow-server B &&
193+
git -C shallow-server checkout -b branch &&
194+
test_commit -C shallow-server C &&
195+
test_commit -C shallow-server E &&
196+
test_commit -C shallow-server D &&
197+
d="$(git -C shallow-server rev-parse --verify D)" &&
198+
git -C shallow-server checkout master &&
199+
200+
git clone --depth=1 --no-tags --no-single-branch \
201+
"file://$PWD/shallow-server" shallow-client &&
202+
203+
: now remove the branch and fetch with prune &&
204+
git -C shallow-server branch -D branch &&
205+
git -C shallow-client fetch --prune --depth=1 \
206+
origin "+refs/heads/*:refs/remotes/origin/*" &&
207+
git -C shallow-client repack -adfl &&
208+
test_must_fail git -C shallow-client rev-parse --verify $d^0 &&
209+
! grep $d shallow-client/.git/shallow &&
210+
211+
git -C shallow-server branch branch-orig D^0 &&
212+
git -C shallow-client fetch --prune --depth=2 \
213+
origin "+refs/heads/*:refs/remotes/origin/*"
214+
'
215+
189216
test_done

0 commit comments

Comments
 (0)