mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-08-14 17:30:50 +00:00
update
This commit is contained in:
parent
ebd82bae91
commit
6503dcd44c
3 changed files with 41 additions and 7 deletions
|
@ -11,13 +11,19 @@ export async function prepareExistingDirectory(
|
|||
repositoryPath: string,
|
||||
repositoryUrl: string,
|
||||
clean: boolean,
|
||||
ref: string
|
||||
ref: string,
|
||||
preserveLocalChanges: boolean = false
|
||||
): Promise<void> {
|
||||
assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
|
||||
assert.ok(repositoryUrl, 'Expected repositoryUrl to be defined')
|
||||
|
||||
// Indicates whether to delete the directory contents
|
||||
let remove = false
|
||||
|
||||
// If preserveLocalChanges is true, log it
|
||||
if (preserveLocalChanges) {
|
||||
core.info(`Preserve local changes is enabled, will attempt to keep local files`)
|
||||
}
|
||||
|
||||
// Check whether using git or REST API
|
||||
if (!git) {
|
||||
|
@ -114,12 +120,23 @@ export async function prepareExistingDirectory(
|
|||
}
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
if (remove && !preserveLocalChanges) {
|
||||
// Delete the contents of the directory. Don't delete the directory itself
|
||||
// since it might be the current working directory.
|
||||
core.info(`Deleting the contents of '${repositoryPath}'`)
|
||||
for (const file of await fs.promises.readdir(repositoryPath)) {
|
||||
// Skip .git directory as we need it to determine if a file is tracked
|
||||
if (file === '.git') {
|
||||
continue
|
||||
}
|
||||
await io.rmRF(path.join(repositoryPath, file))
|
||||
}
|
||||
} else if (remove && preserveLocalChanges) {
|
||||
core.info(`Skipping deletion of directory contents due to preserve-local-changes setting`)
|
||||
// We still need to make sure we have a git repository to work with
|
||||
if (!git) {
|
||||
core.info(`Initializing git repository to prepare for checkout with preserved changes`)
|
||||
await fs.promises.mkdir(path.join(repositoryPath, '.git'), { recursive: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||
settings.repositoryPath,
|
||||
repositoryUrl,
|
||||
settings.clean,
|
||||
settings.ref
|
||||
settings.ref,
|
||||
settings.preserveLocalChanges
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue