Add clean-exclude input

This allows clients to ignore specific paths from the clean phase of the
checkout.
This commit is contained in:
Matthew Endsley 2022-10-28 20:20:33 -07:00
parent 925b9fdcfa
commit 0f6c54dea3
8 changed files with 38 additions and 9 deletions

View file

@ -42,7 +42,7 @@ export interface IGitCommandManager {
submoduleSync(recursive: boolean): Promise<void>
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
tagExists(pattern: string): Promise<boolean>
tryClean(): Promise<boolean>
tryClean(exclude: string[]): Promise<boolean>
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
tryDisableAutomaticGarbageCollection(): Promise<boolean>
tryGetFetchUrl(): Promise<string>
@ -331,8 +331,14 @@ class GitCommandManager {
return !!output.stdout.trim()
}
async tryClean(): Promise<boolean> {
const output = await this.execGit(['clean', '-ffdx'], true)
async tryClean(exclude: string[]): Promise<boolean> {
var cleanArgs: string[] = []
for (const pattern of exclude) {
cleanArgs.push('-e')
cleanArgs.push(pattern)
}
const output = await this.execGit(['clean', '-ffdx', ...cleanArgs], true)
return output.exitCode === 0
}

View file

@ -11,6 +11,7 @@ export async function prepareExistingDirectory(
repositoryPath: string,
repositoryUrl: string,
clean: boolean,
cleanExclude: string[],
ref: string
): Promise<void> {
assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
@ -84,7 +85,7 @@ export async function prepareExistingDirectory(
// Clean
if (clean) {
core.startGroup('Cleaning the repository')
if (!(await git.tryClean())) {
if (!(await git.tryClean(cleanExclude))) {
core.debug(
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
)

View file

@ -68,6 +68,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
settings.repositoryPath,
repositoryUrl,
settings.clean,
settings.cleanExclude,
settings.ref
)
}

View file

@ -29,6 +29,11 @@ export interface IGitSourceSettings {
*/
clean: boolean
/**
* Paths to ignore when cleaning the repository
*/
cleanExclude: string[]
/**
* The depth when fetching
*/

View file

@ -81,6 +81,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
// Clean
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
core.debug(`clean = ${result.clean}`)
result.cleanExclude = (core.getInput('clean-exclude') || '').split(',')
core.debug(`cleanExclude = ${JSON.stringify(result.cleanExclude)}`)
// Fetch depth
result.fetchDepth = Math.floor(Number(core.getInput('fetch-depth') || '1'))