提交 cc712022 编写于 作者: J Joao Moreno

git: clone command

上级 192db5f7
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
}, },
"contributes": { "contributes": {
"commands": [ "commands": [
{
"command": "git.clone",
"title": "%command.clone%",
"category": "Git"
},
{ {
"command": "git.init", "command": "git.init",
"title": "%command.init%", "title": "%command.init%",
......
{ {
"command.init": "Initialize Git Repository", "command.clone": "Clone",
"command.init": "Initialize Repository",
"command.refresh": "Refresh", "command.refresh": "Refresh",
"command.openChange": "Open Change", "command.openChange": "Open Change",
"command.openFile": "Open File", "command.openFile": "Open File",
......
...@@ -10,6 +10,7 @@ import { Ref, RefType } from './git'; ...@@ -10,6 +10,7 @@ import { Ref, RefType } from './git';
import { Model, Resource, Status, CommitOptions } from './model'; import { Model, Resource, Status, CommitOptions } from './model';
import * as staging from './staging'; import * as staging from './staging';
import * as path from 'path'; import * as path from 'path';
import * as os from 'os';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
...@@ -184,6 +185,37 @@ export class CommandCenter { ...@@ -184,6 +185,37 @@ export class CommandCenter {
return ''; return '';
} }
@command('git.clone')
async clone(): Promise<void> {
const url = await window.showInputBox({
prompt: localize('repourl', "Repository URL")
});
if (!url) {
return;
}
const parentPath = await window.showInputBox({
prompt: localize('parent', "Parent Directory"),
value: os.homedir()
});
if (!parentPath) {
return;
}
const clonePromise = this.model.git.clone(url, parentPath);
window.setStatusBarMessage(localize('cloning', "Cloning git repository..."), clonePromise);
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);
if (result === open) {
commands.executeCommand('vscode.openFolder', Uri.file(repositoryPath));
}
}
@command('git.init') @command('git.init')
async init(): Promise<void> { async init(): Promise<void> {
await this.model.init(); await this.model.init();
......
...@@ -289,6 +289,14 @@ export class Git { ...@@ -289,6 +289,14 @@ export class Git {
return new Repository(this, repository, env); return new Repository(this, repository, env);
} }
async clone(url: string, parentPath: string): Promise<string> {
const folderName = url.replace(/^.*\//, '').replace(/\.git$/, '') || 'repository';
const folderPath = path.join(parentPath, folderName);
await this.exec(parentPath, ['clone', url, folderPath]);
return folderPath;
}
async getRepositoryRoot(path: string): Promise<string> { async getRepositoryRoot(path: string): Promise<string> {
const result = await this.exec(path, ['rev-parse', '--show-toplevel']); const result = await this.exec(path, ['rev-parse', '--show-toplevel']);
return result.stdout.trim(); return result.stdout.trim();
......
...@@ -249,6 +249,10 @@ export class Model implements Disposable { ...@@ -249,6 +249,10 @@ export class Model implements Disposable {
return anyEvent(this.onRunOperation as Event<any>, this.onDidRunOperation as Event<any>); return anyEvent(this.onRunOperation as Event<any>, this.onDidRunOperation as Event<any>);
} }
get git(): Git {
return this._git;
}
private _mergeGroup = new MergeGroup([]); private _mergeGroup = new MergeGroup([]);
get mergeGroup(): MergeGroup { return this._mergeGroup; } get mergeGroup(): MergeGroup { return this._mergeGroup; }
...@@ -314,7 +318,7 @@ export class Model implements Disposable { ...@@ -314,7 +318,7 @@ export class Model implements Disposable {
private disposables: Disposable[] = []; private disposables: Disposable[] = [];
constructor( constructor(
private git: Git, private _git: Git,
private rootPath: string, private rootPath: string,
private askpass: Askpass private askpass: Askpass
) { ) {
...@@ -497,9 +501,9 @@ export class Model implements Disposable { ...@@ -497,9 +501,9 @@ export class Model implements Disposable {
this.repositoryDisposable.dispose(); this.repositoryDisposable.dispose();
const disposables: Disposable[] = []; const disposables: Disposable[] = [];
const repositoryRoot = await this.git.getRepositoryRoot(this.rootPath); const repositoryRoot = await this._git.getRepositoryRoot(this.rootPath);
const askpassEnv = await this.askpass.getEnv(); const askpassEnv = await this.askpass.getEnv();
this.repository = this.git.open(repositoryRoot, askpassEnv); this.repository = this._git.open(repositoryRoot, askpassEnv);
const dotGitPath = path.join(repositoryRoot, '.git'); const dotGitPath = path.join(repositoryRoot, '.git');
const { event: onRawGitChange, disposable: watcher } = watch(dotGitPath); const { event: onRawGitChange, disposable: watcher } = watch(dotGitPath);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册