Skip to content

Commit 83f93bf

Browse files
committed
Add bare option to checkout action
Fixes actions#603
1 parent cbb7224 commit 83f93bf

File tree

4 files changed

+159
-110
lines changed

4 files changed

+159
-110
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
126126
# running from unless specified. Example URLs are https://github.com or
127127
# https://my-ghes-server.example.com
128128
github-server-url: ''
129+
130+
# Whether to clone the repository as a bare repository
131+
# Default: false
132+
bare: ''
129133
```
130134
<!-- end usage -->
131135

Diff for: __test__/git-command-manager.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,42 @@ describe('Test fetchDepth and fetchTags options', () => {
375375
expect.any(Object)
376376
)
377377
})
378+
379+
it('should call execGit with the correct arguments when bare is true', async () => {
380+
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
381+
382+
const workingDirectory = 'test'
383+
const lfs = false
384+
const doSparseCheckout = false
385+
git = await commandManager.createCommandManager(
386+
workingDirectory,
387+
lfs,
388+
doSparseCheckout
389+
)
390+
const refSpec = ['refspec1', 'refspec2']
391+
const options = {
392+
filter: 'filterValue',
393+
bare: true
394+
}
395+
396+
await git.fetch(refSpec, options)
397+
398+
expect(mockExec).toHaveBeenCalledWith(
399+
expect.any(String),
400+
[
401+
'-c',
402+
'protocol.version=2',
403+
'fetch',
404+
'--bare',
405+
'--no-tags',
406+
'--prune',
407+
'--no-recurse-submodules',
408+
'--filter=filterValue',
409+
'origin',
410+
'refspec1',
411+
'refspec2'
412+
],
413+
expect.any(Object)
414+
)
415+
})
378416
})

Diff for: action.yml

+112-109
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,112 @@
1-
name: 'Checkout'
2-
description: 'Checkout a Git repository at a particular version'
3-
inputs:
4-
repository:
5-
description: 'Repository name with owner. For example, actions/checkout'
6-
default: ${{ github.repository }}
7-
ref:
8-
description: >
9-
The branch, tag or SHA to checkout. When checking out the repository that
10-
triggered a workflow, this defaults to the reference or SHA for that
11-
event. Otherwise, uses the default branch.
12-
token:
13-
description: >
14-
Personal access token (PAT) used to fetch the repository. The PAT is configured
15-
with the local git config, which enables your scripts to run authenticated git
16-
commands. The post-job step removes the PAT.
17-
18-
19-
We recommend using a service account with the least permissions necessary.
20-
Also when generating a new PAT, select the least scopes necessary.
21-
22-
23-
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
24-
default: ${{ github.token }}
25-
ssh-key:
26-
description: >
27-
SSH key used to fetch the repository. The SSH key is configured with the local
28-
git config, which enables your scripts to run authenticated git commands.
29-
The post-job step removes the SSH key.
30-
31-
32-
We recommend using a service account with the least permissions necessary.
33-
34-
35-
[Learn more about creating and using
36-
encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
37-
ssh-known-hosts:
38-
description: >
39-
Known hosts in addition to the user and global host key database. The public
40-
SSH keys for a host may be obtained using the utility `ssh-keyscan`. For example,
41-
`ssh-keyscan github.com`. The public key for github.com is always implicitly added.
42-
ssh-strict:
43-
description: >
44-
Whether to perform strict host key checking. When true, adds the options `StrictHostKeyChecking=yes`
45-
and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to
46-
configure additional hosts.
47-
default: true
48-
ssh-user:
49-
description: >
50-
The user to use when connecting to the remote SSH host. By default 'git' is used.
51-
default: git
52-
persist-credentials:
53-
description: 'Whether to configure the token or SSH key with the local git config'
54-
default: true
55-
path:
56-
description: 'Relative path under $GITHUB_WORKSPACE to place the repository'
57-
clean:
58-
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
59-
default: true
60-
filter:
61-
description: >
62-
Partially clone against a given filter.
63-
Overrides sparse-checkout if set.
64-
default: null
65-
sparse-checkout:
66-
description: >
67-
Do a sparse checkout on given patterns.
68-
Each pattern should be separated with new lines.
69-
default: null
70-
sparse-checkout-cone-mode:
71-
description: >
72-
Specifies whether to use cone-mode when doing a sparse checkout.
73-
default: true
74-
fetch-depth:
75-
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
76-
default: 1
77-
fetch-tags:
78-
description: 'Whether to fetch tags, even if fetch-depth > 0.'
79-
default: false
80-
show-progress:
81-
description: 'Whether to show progress status output when fetching.'
82-
default: true
83-
lfs:
84-
description: 'Whether to download Git-LFS files'
85-
default: false
86-
submodules:
87-
description: >
88-
Whether to checkout submodules: `true` to checkout submodules or `recursive` to
89-
recursively checkout submodules.
90-
91-
92-
When the `ssh-key` input is not provided, SSH URLs beginning with `[email protected]:` are
93-
converted to HTTPS.
94-
default: false
95-
set-safe-directory:
96-
description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`
97-
default: true
98-
github-server-url:
99-
description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com
100-
required: false
101-
outputs:
102-
ref:
103-
description: 'The branch, tag or SHA that was checked out'
104-
commit:
105-
description: 'The commit SHA that was checked out'
106-
runs:
107-
using: node20
108-
main: dist/index.js
109-
post: dist/index.js
1+
name: 'Checkout'
2+
description: 'Checkout a Git repository at a particular version'
3+
inputs:
4+
repository:
5+
description: 'Repository name with owner. For example, actions/checkout'
6+
default: ${{ github.repository }}
7+
ref:
8+
description: >
9+
The branch, tag or SHA to checkout. When checking out the repository that
10+
triggered a workflow, this defaults to the reference or SHA for that
11+
event. Otherwise, uses the default branch.
12+
token:
13+
description: >
14+
Personal access token (PAT) used to fetch the repository. The PAT is configured
15+
with the local git config, which enables your scripts to run authenticated git
16+
commands. The post-job step removes the PAT.
17+
18+
19+
We recommend using a service account with the least permissions necessary.
20+
Also when generating a new PAT, select the least scopes necessary.
21+
22+
23+
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
24+
default: ${{ github.token }}
25+
ssh-key:
26+
description: >
27+
SSH key used to fetch the repository. The SSH key is configured with the local
28+
git config, which enables your scripts to run authenticated git commands.
29+
The post-job step removes the SSH key.
30+
31+
32+
We recommend using a service account with the least permissions necessary.
33+
34+
35+
[Learn more about creating and using
36+
encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
37+
ssh-known-hosts:
38+
description: >
39+
Known hosts in addition to the user and global host key database. The public
40+
SSH keys for a host may be obtained using the utility `ssh-keyscan`. For example,
41+
`ssh-keyscan github.com`. The public key for github.com is always implicitly added.
42+
ssh-strict:
43+
description: >
44+
Whether to perform strict host key checking. When true, adds the options `StrictHostKeyChecking=yes`
45+
and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to
46+
configure additional hosts.
47+
default: true
48+
ssh-user:
49+
description: >
50+
The user to use when connecting to the remote SSH host. By default 'git' is used.
51+
default: git
52+
persist-credentials:
53+
description: 'Whether to configure the token or SSH key with the local git config'
54+
default: true
55+
path:
56+
description: 'Relative path under $GITHUB_WORKSPACE to place the repository'
57+
clean:
58+
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
59+
default: true
60+
filter:
61+
description: >
62+
Partially clone against a given filter.
63+
Overrides sparse-checkout if set.
64+
default: null
65+
sparse-checkout:
66+
description: >
67+
Do a sparse checkout on given patterns.
68+
Each pattern should be separated with new lines.
69+
default: null
70+
sparse-checkout-cone-mode:
71+
description: >
72+
Specifies whether to use cone-mode when doing a sparse checkout.
73+
default: true
74+
fetch-depth:
75+
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
76+
default: 1
77+
fetch-tags:
78+
description: 'Whether to fetch tags, even if fetch-depth > 0.'
79+
default: false
80+
show-progress:
81+
description: 'Whether to show progress status output when fetching.'
82+
default: true
83+
lfs:
84+
description: 'Whether to download Git-LFS files'
85+
default: false
86+
submodules:
87+
description: >
88+
Whether to checkout submodules: `true` to checkout submodules or `recursive` to
89+
recursively checkout submodules.
90+
91+
92+
When the `ssh-key` input is not provided, SSH URLs beginning with `[email protected]:` are
93+
converted to HTTPS.
94+
default: false
95+
set-safe-directory:
96+
description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`
97+
default: true
98+
github-server-url:
99+
description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com
100+
required: false
101+
bare:
102+
description: 'Whether to clone the repository as a bare repository'
103+
default: false
104+
outputs:
105+
ref:
106+
description: 'The branch, tag or SHA that was checked out'
107+
commit:
108+
description: 'The commit SHA that was checked out'
109+
runs:
110+
using: node20
111+
main: dist/index.js
112+
post: dist/index.js

Diff for: src/git-source-provider.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
110110
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
111111
) {
112112
core.startGroup('Initializing the repository')
113-
await git.init()
113+
const initArgs = ['init']
114+
if (settings.bare) {
115+
initArgs.push('--bare')
116+
}
117+
await git.execGit(initArgs)
114118
await git.remoteAdd('origin', repositoryUrl)
115119
core.endGroup()
116120
}

0 commit comments

Comments
 (0)