1
0
Fork 0
mirror of https://github.com/actions/checkout.git synced 2025-03-28 11:00:05 +01:00

clean-submodules

This commit is contained in:
Hazel 2024-01-29 15:54:16 +00:00
parent fc0a6fcb57
commit 1f1d74371e
No known key found for this signature in database
GPG key ID: C7C5A3D1A085B70F
7 changed files with 41 additions and 13 deletions

View file

@ -801,6 +801,7 @@ async function setup(testName: string): Promise<void> {
settings = {
authToken: 'some auth token',
clean: true,
cleanSubmodules: true,
commit: '',
filter: undefined,
sparseCheckout: [],

View file

@ -77,6 +77,7 @@ describe('input-helper tests', () => {
expect(settings).toBeTruthy()
expect(settings.authToken).toBeFalsy()
expect(settings.clean).toBe(true)
expect(settings.cleanSubmodules).toBe(true)
expect(settings.commit).toBeTruthy()
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
expect(settings.filter).toBe(undefined)

View file

@ -53,6 +53,9 @@ inputs:
clean:
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
default: true
clean-submodules:
description: 'Whether to execute clean task again before fetching submodules'
default: true
filter:
description: >
Partially clone against a given filter.

View file

@ -89,21 +89,11 @@ export async function prepareExistingDirectory(
// Clean
if (clean) {
core.startGroup('Cleaning the repository')
if (!(await git.tryClean())) {
core.debug(
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For further investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
)
remove = true
} else if (!(await git.tryReset())) {
remove = true
}
core.endGroup()
if (remove) {
if (!(await cleanExistingDirectory(git, repositoryPath))) {
core.warning(
`Unable to clean or reset the repository. The repository will be recreated instead.`
)
remove = true
}
}
} catch (error) {
@ -123,3 +113,22 @@ export async function prepareExistingDirectory(
}
}
}
export async function cleanExistingDirectory(git: IGitCommandManager, repositoryPath: string) {
core.startGroup('Cleaning the repository')
if (!(await git.tryClean())) {
core.debug(
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For further investigation, manually run 'git clean -ffdx --recurse-submodules' on the directory '${repositoryPath}'.`
)
return false
}
if (!(await git.tryReset())) {
return false
}
core.endGroup()
return true
}

View file

@ -230,6 +230,11 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
await authHelper.configureGlobalAuth()
core.endGroup()
if (settings.cleanSubmodules) {
core.info('Cleaning the repository again before fetching submodules')
await gitDirectoryHelper.cleanExistingDirectory(git, settings.repositoryPath)
}
// Checkout submodules
core.startGroup('Fetching submodules')
await git.submoduleSync(settings.nestedSubmodules)

View file

@ -25,10 +25,15 @@ export interface IGitSourceSettings {
commit: string
/**
* Indicates whether to clean the repository
* Indicates whether to clean the repository before fetching
*/
clean: boolean
/**
* Indicates whether to clean the repository before fetching submodules
*/
cleanSubmodules: boolean
/**
* The filter determining which objects to include
*/

View file

@ -82,6 +82,10 @@ export async function getInputs(): Promise<IGitSourceSettings> {
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
core.debug(`clean = ${result.clean}`)
// Clean
result.cleanSubmodules = (core.getInput('clean-submodules') || core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
core.debug(`clean-submodules = ${result.clean}`)
// Filter
const filter = core.getInput('filter')
if (filter) {