Skip to content

fix(git): check a commit out aside, and keep the cache of remote resources in a directory for each kind - #14475

Merged
glours merged 2 commits into
docker:mainfrom
ndeloof:cache-kind-subdirectories
Nov 9, 2026
Merged

glours merged 2 commits into
docker:mainfrom
ndeloof:cache-kind-subdirectories

Conversation

@ndeloof

@ndeloof ndeloof commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

The cache of remote resources now has one directory for each kind of resource, git/ and oci/, and a Git checkout is placed in its directory only once it is complete.

Context

This follows #14462, which made the OCI loader place an extracted artifact in the cache only once it is complete. This PR applies the equivalent fix to the Git loader, and gives the two kinds of resource the same layout in the cache.

Compose keeps what it fetches for a remote Compose file in a cache, one directory for each commit or digest. The two loaders do not do it the same way: extracted OCI artifacts sit at the root of the cache, and Git checkouts sit there too, next to them.

The Git loader also checks a commit out directly into its directory, and takes the directory for a valid entry as soon as it exists. A run interrupted during the fetch or the checkout (Ctrl-C, a dropped connection, a killed process) leaves a partial directory, and every later run uses it, with no sign that something is missing.

What the PR brings

  • A Git checkout is made in a directory of its own and renamed to the one of its commit once complete, so the directory of a commit is never a partial checkout. Runs which check out the same commit together end with one entry, and none of them fails because another was first. This is the same approach the OCI loader already has for its entries.
  • Checkouts live in <cache>/git/<sha> and extracted OCI artifacts in <cache>/oci/<digest>, so the cache has the same structure for both.

Not changed: how a reference is resolved to a commit or a digest, what is checked out or extracted, the offline behavior, and the files that are loaded.

One consequence: what earlier releases left at the root of the cache is no longer looked for, so a remote resource is fetched again the first time it is used after the upgrade. The old directories are not removed.

Separating the cache by kind of remote also makes it easier to purge the historical data later. What earlier releases cached cannot be relied on, since it may be incomplete, and it now sits at the root of the cache, apart from the git/ and oci/ directories, so it can be told from what the current code writes and removed without touching it.

🤖 Generated with Claude Code

…tory of the cache for Git

A commit was checked out directly into its directory of the cache, which was
then taken for complete as soon as it existed: a run interrupted during the
fetch or the checkout left a partial directory that every later run used.

The checkout is now made in a directory of its own and renamed to the one of the
commit once it is complete, so the directory of a commit is never a partial
checkout, and no file beside it is needed to tell. Checkouts live in a "git"
directory of the cache, and what earlier releases left at the root of the cache
is no longer looked for.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…the cache

The cache of remote resources now has one directory for each kind of resource:
the checkouts of Git repositories are in "git", and the extracted OCI artifacts
are in "oci" rather than at the root of the cache.

What earlier releases left at the root of the cache is no longer looked for: an
artifact is pulled again the first time it is used.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested review from a team as code owners November 6, 2026 17:41

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/remote/git.go 80.00% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glours
glours merged commit 83c5029 into docker:main Nov 9, 2026
118 of 121 checks passed
@ndeloof
ndeloof deleted the cache-kind-subdirectories branch November 9, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants