Fix checkout init for SHA-256 repositories#2439
Open
yaananth wants to merge 2 commits into
Open
Conversation
f279b42 to
67bd696
Compare
hhaador
approved these changes
May 22, 2026
BastirEiii
approved these changes
May 23, 2026
12bc7fa to
d2a514d
Compare
d2a514d to
4823ef7
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes checkout for SHA-256 repositories by detecting the target repository's object format before git init and initializing the local repo with --object-format=sha256 when appropriate. Detection uses either the existing commit SHA length (40/64 hex chars) or a pre-init call to GET /repos/{owner}/{repo}/hash-algorithm via the existing action token; SHA-1 and undetermined cases preserve the prior default git init behavior.
Changes:
- Add
tryGetRepositoryObjectFormatingithub-api-helper.ts(commit-SHA-based or hash-algorithm endpoint). - Extend
git.init()to accept an optionalobjectFormatand append--object-format=sha256when applicable. - Wire detection into
git-source-provider.tsbefore init, and add unit tests + rebuiltdist/index.js.
Show a summary per file
| File | Description |
|---|---|
| src/github-api-helper.ts | Adds RepositoryObjectFormatResult interface, tryGetRepositoryObjectFormat, and getObjectFormat SHA-length helper. |
| src/git-source-provider.ts | Detects object format prior to repo initialization and passes it to git.init. |
| src/git-command-manager.ts | Updates init() signature/impl to optionally pass --object-format=sha256. |
| dist/index.js | Regenerated bundle reflecting the above source changes. |
| test/github-api-helper.test.ts | New tests covering sha1/sha256/unknown/error responses and SHA-based detection without API calls. |
| test/git-command-manager.test.ts | New tests verifying git init arguments for sha256 vs sha1 inputs. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/6 changed files
- Comments generated: 1
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 initGET /repos/{owner}/{repo}/hash-algorithmgit init --object-format=sha256only when the repository is 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 hash-algorithm endpoint uses the existing action token through Octokit and works before a
.gitdirectory exists, so it supports private repositories without setting up Git credential config early.The endpoint returns
hash_algorithmassha1orsha256. Checkout uses that value directly instead of inferring the repository format from a branch commit SHA.When checkout already has a 40- or 64-character commit SHA, it can determine the object format from that SHA without an API request. Otherwise, object-format detection is one pre-init API request to the hash-algorithm endpoint.
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 lintGET /repos/{owner}/{repo}/hash-algorithmrequest andsha1/sha256responses