Support pinning git package sources to a full commit SHA - #602
Open
joahg wants to merge 2 commits into
Open
Conversation
Git sources currently pass the #ref fragment to 'git clone --branch', which only accepts branch and tag names, so packages cannot be pinned to an exact commit. Treat a #ref that is a full lowercase hex commit hash (40 or 64 characters) as a commit SHA: initialise an empty repository and fetch just that commit rather than cloning a branch. The ETag of a pinned commit is the commit itself, so no remote check is needed, and validation checks repository reachability since ls-remote cannot list an unadvertised commit. Fetching by SHA requires the server to allow it (GitHub and GitLab do). Abbreviated hashes are not treated as commits since they are indistinguishable from branch names. Buzz-Message: buzz://message?channel=573ff355-6c19-422d-b425-112853d0ec7e&id=16f5b666c0976829a1985868753407c7b20b393d89f99a8b39106be9fe6a1514 Amp-Thread-ID: https://ampcode.com/threads/T-019fce27-e59e-727c-b6d3-cdeeba894a4e Co-authored-by: Amp <amp@ampcode.com>
Git permits branch and tag names that are exactly 40 or 64 lowercase hex characters. Unconditionally reinterpreting such refs as commit object IDs would change existing 'git clone --branch' behaviour for those repositories. Resolve an advertised exact branch or tag first (branches take precedence over tags, matching 'git clone --branch'), and only fall back to commit-SHA fetching when the remote advertises no ref with that name. The ETag of a full-hex ref follows the same resolution. Buzz-Message: buzz://message?channel=573ff355-6c19-422d-b425-112853d0ec7e&id=37a4a83af83ddcf40f55a799a2d7e52e69f2908db5098993c82d4a96727015a6 Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019fce44-560f-770d-bacb-fba12dd9ae31
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.
Context: #597 — composing agent-skills-style content packages from existing Hermit primitives. A commit pin is the immutable-security-pin counterpart to tracking a branch.
Git sources currently pass the
#reffragment togit clone --branch, which only accepts branch and tag names, so packages cannot be pinned to an exact commit — and tags are mutable, so there is no immutable pin at all.A
#refthat is a full lowercase hex commit hash (40 or 64 characters) is now fetched as a commit: initialise an empty repository and fetch just that commit rather than cloning a branch. Fetching by SHA requires the server to allow it (GitHub and GitLab do). Abbreviated hashes are not treated as commits since they are indistinguishable from branch names.Because git also permits branch/tag names that are exactly 40/64 hex characters, an advertised exact branch or tag is resolved first (branches take precedence over tags, matching
git clone --branch), and commit-SHA fetching is only the fallback when the remote advertises no ref with that name — existing behaviour for such refs is preserved.Tested with
go test ./...andgolangci-lint run.