Repository navigation
[repo-assist] Fix git dependency restore from a cold git cache - #4463
Merged
fpellet merged 19 commits intoNov 7, 2026
Merged
Conversation
ProcessHelper.start read proc.StartTime after Start, to fill a set that nothing reads. On Linux, it throws once the process has exited, as a fast git command often has: the start failed with "Start of process ... failed", and getHash turned "git rev-parse" into None, so the branch of a local git repository was not found.
Since #4377, the path of a local git repository was its URL without "file://", so "file:///C:/code/repo" gave "/C:/code/repo" on Windows and its branches were not found. localPathOfFileUrl also drops the slash before a drive letter, and decodes the escaped characters, the only way to write a space in the URL. The project of a local repository was the end of the URL after its last "/": a Windows path that ends with "\" gave an empty name, so the git cache was ~/.paket/git/db itself, and one that doesn't exist gave the whole path. It is now the folder name from the path, split on "/" and "\".
Since #4407, fetchCache runs inside RunInLockedAccessMode, which creates the cache folder for its paket.processlock file. fetchCache then skipped "clone --mirror", which refuses a folder that isn't empty, and ran "remote set-url" in a folder that isn't a repository: git dependencies failed to restore from a cold git cache, as on every fresh CI agent. The mirror is now set up in place with "init --bare" and "remote add --mirror=fetch", and a cache left without origin by a failed run is set up again. The HEAD of such a mirror stays on init.defaultBranch, which the repository may not have, and the one of any cache names a branch that is gone once the remote renames it: a clone of the cache then has no checkout, and the checks for local changes failed with "bad revision 'HEAD'". The paket-files are now cloned with --no-checkout and checked out at the commit, only an existing checkout is checked, and the tag and the checkout fail on their exit code, since a failed checkout reports "error:" and not "fatal:". Closes #4461
A clone made with --no-checkout has a HEAD but no file until the checkout of the commit. When that checkout failed, as for a file name too long for the file system, the next run took the clone for one with local changes, or for an up-to-date one when the HEAD was the locked commit, and only removing it by hand helped. checkoutToPaketFolder now removes the clone it made when a later step fails, and a clone whose .git is a folder counts as checked out only when it has an index, else the restore clones it again. A .git file, as for a submodule or a worktree, names a repository whose index is elsewhere.
git looked for the repository from the cache folder up: when a cache had lost its HEAD or config, "remote set-url" and "remote update" ran on the repository of a parent folder, such as a dotfiles repository in the home folder. The commands on the cache, including the tags of a version range, now name it with --git-dir, which safe.bareRepository=explicit also allows, and "init --bare" runs every time to repair such a cache. The git tests run with safe.bareRepository=explicit, so that a command on the cache without --git-dir fails.
git looked for the repository from the paket-files folder up: for a folder that isn't a clone, as paket-files committed with the project, the fetch, the tag and the checkout of the dependency ran on the repository of the project, and switched its working tree to the dependency. The git commands on a paket-files clone now name it with --git-dir and --work-tree, and a folder without .git is cloned again. A .git file, as for a submodule or a worktree, names the repository of a clone, which --git-dir reads: such a clone keeps its changes.
rev-parse of an annotated tag gives the tag object, and ls-remote gives it on
the line of the tag, so a git dependency on such a tag was locked at the tag
object. The checkout peeled it, but the check for an up-to-date clone compared
it with the commit of HEAD, and each restore downloaded the dependency again.
rev-parse now asks for <commit-ish>^{commit}, ls-remote for the ^{} line of a
tag, and the check also accepts a lock file that holds the tag object.
The project of a git repository was the end of its URL with every ".git" removed, so me.github.io gave "mehub.io" as the name of its paket-files and git cache folders. Only the ".git" that ends the name is removed now. A local repository given by its .git folder, as file:///home/me/repo/.git, gave the empty name, so its folders were the ones that hold all the local repositories, as paket-files/localfilesystem, which the restore could delete: it is named after the folder of the .git now. The root of a file system has no folder name: file:///.git gave the empty name too, and file:///C:/ "C:", which Path.Combine takes for the current folder of the drive on Windows, as the folder of the project. Such a repository fails with an error.
The git cache of a repository was ~/.paket/git/db/<project>: two repositories of the same name from different owners shared it, and each fetch set its origin to the other one and pruned the branches of the first. The cache is now ~/.paket/git/db/<owner>/<project>, as the paket-files are, so each repository is cloned again once. The git tests remove the folder of the owner when they leave it empty.
The paket-files are cloned from file:///<git cache>, and git decodes the escaped characters of a file URL. The project name of a local repository is decoded from its URL, so "100%25" gave a cache folder named "100%", which the clone looked for as "100" followed by an invalid escape. The % of the cache path are now escaped.
A local git dependency without branch takes master, and a repository whose default branch is main failed with "Could not find hash for master" alone. The message now says to give the branch.
fpellet
force-pushed
the
repo-assist/fix-issue-4461-cold-git-cache-72832df9fc4f3ea6
branch
from
November 7, 2026 09:11
d5223cc to
83a9abc
Compare
A path like file:///home/me/repo/. or a repository named "..git" gave the project "." or "..", so its paket-files and git cache folders were a parent folder, which the restore deleted when it held no clone.
The commit of an annotated tag was looked for only as refs/tags/<tag>^{},
so "tags/v1.0" and "refs/tags/v1.0" were locked at the tag object.
The comparison was case-sensitive and culture-sensitive, so the same repository written as Repo.git and Repo.GIT got two git caches and paket-files folders on Windows, and Repo/.GIT became the root of a file system.
DownloadSourceFiles and checkoutToPaketFolder both ran git rev-parse on the paket-files clone. DownloadSourceFiles now passes on whether it holds a checkout, also with --force.
fetchCache ran git init --bare and listed the remotes on each call, so a healthy cache started 4 git processes instead of 2. It now reads the URL of origin first, and sets it again only when it changed.
…of its own Two repositories created in the same second got the same commit, so the check passed even when the git cache didn't follow the moved repository.
… folder A remote URL like ssh://host/home/me/repo/.git, or .../repo/.GIT since the .git suffix is removed in any case, gave an empty project. Its paket-files folder was then the one of its owner, which the restore deleted with the clones of the other repositories in it, and its checkout skipped the checks for local changes. Such a URL is now named like ssh://host/home/me/repo, and an empty project fails as a dot segment does.
…origin The repair path of fetchCache chose between remote add and remote set-url with the output of git remote, which also lists an origin of the git config of the user, as from remote.origin.prune in ~/.gitconfig. A cold cache then got set-url, which git refused without a fatal error, and the fetch failed. The choice now reads the config of the cache only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4461
Root cause
Since #4407,
fetchCacheruns insideRunInLockedAccessMode, which creates the git cache folder for itspaket.processlockfile.fetchCachethen skippedgit clone --mirror, which refuses a folder that isn't empty, and rangit remote set-urlin a folder that isn't a repository. Git dependencies failed to restore from a cold git cache, as on every fresh CI agent.Changes
Each commit fixes one problem, with its test and release note. Besides the cold cache itself, it covers the problems that showed up while testing that path.
Cold git cache (#4461)
git init --bareandgit remote add --mirror=fetch. A cache that a failed run left without origin is set up again.--no-checkout, then checked out at the locked commit. A cache whose HEAD names a branch that is gone, such asinit.defaultBranchor a renamed default branch, no longer fails with "bad revision 'HEAD'". The tag and checkout steps now fail on their exit code.Git commands that ran on the wrong repository
--git-dir. A broken cache no longer makes git change the repository of a parent folder, such as a dotfiles repository in the home folder, and the cache works withsafe.bareRepository=explicit.--git-dirand--work-tree. A paket-files folder committed with the project, without its clone, is cloned again: Paket no longer checks the dependency out over the project's repository. A clone whose.gitis a file, as for a submodule or a worktree, keeps its changes.Restore state
Names of the git cache and paket-files folders
~/.paket/git/db/<owner>/<project>. Remote repositories of the same name from two owners no longer share a cache and swap its branches on each fetch..gitthat ends a name is removed, some.github.iono longer becomesmehub.io..gitfolder is named after the folder that holds it. One at the root of a file system fails with an error: before, its name was empty orC:, which pointed at the folder of all the local clones or at the project.%of the cache path is escaped in the clone URL.Local repositories
file://URL. Windows paths (file:///C:/code/repo), broken since [repo-assist] Fix (redacted) git URL handling to preserve absolute path slash #4377, work again, and so do escaped characters (%20) and a path that ends with\.ProcessHelper.startno longer reads theStartTimeof a process that may have exited. On Linux it failed a fast git command with "Start of process ... failed", which showed as "Could not find hash for ...".master, the error suggests giving the branch.Behaviour changes
paket clear-cacheremoves the old caches..gitinside its name, such asme.github.io, moves.localfilesystem.Tests
integrationtests/Paket.IntegrationTests/GitSpecs.fs(new): 12 tests on local repositories, with no network..gitis a file.%in the folder name.The tests keep git inside their scenario folder with
GIT_CEILING_DIRECTORIESand run withsafe.bareRepository=explicit.tests/Paket.Tests/GitHandlingSpecs.fs(new): unit tests of the path read from afile://URL, and of the project name.