Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

[repo-assist] Fix git dependency restore from a cold git cache - #4463

Merged
fpellet merged 19 commits into
masterfrom
repo-assist/fix-issue-4461-cold-git-cache-72832df9fc4f3ea6
Nov 7, 2026
Merged

fpellet merged 19 commits into
masterfrom
repo-assist/fix-issue-4461-cold-git-cache-72832df9fc4f3ea6

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4461

Root cause

Since #4407, fetchCache runs inside RunInLockedAccessMode, which creates the git cache folder for its paket.processlock file. fetchCache then skipped git clone --mirror, which refuses a folder that isn't empty, and ran git 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.

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)

  • The mirror is set up in place with git init --bare and git remote add --mirror=fetch. A cache that a failed run left without origin is set up again.
  • The paket-files are cloned with --no-checkout, then checked out at the locked commit. A cache whose HEAD names a branch that is gone, such as init.defaultBranch or 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

  • The commands on the git cache use --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 with safe.bareRepository=explicit.
  • The commands on a paket-files clone use --git-dir and --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 .git is a file, as for a submodule or a worktree, keeps its changes.

Restore state

  • A clone whose checkout failed is removed, and one without a checkout, as an earlier version could leave, is cloned again. Before, such a clone was taken for one with local changes, or for an up-to-date one.
  • An annotated tag is locked at its commit, not at the tag object, which made every restore download the dependency again. A lock file that holds the tag object still restores.

Names of the git cache and paket-files folders

  • The git cache is ~/.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.
  • Only the .git that ends a name is removed, so me.github.io no longer becomes mehub.io.
  • A local repository given by its .git folder 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 or C:, which pointed at the folder of all the local clones or at the project.
  • The % of the cache path is escaped in the clone URL.

Local repositories

  • The path is read from the 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.start no longer reads the StartTime of 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 ...".
  • When a local repository has no master, the error suggests giving the branch.

Behaviour changes

  • Every git repository is cloned again once into its new cache folder. paket clear-cache removes the old caches.
  • The paket-files folder of a repository with .git inside its name, such as me.github.io, moves.
  • Local repositories with the same folder name still share a git cache, because their owner is always localfilesystem.

Tests

  • integrationtests/Paket.IntegrationTests/GitSpecs.fs (new): 12 tests on local repositories, with no network.

    • Restore from a cold cache, then an update.
    • A cache HEAD that names no branch.
    • A failed checkout, and a clone left without one.
    • A paket-files folder without a clone, and a clone whose .git is a file.
    • Owner-keyed caches.
    • A % in the folder name.
    • Annotated tags, including a lock file that holds the tag object.
    • Repair of a broken cache.
    • Version ranges resolved from the tags of the cache.

    The tests keep git inside their scenario folder with GIT_CEILING_DIRECTORIES and run with safe.bareRepository=explicit.

  • tests/Paket.Tests/GitHandlingSpecs.fs (new): unit tests of the path read from a file:// URL, and of the project name.

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
fpellet force-pushed the repo-assist/fix-issue-4461-cold-git-cache-72832df9fc4f3ea6 branch from d5223cc to 83a9abc Compare November 7, 2026 09:11
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.
@fpellet
fpellet marked this pull request as ready for review November 7, 2026 10:53
@fpellet
fpellet merged commit 23f89b4 into master Nov 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git dependencies fail to restore from a cold git cache since 11.0.0 (fetchCache runs after the lock creates the cache folder)

1 participant