mirror of
https://github.com/actions/checkout.git
synced 2025-04-01 22:10:06 +02:00
clean-submodules
This commit is contained in:
parent
fc0a6fcb57
commit
1f1d74371e
7 changed files with 41 additions and 13 deletions
|
@ -801,6 +801,7 @@ async function setup(testName: string): Promise<void> {
|
||||||
settings = {
|
settings = {
|
||||||
authToken: 'some auth token',
|
authToken: 'some auth token',
|
||||||
clean: true,
|
clean: true,
|
||||||
|
cleanSubmodules: true,
|
||||||
commit: '',
|
commit: '',
|
||||||
filter: undefined,
|
filter: undefined,
|
||||||
sparseCheckout: [],
|
sparseCheckout: [],
|
||||||
|
|
|
@ -77,6 +77,7 @@ describe('input-helper tests', () => {
|
||||||
expect(settings).toBeTruthy()
|
expect(settings).toBeTruthy()
|
||||||
expect(settings.authToken).toBeFalsy()
|
expect(settings.authToken).toBeFalsy()
|
||||||
expect(settings.clean).toBe(true)
|
expect(settings.clean).toBe(true)
|
||||||
|
expect(settings.cleanSubmodules).toBe(true)
|
||||||
expect(settings.commit).toBeTruthy()
|
expect(settings.commit).toBeTruthy()
|
||||||
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
|
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
|
||||||
expect(settings.filter).toBe(undefined)
|
expect(settings.filter).toBe(undefined)
|
||||||
|
|
|
@ -53,6 +53,9 @@ inputs:
|
||||||
clean:
|
clean:
|
||||||
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
|
description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching'
|
||||||
default: true
|
default: true
|
||||||
|
clean-submodules:
|
||||||
|
description: 'Whether to execute clean task again before fetching submodules'
|
||||||
|
default: true
|
||||||
filter:
|
filter:
|
||||||
description: >
|
description: >
|
||||||
Partially clone against a given filter.
|
Partially clone against a given filter.
|
||||||
|
|
|
@ -89,21 +89,11 @@ export async function prepareExistingDirectory(
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
if (clean) {
|
if (clean) {
|
||||||
core.startGroup('Cleaning the repository')
|
if (!(await cleanExistingDirectory(git, repositoryPath))) {
|
||||||
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) {
|
|
||||||
core.warning(
|
core.warning(
|
||||||
`Unable to clean or reset the repository. The repository will be recreated instead.`
|
`Unable to clean or reset the repository. The repository will be recreated instead.`
|
||||||
)
|
)
|
||||||
|
remove = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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
|
||||||
|
}
|
|
@ -230,6 +230,11 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
await authHelper.configureGlobalAuth()
|
await authHelper.configureGlobalAuth()
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
|
if (settings.cleanSubmodules) {
|
||||||
|
core.info('Cleaning the repository again before fetching submodules')
|
||||||
|
await gitDirectoryHelper.cleanExistingDirectory(git, settings.repositoryPath)
|
||||||
|
}
|
||||||
|
|
||||||
// Checkout submodules
|
// Checkout submodules
|
||||||
core.startGroup('Fetching submodules')
|
core.startGroup('Fetching submodules')
|
||||||
await git.submoduleSync(settings.nestedSubmodules)
|
await git.submoduleSync(settings.nestedSubmodules)
|
||||||
|
|
|
@ -25,10 +25,15 @@ export interface IGitSourceSettings {
|
||||||
commit: string
|
commit: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether to clean the repository
|
* Indicates whether to clean the repository before fetching
|
||||||
*/
|
*/
|
||||||
clean: boolean
|
clean: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether to clean the repository before fetching submodules
|
||||||
|
*/
|
||||||
|
cleanSubmodules: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The filter determining which objects to include
|
* The filter determining which objects to include
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -82,6 +82,10 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||||
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
|
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
|
||||||
core.debug(`clean = ${result.clean}`)
|
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
|
// Filter
|
||||||
const filter = core.getInput('filter')
|
const filter = core.getInput('filter')
|
||||||
if (filter) {
|
if (filter) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue