From 0f1904834ba4d85ea4700ae24794de54ff03335e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Thu, 22 Oct 2020 21:12:13 +0200 Subject: [PATCH] :lipstick: --- extensions/git/package.json | 11 +++-------- extensions/git/package.nls.json | 2 +- extensions/git/src/commands.ts | 12 ++++++------ extensions/git/src/git.ts | 20 +++++++++++++------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index a54b8a6270b..502561836ba 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -39,8 +39,8 @@ "category": "Git" }, { - "command": "git.cloneRecursively", - "title": "%command.cloneRecursively%", + "command": "git.cloneRecursive", + "title": "%command.cloneRecursive%", "category": "Git" }, { @@ -501,7 +501,7 @@ "when": "config.git.enabled && !git.missing" }, { - "command": "git.cloneRecursively", + "command": "git.cloneRecursive", "when": "config.git.enabled && !git.missing" }, { @@ -894,11 +894,6 @@ "command": "git.showOutput", "group": "3_footer", "when": "scmProvider == git" - }, - { - "command": "git.cloneRecursively", - "group": "3_footer", - "when": "scmProvider == git" } ], "scm/sourceControl": [ diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 7c03ca7c31d..822954e8dd9 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -3,7 +3,7 @@ "description": "Git SCM Integration", "command.setLogLevel": "Set Log Level...", "command.clone": "Clone", - "command.cloneRecursively": "Clone Recursively", + "command.cloneRecursive": "Clone (Recursive)", "command.init": "Initialize Repository", "command.openRepository": "Open Repository", "command.close": "Close Repository", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 6b04758716a..e3d74d8c5e9 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -458,7 +458,7 @@ export class CommandCenter { } } - async cloneRepository(url?: string, parentPath?: string, shouldRecurse?: boolean): Promise { + async cloneRepository(url?: string, parentPath?: string, options: { recursive?: boolean } = {}): Promise { if (!url || typeof url !== 'string') { url = await pickRemoteSource(this.model, { providerLabel: provider => localize('clonefrom', "Clone from {0}", provider.name), @@ -514,7 +514,7 @@ export class CommandCenter { const repositoryPath = await window.withProgress( opts, - (progress, token) => this.git.clone(url!, parentPath!, progress, token, shouldRecurse) + (progress, token) => this.git.clone(url!, { parentPath: parentPath!, progress, recursive: options.recursive }, token) ); let message = localize('proposeopen', "Would you like to open the cloned repository?"); @@ -573,12 +573,12 @@ export class CommandCenter { @command('git.clone') async clone(url?: string, parentPath?: string): Promise { - this.cloneRepository(url, parentPath, false); + this.cloneRepository(url, parentPath); } - @command('git.cloneRecursively') - async cloneRecursively(url?: string, parentPath?: string): Promise { - this.cloneRepository(url, parentPath, true); + @command('git.cloneRecursive') + async cloneRecursive(url?: string, parentPath?: string): Promise { + this.cloneRepository(url, parentPath, { recursive: true }); } @command('git.init') diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index be2595ce0a9..80067437615 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -351,6 +351,12 @@ function sanitizePath(path: string): string { const COMMIT_FORMAT = '%H%n%aN%n%aE%n%at%n%ct%n%P%n%B'; +export interface ICloneOptions { + readonly parentPath: string; + readonly progress: Progress<{ increment: number }>; + readonly recursive?: boolean; +} + export class Git { readonly path: string; @@ -373,18 +379,18 @@ export class Git { return; } - async clone(url: string, parentPath: string, progress: Progress<{ increment: number }>, cancellationToken?: CancellationToken, shouldRecurse?: boolean): Promise { + async clone(url: string, options: ICloneOptions, cancellationToken?: CancellationToken): Promise { let baseFolderName = decodeURI(url).replace(/[\/]+$/, '').replace(/^.*[\/\\]/, '').replace(/\.git$/, '') || 'repository'; let folderName = baseFolderName; - let folderPath = path.join(parentPath, folderName); + let folderPath = path.join(options.parentPath, folderName); let count = 1; while (count < 20 && await new Promise(c => exists(folderPath, c))) { folderName = `${baseFolderName}-${count++}`; - folderPath = path.join(parentPath, folderName); + folderPath = path.join(options.parentPath, folderName); } - await mkdirp(parentPath); + await mkdirp(options.parentPath); const onSpawn = (child: cp.ChildProcess) => { const decoder = new StringDecoder('utf8'); @@ -408,7 +414,7 @@ export class Git { } if (totalProgress !== previousProgress) { - progress.report({ increment: totalProgress - previousProgress }); + options.progress.report({ increment: totalProgress - previousProgress }); previousProgress = totalProgress; } }); @@ -416,10 +422,10 @@ export class Git { try { let command = ['clone', url.includes(' ') ? encodeURI(url) : url, folderPath, '--progress']; - if (shouldRecurse) { + if (options.recursive) { command.push('--recursive'); } - await this.exec(parentPath, command, { cancellationToken, onSpawn }); + await this.exec(options.parentPath, command, { cancellationToken, onSpawn }); } catch (err) { if (err.stderr) { err.stderr = err.stderr.replace(/^Cloning.+$/m, '').trim(); -- GitLab