Skip to content

buildx(build): pin implicit git contexts consistently#1085

Merged
crazy-max merged 2 commits into
docker:mainfrom
crazy-max:git-context-pin
May 7, 2026
Merged

buildx(build): pin implicit git contexts consistently#1085
crazy-max merged 2 commits into
docker:mainfrom
crazy-max:git-context-pin

Conversation

@crazy-max

@crazy-max crazy-max commented Apr 16, 2026

Copy link
Copy Markdown
Member

fixes #1083

This change makes implicit git contexts resolve to the event commit consistently across fragment and query formats. The old behavior already pinned most fragment contexts to the event SHA, but query mode still kept symbolic branch and tag refs with a checksum, which meant a later ref update could fail before BuildKit ever got to the pinned commit.

The current gitContext() logic now treats implicit refs as commit-pinned by default and only preserves a symbolic ref in query mode when the caller explicitly provided a checksum. This keeps the old explicit checksum contract, keeps refs/pull/*/head pinned to the pull request head SHA instead of the merge SHA, and removes the older split where pull request refs had special ad hoc handling while branches and tags followed a different path. The function was also simplified in place so the main concepts are easier to read, namely the explicit checksum, the implicit pinned ref, and the final rendered URL.

The history here matters because the previous fix only addressed refs/pull/* drift, but the real problem was broader. Older code at 3bb4ae3#diff-0cd594dddd6a9f2e3e26afebbb92716434437d7001c2416252aa7531e7f2b8d4L45-L60 collapsed most non-PR refs to the event SHA, which made fragment-style contexts effectively pinned, while newer query-style contexts preserved symbolic refs like refs/heads/* and refs/tags/* together.

This also supports BuildKit's new fetch-by-commit query attribute as an explicit opt-in, so callers on compatible builders can preserve the symbolic ref in the URL while having BuildKit fetch the pinned checksum directly instead of resolving the possibly moved ref first.

@crazy-max crazy-max requested a review from tonistiigi April 16, 2026 12:34
@crazy-max crazy-max marked this pull request as ready for review April 16, 2026 12:34
@tcely

This comment was marked as off-topic.

@crazy-max

This comment was marked as off-topic.

crazy-max added 2 commits May 7, 2026 11:46
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max crazy-max merged commit 4386736 into docker:main May 7, 2026
116 checks passed
@crazy-max crazy-max deleted the git-context-pin branch May 7, 2026 11:43
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.

Prepare is not providing the correct context

2 participants