未验证 提交 0f190483 编写于 作者: J João Moreno

💄

上级 990c0284
......@@ -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": [
......
......@@ -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",
......
......@@ -458,7 +458,7 @@ export class CommandCenter {
}
}
async cloneRepository(url?: string, parentPath?: string, shouldRecurse?: boolean): Promise<void> {
async cloneRepository(url?: string, parentPath?: string, options: { recursive?: boolean } = {}): Promise<void> {
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<void> {
this.cloneRepository(url, parentPath, false);
this.cloneRepository(url, parentPath);
}
@command('git.cloneRecursively')
async cloneRecursively(url?: string, parentPath?: string): Promise<void> {
this.cloneRepository(url, parentPath, true);
@command('git.cloneRecursive')
async cloneRecursive(url?: string, parentPath?: string): Promise<void> {
this.cloneRepository(url, parentPath, { recursive: true });
}
@command('git.init')
......
......@@ -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<string> {
async clone(url: string, options: ICloneOptions, cancellationToken?: CancellationToken): Promise<string> {
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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册