]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: point out a bug handling stale shallow info
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 24 Oct 2018 15:56:10 +0000 (08:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Oct 2018 03:59:27 +0000 (12:59 +0900)
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5537-fetch-shallow.sh

index 7045685e2d3942161084ecd04a116faa83f35a44..686fdc9280532c18cfd5f30595466d07a08e106e 100755 (executable)
@@ -186,6 +186,33 @@ EOF
        test_cmp expect actual
 '
 
+test_expect_failure '.git/shallow is edited by repack' '
+       git init shallow-server &&
+       test_commit -C shallow-server A &&
+       test_commit -C shallow-server B &&
+       git -C shallow-server checkout -b branch &&
+       test_commit -C shallow-server C &&
+       test_commit -C shallow-server E &&
+       test_commit -C shallow-server D &&
+       d="$(git -C shallow-server rev-parse --verify D^0)" &&
+       git -C shallow-server checkout master &&
+
+       git clone --depth=1 --no-tags --no-single-branch \
+               "file://$PWD/shallow-server" shallow-client &&
+
+       : now remove the branch and fetch with prune &&
+       git -C shallow-server branch -D branch &&
+       git -C shallow-client fetch --prune --depth=1 \
+               origin "+refs/heads/*:refs/remotes/origin/*" &&
+       git -C shallow-client repack -adfl &&
+       test_must_fail git -C shallow-client rev-parse --verify $d^0 &&
+       ! grep $d shallow-client/.git/shallow &&
+
+       git -C shallow-server branch branch-orig $d &&
+       git -C shallow-client fetch --prune --depth=2 \
+               origin "+refs/heads/*:refs/remotes/origin/*"
+'
+
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd