1
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2024-12-23 04:05:59 +01:00

Add bare option to checkout action

Fixes #603
This commit is contained in:
Mohammad Ismail 2024-11-27 13:44:30 +01:00
parent cbb722410c
commit 83f93bf255
4 changed files with 159 additions and 110 deletions

View file

@ -126,6 +126,10 @@ 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: ''
# Whether to clone the repository as a bare repository
# Default: false
bare: ''
```
<!-- end usage -->

View file

@ -375,4 +375,42 @@ describe('Test fetchDepth and fetchTags options', () => {
expect.any(Object)
)
})
it('should call execGit with the correct arguments when bare is true', async () => {
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
const workingDirectory = 'test'
const lfs = false
const doSparseCheckout = false
git = await commandManager.createCommandManager(
workingDirectory,
lfs,
doSparseCheckout
)
const refSpec = ['refspec1', 'refspec2']
const options = {
filter: 'filterValue',
bare: true
}
await git.fetch(refSpec, options)
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
[
'-c',
'protocol.version=2',
'fetch',
'--bare',
'--no-tags',
'--prune',
'--no-recurse-submodules',
'--filter=filterValue',
'origin',
'refspec1',
'refspec2'
],
expect.any(Object)
)
})
})

View file

@ -98,6 +98,9 @@ inputs:
github-server-url:
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
required: false
bare:
description: 'Whether to clone the repository as a bare repository'
default: false
outputs:
ref:
description: 'The branch, tag or SHA that was checked out'

View file

@ -110,7 +110,11 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
) {
core.startGroup('Initializing the repository')
await git.init()
const initArgs = ['init']
if (settings.bare) {
initArgs.push('--bare')
}
await git.execGit(initArgs)
await git.remoteAdd('origin', repositoryUrl)
core.endGroup()
}