mirror of
https://github.com/actions/checkout.git
synced 2025-03-14 10:07:00 +00:00
Add clean-exclude input
This allows clients to ignore specific paths from the clean phase of the checkout.
This commit is contained in:
parent
925b9fdcfa
commit
0f6c54dea3
8 changed files with 38 additions and 9 deletions
|
@ -74,6 +74,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
|
||||||
# Default: true
|
# Default: true
|
||||||
clean: ''
|
clean: ''
|
||||||
|
|
||||||
|
# Comma separated paths to exclude when executing `git clean -ffdx`
|
||||||
|
# Default:
|
||||||
|
clean-exclude: ''
|
||||||
|
|
||||||
# Number of commits to fetch. 0 indicates all history for all branches and tags.
|
# Number of commits to fetch. 0 indicates all history for all branches and tags.
|
||||||
# Default: 1
|
# Default: 1
|
||||||
fetch-depth: ''
|
fetch-depth: ''
|
||||||
|
|
|
@ -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-exclude:
|
||||||
|
description: 'Comma separated paths to exclude when executing `git clean -ffdx`'
|
||||||
|
default: ''
|
||||||
fetch-depth:
|
fetch-depth:
|
||||||
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
|
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
|
||||||
default: 1
|
default: 1
|
||||||
|
|
17
dist/index.js
vendored
17
dist/index.js
vendored
|
@ -7608,9 +7608,14 @@ class GitCommandManager {
|
||||||
return !!output.stdout.trim();
|
return !!output.stdout.trim();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
tryClean() {
|
tryClean(exclude) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const output = yield this.execGit(['clean', '-ffdx'], true);
|
var cleanArgs = [];
|
||||||
|
for (const pattern of exclude) {
|
||||||
|
cleanArgs.push('-e');
|
||||||
|
cleanArgs.push(pattern);
|
||||||
|
}
|
||||||
|
const output = yield this.execGit(['clean', '-ffdx', ...cleanArgs], true);
|
||||||
return output.exitCode === 0;
|
return output.exitCode === 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9290,7 +9295,7 @@ const fs = __importStar(__webpack_require__(747));
|
||||||
const fsHelper = __importStar(__webpack_require__(618));
|
const fsHelper = __importStar(__webpack_require__(618));
|
||||||
const io = __importStar(__webpack_require__(1));
|
const io = __importStar(__webpack_require__(1));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean, ref) {
|
function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean, cleanExclude, ref) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
assert.ok(repositoryPath, 'Expected repositoryPath to be defined');
|
assert.ok(repositoryPath, 'Expected repositoryPath to be defined');
|
||||||
|
@ -9354,7 +9359,7 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean, ref
|
||||||
// Clean
|
// Clean
|
||||||
if (clean) {
|
if (clean) {
|
||||||
core.startGroup('Cleaning the repository');
|
core.startGroup('Cleaning the repository');
|
||||||
if (!(yield git.tryClean())) {
|
if (!(yield 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}'.`);
|
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}'.`);
|
||||||
remove = true;
|
remove = true;
|
||||||
}
|
}
|
||||||
|
@ -18447,6 +18452,8 @@ function getInputs() {
|
||||||
// Clean
|
// Clean
|
||||||
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}`);
|
||||||
|
result.cleanExclude = (core.getInput('clean-exclude') || '').split(',');
|
||||||
|
core.debug(`cleanExclude = ${JSON.stringify(result.cleanExclude)}`);
|
||||||
// Fetch depth
|
// Fetch depth
|
||||||
result.fetchDepth = Math.floor(Number(core.getInput('fetch-depth') || '1'));
|
result.fetchDepth = Math.floor(Number(core.getInput('fetch-depth') || '1'));
|
||||||
if (isNaN(result.fetchDepth) || result.fetchDepth < 0) {
|
if (isNaN(result.fetchDepth) || result.fetchDepth < 0) {
|
||||||
|
@ -31850,7 +31857,7 @@ function getSource(settings) {
|
||||||
}
|
}
|
||||||
// Prepare existing directory, otherwise recreate
|
// Prepare existing directory, otherwise recreate
|
||||||
if (isExisting) {
|
if (isExisting) {
|
||||||
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean, settings.ref);
|
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean, settings.cleanExclude, settings.ref);
|
||||||
}
|
}
|
||||||
if (!git) {
|
if (!git) {
|
||||||
// Downloading using REST API
|
// Downloading using REST API
|
||||||
|
|
|
@ -42,7 +42,7 @@ export interface IGitCommandManager {
|
||||||
submoduleSync(recursive: boolean): Promise<void>
|
submoduleSync(recursive: boolean): Promise<void>
|
||||||
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
|
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
|
||||||
tagExists(pattern: string): Promise<boolean>
|
tagExists(pattern: string): Promise<boolean>
|
||||||
tryClean(): Promise<boolean>
|
tryClean(exclude: string[]): Promise<boolean>
|
||||||
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
|
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
|
||||||
tryDisableAutomaticGarbageCollection(): Promise<boolean>
|
tryDisableAutomaticGarbageCollection(): Promise<boolean>
|
||||||
tryGetFetchUrl(): Promise<string>
|
tryGetFetchUrl(): Promise<string>
|
||||||
|
@ -331,8 +331,14 @@ class GitCommandManager {
|
||||||
return !!output.stdout.trim()
|
return !!output.stdout.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
async tryClean(): Promise<boolean> {
|
async tryClean(exclude: string[]): Promise<boolean> {
|
||||||
const output = await this.execGit(['clean', '-ffdx'], true)
|
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
|
return output.exitCode === 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ export async function prepareExistingDirectory(
|
||||||
repositoryPath: string,
|
repositoryPath: string,
|
||||||
repositoryUrl: string,
|
repositoryUrl: string,
|
||||||
clean: boolean,
|
clean: boolean,
|
||||||
|
cleanExclude: string[],
|
||||||
ref: string
|
ref: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
|
assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
|
||||||
|
@ -84,7 +85,7 @@ export async function prepareExistingDirectory(
|
||||||
// Clean
|
// Clean
|
||||||
if (clean) {
|
if (clean) {
|
||||||
core.startGroup('Cleaning the repository')
|
core.startGroup('Cleaning the repository')
|
||||||
if (!(await git.tryClean())) {
|
if (!(await git.tryClean(cleanExclude))) {
|
||||||
core.debug(
|
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}'.`
|
`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}'.`
|
||||||
)
|
)
|
||||||
|
|
|
@ -68,6 +68,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
settings.repositoryPath,
|
settings.repositoryPath,
|
||||||
repositoryUrl,
|
repositoryUrl,
|
||||||
settings.clean,
|
settings.clean,
|
||||||
|
settings.cleanExclude,
|
||||||
settings.ref
|
settings.ref
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,11 @@ export interface IGitSourceSettings {
|
||||||
*/
|
*/
|
||||||
clean: boolean
|
clean: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paths to ignore when cleaning the repository
|
||||||
|
*/
|
||||||
|
cleanExclude: string[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The depth when fetching
|
* The depth when fetching
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -81,6 +81,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||||
// Clean
|
// Clean
|
||||||
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}`)
|
||||||
|
result.cleanExclude = (core.getInput('clean-exclude') || '').split(',')
|
||||||
|
core.debug(`cleanExclude = ${JSON.stringify(result.cleanExclude)}`)
|
||||||
|
|
||||||
// Fetch depth
|
// Fetch depth
|
||||||
result.fetchDepth = Math.floor(Number(core.getInput('fetch-depth') || '1'))
|
result.fetchDepth = Math.floor(Number(core.getInput('fetch-depth') || '1'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue