filesystem: pack without index breaks packed object reads
What happened?
A well-named objects/pack/pack-<hash>.pack without a matching .idx causes reads of otherwise valid packed objects to fail with packfile not found.
This can be left behind by an interrupted fetch. Loose-object reads continue to work, which can make the failure appear intermittent until an object is packed.
Reproduction
git init -q repo
cd repo
git config user.email t@t
git config user.name t
echo hi >a.txt
git add a.txt
git commit -qm one
git repack -adq
cp an-existing-pack .git/objects/pack/pack-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.packWith no corresponding pack-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.idx, opening the repository with go-git and calling CommitObject(HEAD) returns packfile not found. git cat-file -t HEAD still returns commit.
Cause
DotGit.objectPacks discovers packs by enumerating .pack files. ObjectStorage.populateIndex then tries to load every corresponding .idx, so one missing index aborts index population for all valid packs.
Git instead prepares readable packs from their index files and treats a .pack without an index as garbage. See for_each_file_in_pack_dir and its use by the packed object database.
Proposed behavior
Only enumerate a pack when both its .pack and .idx are present. This is lossless for go-git's filesystem read path because every packed-object lookup requires an index; no existing read path reconstructs an index from a bare pack.
Source: go-git/go-git