On Tue, Jul 17, 2018 at 06:51:39AM -0700, Johannes Schindelin via GitGitGadget wrote: > Under certain circumstances, commits that were reachable can be made > unreachable, e.g. via `git fetch --prune`. These commits might have > been packed already, in which case `git repack -adlf` will just drop > them without giving them the usual grace period before an eventual > `git prune` (via `git gc`) prunes them. > > This is a problem when the `shallow` file still lists them, which is > the reason why `git prune` edits that file. And with the proposed > changes, `git repack -ad` will now do the same. > > Reported by Alejandro Pauly. > > Changes since v1: > > - Also trigger `prune_shallow()` when `--unpack-unreachable=<approxidate>` was passed to `git repack`. > - No need to trigger `prune_shallow()` when `git repack` was called with `-k`. I think you might have missed the bigger problem I pointed at, as it was buried deep within my later reply. Try applying this patch on top, which tests the opposite case (reachable shallow commits are retained): diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh index d32ba20f9d..911e457ae1 100755 --- a/t/t5537-fetch-shallow.sh +++ b/t/t5537-fetch-shallow.sh @@ -186,17 +186,20 @@ EOF test_cmp expect actual ' -test_expect_success '.git/shallow is edited by repack' ' +test_expect_success 'set up shallow server' ' 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)" && - git -C shallow-server checkout master && + git -C shallow-server checkout master +' +test_expect_success 'repack drops unreachable objects from .git/shallow' ' + test_when_finished "rm -rf shallow-client" && git clone --depth=1 --no-tags --no-single-branch \ "file://$PWD/shallow-server" shallow-client && @@ -213,4 +216,13 @@ test_expect_success '.git/shallow is edited by repack' ' origin "+refs/heads/*:refs/remotes/origin/*" ' +test_expect_success 'repack keeps reachable objects in .git/shallow' ' + test_when_finished "rm -rf shallow-client" && + git clone --depth=1 --no-tags --no-single-branch \ + "file://$PWD/shallow-server" shallow-client && + + git -C shallow-client repack -adfl && + grep $d shallow-client/.git/shallow +' + test_done