mirror of
https://github.com/actions/checkout.git
synced 2026-06-14 16:53:47 +08:00
feat: Honor preserve-local-changes flag when repository URL changes
Makes preserve-local-changes option work consistently in all scenarios, including when repository URL changes. Updates warning message to correctly reflect this behavior.
This commit is contained in:
@@ -122,6 +122,20 @@ export async function prepareExistingDirectory(
|
||||
}
|
||||
}
|
||||
|
||||
// Check repository conditions
|
||||
let isLocalGitRepo = git && fsHelper.directoryExistsSync(path.join(repositoryPath, '.git'));
|
||||
let repoUrl = isLocalGitRepo ? await git?.tryGetFetchUrl() : '';
|
||||
let isSameRepository = repositoryUrl === repoUrl;
|
||||
let differentRepoUrl = !isSameRepository;
|
||||
|
||||
// Repository URL has changed
|
||||
if (differentRepoUrl) {
|
||||
if (preserveLocalChanges) {
|
||||
core.warning(`Repository URL has changed from '${repoUrl}' to '${repositoryUrl}'. Local changes will be preserved as requested.`);
|
||||
}
|
||||
remove = true; // Mark for removal, but actual removal will respect preserveLocalChanges
|
||||
}
|
||||
|
||||
if (remove && !preserveLocalChanges) {
|
||||
// Delete the contents of the directory. Don't delete the directory itself
|
||||
// since it might be the current working directory.
|
||||
|
||||
Reference in New Issue
Block a user