Skip to content

Commit

Permalink
Add objectFormat setting to allow init()ing a repo with sha256
Browse files Browse the repository at this point in the history
  • Loading branch information
yangskyboxlabs committed Oct 15, 2024
1 parent eef6144 commit 68a03db
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 39 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
# running from unless specified. Example URLs are https://github.com or
# https://my-ghes-server.example.com
github-server-url: ''

# Use the given object format when creating local repository. Specifically, use
# 'sha256' to checkout a SHA-256 repository.
# Defualt: null
object-format: ''
```
<!-- end usage -->
Expand All @@ -143,6 +148,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit)
- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event)
- [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token)
- [Checkout SHA-256 repository](#checkout-sha-256-repository)

## Fetch only the root files

Expand Down Expand Up @@ -288,6 +294,14 @@ jobs:
```
*NOTE:* The user email is `{user.id}+{user.login}@users.noreply.github.com`. See users API: https://api.github.com/users/github-actions%5Bbot%5D

## Checkout SHA-256 repository

```yaml
- uses: actions/checkout@v4
with:
object-format: sha256
```

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE)
3 changes: 2 additions & 1 deletion __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,8 @@ async function setup(testName: string): Promise<void> {
sshUser: '',
workflowOrganizationId: 123456,
setSafeDirectory: true,
githubServerUrl: githubServerUrl
githubServerUrl: githubServerUrl,
objectFormat: undefined
}
}

Expand Down
27 changes: 27 additions & 0 deletions __test__/git-command-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,31 @@ describe('Test fetchDepth and fetchTags options', () => {
expect.any(Object)
)
})

it('should call execGit wiwth the correct arguments when sha256 is used', async () => {
jest.spyOn(exec, 'exec').mockImplementation(mockExec)

const workingDirectory = 'test'
const lfs = false
const doSparseCheckout = false
git = await commandManager.createCommandManager(
workingDirectory,
lfs,
doSparseCheckout
)

await git.init({objectFormat: 'sha256'})
// await git.init({objectFormat: undefined})

expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
[
'init',
'--object-format=sha256',
'test'
],
expect.any(Object)
)
})
})

Loading

0 comments on commit 68a03db

Please sign in to comment.