mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
create _git.clone command
This commit is contained in:
@@ -169,16 +169,26 @@ export class CommandCenter {
|
||||
return '';
|
||||
}
|
||||
|
||||
@command('git.clone')
|
||||
async clone(telemetryData: { [key: string]: any }): Promise<void> {
|
||||
/**
|
||||
* Attempts to clone a git repository. Throws descriptive errors
|
||||
* for usual error cases. Returns whether the user chose to open
|
||||
* the resulting folder or otherwise.
|
||||
*
|
||||
* This only exists for the walkthrough contribution to have good
|
||||
* telemetry.
|
||||
*
|
||||
* TODO@Christof: when all the telemetry questions are answered,
|
||||
* please clean this up into a single clone method.
|
||||
*/
|
||||
@command('_git.clone')
|
||||
async _clone(): Promise<boolean> {
|
||||
const url = await window.showInputBox({
|
||||
prompt: localize('repourl', "Repository URL"),
|
||||
ignoreFocusOut: true
|
||||
});
|
||||
|
||||
if (!url) {
|
||||
this.telemetryReporter.sendTelemetryEvent('clone', { ...telemetryData, outcome: 'no_URL' });
|
||||
return;
|
||||
throw new Error('no_URL');
|
||||
}
|
||||
|
||||
const parentPath = await window.showInputBox({
|
||||
@@ -188,32 +198,41 @@ export class CommandCenter {
|
||||
});
|
||||
|
||||
if (!parentPath) {
|
||||
this.telemetryReporter.sendTelemetryEvent('clone', { ...telemetryData, outcome: 'no_directory' });
|
||||
return;
|
||||
throw new Error('no_directory');
|
||||
}
|
||||
|
||||
const clonePromise = this.model.git.clone(url, parentPath);
|
||||
window.setStatusBarMessage(localize('cloning', "Cloning git repository..."), clonePromise);
|
||||
let repositoryPath: string;
|
||||
|
||||
try {
|
||||
const repositoryPath = await clonePromise;
|
||||
|
||||
const open = localize('openrepo', "Open Repository");
|
||||
const result = await window.showInformationMessage(localize('proposeopen', "Would you like to open the cloned repository?"), open);
|
||||
|
||||
const openFolder = result === open;
|
||||
this.telemetryReporter.sendTelemetryEvent('clone', { ...telemetryData, outcome: 'success' }, { openFolder: openFolder ? 1 : 0 });
|
||||
if (openFolder) {
|
||||
commands.executeCommand('vscode.openFolder', Uri.file(repositoryPath));
|
||||
}
|
||||
repositoryPath = await clonePromise;
|
||||
} catch (err) {
|
||||
if (/already exists and is not an empty directory/.test(err && err.stderr || '')) {
|
||||
this.telemetryReporter.sendTelemetryEvent('clone', { ...telemetryData, outcome: 'directory_not_empty' });
|
||||
} else {
|
||||
this.telemetryReporter.sendTelemetryEvent('clone', { ...telemetryData, outcome: 'error' });
|
||||
throw new Error('directory_not_empty');
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
const open = localize('openrepo', "Open Repository");
|
||||
const result = await window.showInformationMessage(localize('proposeopen', "Would you like to open the cloned repository?"), open);
|
||||
const openFolder = result === open;
|
||||
|
||||
if (openFolder) {
|
||||
commands.executeCommand('vscode.openFolder', Uri.file(repositoryPath));
|
||||
}
|
||||
|
||||
return openFolder;
|
||||
}
|
||||
|
||||
@command('git.clone')
|
||||
async clone(): Promise<void> {
|
||||
try {
|
||||
await this._clone();
|
||||
} catch (err) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
@command('git.init')
|
||||
|
||||
Reference in New Issue
Block a user