Skip to content

Commit

Permalink
Revert "Pass folder and branch to clone command" (che-incubator#1)
Browse files Browse the repository at this point in the history
This reverts commit 037f3e4.
  • Loading branch information
vinokurig authored Jul 10, 2019
1 parent 037f3e4 commit ed98620
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
84 changes: 48 additions & 36 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export class CommandCenter {
}

@command('git.clone')
async clone(url?: string, folder?: string, branch?: string): Promise<void> {
async clone(url?: string): Promise<void> {
if (!url) {
url = await window.showInputBox({
prompt: localize('repourl', "Repository URL"),
Expand All @@ -408,37 +408,25 @@ export class CommandCenter {
let defaultCloneDirectory = config.get<string>('defaultCloneDirectory') || os.homedir();
defaultCloneDirectory = defaultCloneDirectory.replace(/^~/, os.homedir());

let uri: Uri;
if (folder) {
uri = Uri.file(folder);
} else {
const folders = workspace.workspaceFolders;
if (folders && folders[0]) {
const repoName = decodeURI(url).replace(/^.*\//, '').replace(/\.git$/, '') || 'repository';
uri = Uri.parse(path.join(folders[0].uri.fsPath, repoName));
} else {
const uris = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(defaultCloneDirectory),
openLabel: localize('selectFolder', "Select Repository Location")
});
const uris = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(defaultCloneDirectory),
openLabel: localize('selectFolder', "Select Repository Location")
});

if (!uris || uris.length === 0) {
/* __GDPR__
"clone" : {
"outcome" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.telemetryReporter.sendTelemetryEvent('clone', { outcome: 'no_directory' });
return;
if (!uris || uris.length === 0) {
/* __GDPR__
"clone" : {
"outcome" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}

uri = uris[0];
}
*/
this.telemetryReporter.sendTelemetryEvent('clone', { outcome: 'no_directory' });
return;
}

const uri = uris[0];
const parentPath = uri.fsPath;

try {
Expand All @@ -448,16 +436,40 @@ export class CommandCenter {
cancellable: true
};

await window.withProgress(
const repositoryPath = await window.withProgress(
opts,
async (_, token) => {
const result = await this.git.clone(url!, parentPath, token);
if (branch) {
await this.git.exec(parentPath, ['checkout', branch], { cancellationToken: token });
}
return result;
}
(_, token) => this.git.clone(url!, parentPath, token)
);

const choices = [];
let message = localize('proposeopen', "Would you like to open the cloned repository?");
const open = localize('openrepo', "Open Repository");
choices.push(open);

const addToWorkspace = localize('add', "Add to Workspace");
if (workspace.workspaceFolders) {
message = localize('proposeopen2', "Would you like to open the cloned repository, or add it to the current workspace?");
choices.push(addToWorkspace);
}

const result = await window.showInformationMessage(message, ...choices);

const openFolder = result === open;
/* __GDPR__
"clone" : {
"outcome" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"openFolder": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true }
}
*/
this.telemetryReporter.sendTelemetryEvent('clone', { outcome: 'success' }, { openFolder: openFolder ? 1 : 0 });

const uri = Uri.file(repositoryPath);

if (openFolder) {
commands.executeCommand('vscode.openFolder', uri);
} else if (result === addToWorkspace) {
workspace.updateWorkspaceFolders(workspace.workspaceFolders!.length, 0, { uri });
}
} catch (err) {
if (/already exists and is not an empty directory/.test(err && err.stderr || '')) {
/* __GDPR__
Expand Down
2 changes: 1 addition & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class Git {
await mkdirp(parentPath);

try {
await this.exec(parentPath.substring(0, parentPath.lastIndexOf('/') + 1), ['clone', url, parentPath], { cancellationToken });
await this.exec(parentPath, ['clone', url, folderPath], { cancellationToken });
} catch (err) {
if (err.stderr) {
err.stderr = err.stderr.replace(/^Cloning.+$/m, '').trim();
Expand Down

0 comments on commit ed98620

Please sign in to comment.