Conversation
stanhu
force-pushed
the
sh-git-fetcher-shallow-clone
branch
2 times, most recently
from
August 8, 2026 20:33
c43e7d4 to
a32bba0
Compare
Introduce a `depth` source option on git sources so components can be
fetched with a shallow clone instead of downloading the full history.
This can significantly cut fetch time and disk usage for large
repositories where full history is not needed.
When `source git: url, depth: N` (positive integer) is set, the fetcher
initializes an empty repo and fetches the *resolved revision* (SHA)
directly at that depth, rather than `git clone`ing the full history:
git init --quiet .
git fetch --depth N <url> <sha>
Fetching the resolved SHA (instead of a branch/tag ref) means shallow
mode works for tag, branch, and SHA pins alike, and is immune to a
pinned branch tip moving between resolution and fetch. It does require
the remote to allow fetching a reachable SHA
(uploadpack.allowReachableSHA1InWant / allowAnySHA1InWant).
For submodules, shallow mode uses `submodule update --init` (since there
was no `clone --recursive`) but deliberately does not pass `--depth`:
a shallow submodule fetch targets the submodule's branch tip and fails
when the pinned submodule commit is not near it, so submodules are
fetched at full depth.
A missing or non-positive depth preserves the existing full-clone
behavior, so this is fully backward compatible. Components whose build
depends on git history (e.g. `git describe`) should not use this option.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Stan Hu <stanhu@gmail.com>
stanhu
force-pushed
the
sh-git-fetcher-shallow-clone
branch
from
August 8, 2026 21:45
a32bba0 to
dca1e51
Compare
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.
Description
Adds a
depthsource option to git sources so components can be fetched with a shallow clone instead of downloading the full repository history. This can significantly cut fetch time and disk usage for large repositories where full history isn't needed.Behavior
When a git source sets a positive integer
depth:the fetcher initializes an empty repo and fetches the resolved revision (SHA) directly at that depth, instead of
git cloneing the full history:Fetching the resolved SHA (rather than a branch/tag ref) means shallow mode:
A missing or non-positive
depthpreserves the existing full-clone behavior, so this is fully backward compatible.Submodules
In shallow mode there is no
clone --recursive, sogit_checkoutusessubmodule update --init --recursive. It deliberately does not pass--depth: a shallow submodule fetch targets the submodule's branch tip and fails when the pinned submodule commit isn't near it, so submodules are fetched at full depth.Requirements / caveats
uploadpack.allowReachableSHA1InWant/allowAnySHA1InWant).git describe) should not use this option.Changes
lib/omnibus/fetchers/git_fetcher.rb— addclone_depth;git_clonedoesinit+git_fetchin shallow mode;git_fetchfetches the resolved SHA with--depth;git_checkoutinitializes submodules at full depth.lib/omnibus/software.rb— allow:depthas a valid git source key and document the option.spec/unit/fetchers/git_fetcher_spec.rb— specs covering no/zero/positive depth, larger depth, submodule handling in both modes, and the fetch-resolved-SHA behavior.Testing
bundle exec rspec spec/unit/fetchers/git_fetcher_spec.rb— 21 examples, 0 failures.chefstyleclean on all changed files.🤖 Generated with Claude Code