Allow git clone command to also always use the cache (#274354)

* Allow git clone command to also always use the cache

* Fix redundant checks
This commit is contained in:
Alex Ross
2025-11-02 19:27:13 +01:00
committed by GitHub
parent 16b9d1ba2a
commit a2a6d74b9f
2 changed files with 10 additions and 9 deletions

View File

@@ -27,15 +27,7 @@ export class CloneManager {
private readonly telemetryReporter: TelemetryReporter,
private readonly repositoryCache: RepositoryCache) { }
clone(url?: string, options: CloneOptions = {}) {
const cachedRepository = url ? this.repositoryCache.get(url) : undefined;
if (url && cachedRepository && (cachedRepository.length > 0)) {
return this.tryOpenExistingRepository(cachedRepository, url, options.postCloneAction, options.parentPath, options.ref);
}
return this.cloneRepository(url, options.parentPath, options);
}
private async cloneRepository(url?: string, parentPath?: string, options: { recursive?: boolean; ref?: string; postCloneAction?: ApiPostCloneAction } = {}): Promise<string | undefined> {
async clone(url?: string, options: CloneOptions = {}) {
if (!url || typeof url !== 'string') {
url = await pickRemoteSource({
providerLabel: provider => l10n.t('Clone from {0}', provider.name),
@@ -56,6 +48,14 @@ export class CloneManager {
url = url.trim().replace(/^git\s+clone\s+/, '');
const cachedRepository = this.repositoryCache.get(url);
if (cachedRepository && (cachedRepository.length > 0)) {
return this.tryOpenExistingRepository(cachedRepository, url, options.postCloneAction, options.parentPath, options.ref);
}
return this.cloneRepository(url, options.parentPath, options);
}
private async cloneRepository(url: string, parentPath?: string, options: { recursive?: boolean; ref?: string; postCloneAction?: ApiPostCloneAction } = {}): Promise<string | undefined> {
if (!parentPath) {
const config = workspace.getConfiguration('git');
let defaultCloneDirectory = config.get<string>('defaultCloneDirectory') || os.homedir();