Skip to content

Support pinning git package sources to a full commit SHA - #602

Open
joahg wants to merge 2 commits into
cashapp:masterfrom
joahg:joah/git-sha-pinning
Open

Support pinning git package sources to a full commit SHA#602
joahg wants to merge 2 commits into
cashapp:masterfrom
joahg:joah/git-sha-pinning

Conversation

@joahg

@joahg joahg commented Aug 5, 2026

Copy link
Copy Markdown

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 #ref fragment to git 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 #ref that 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 ./... and golangci-lint run.

joahg and others added 2 commits August 4, 2026 22:04
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
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.

1 participant