Fix checkout init for SHA-256 repositories#2439
Draft
yaananth wants to merge 1 commit into
Draft
Conversation
f279b42 to
67bd696
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.
Summary
Fixes github/actions-runtime#5528 by initializing checkout's local Git repository with the object format used by the target repository.
SHA-256 repositories fail today because checkout creates the local repository with plain
git initbefore fetching. Plaingit initcreates a SHA-1 repository by default, so the later fetch from a SHA-256 remote fails with a client/server object-format mismatch unless the workflow manually setsGIT_DEFAULT_HASH=sha256.This PR updates checkout to:
git initgit ls-remote --symref HEADwhen the API path cannot identify the format and the remote can advertiseHEADdirectlygit init --object-format=sha256only when the repository is positively identified as SHA-256git initbehavior for SHA-1 repositories and for cases where the format is not identifiedWhy this approach
Checkout has to choose the local repository object format before the first fetch. The GitHub API path already uses the action token and works before a
.gitdirectory exists, so it supports private repositories without setting up Git credential config early.The request count depends on the information checkout already has:
default_branch, then the branch endpoint for that branch's commit SHA; the resolved default branch is reused later in the checkout flowFor the hash algorithms handled here, a 40-character commit object ID is SHA-1 and a 64-character commit object ID is SHA-256.
The direct Git probe covers repositories where the API lookup is unavailable but
HEADis advertised normally. Checkout only opts into SHA-256 initialization after a positive SHA-256 result; otherwise it preserves the existing initialization path.Security notes
The pre-init detection uses the existing Octokit/API authentication path and does not require writing Git credentials before repository initialization. Normal checkout authentication still happens through the existing auth helper flow, including the existing cleanup behavior for
persist-credentials: false.Validation
npm run buildnpm test -- --runInBandnpm run format-checknpm run lintsha256persist-credentials: falseverified checkout succeeds and leaves no local auth config or temporary credential file behind