mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
git: clone command
This commit is contained in:
parent
192db5f7d1
commit
cc71202224
|
@ -21,6 +21,11 @@
|
|||
},
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "git.clone",
|
||||
"title": "%command.clone%",
|
||||
"category": "Git"
|
||||
},
|
||||
{
|
||||
"command": "git.init",
|
||||
"title": "%command.init%",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"command.init": "Initialize Git Repository",
|
||||
"command.clone": "Clone",
|
||||
"command.init": "Initialize Repository",
|
||||
"command.refresh": "Refresh",
|
||||
"command.openChange": "Open Change",
|
||||
"command.openFile": "Open File",
|
||||
|
|
|
@ -10,6 +10,7 @@ import { Ref, RefType } from './git';
|
|||
import { Model, Resource, Status, CommitOptions } from './model';
|
||||
import * as staging from './staging';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as nls from 'vscode-nls';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
@ -184,6 +185,37 @@ export class CommandCenter {
|
|||
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')
|
||||
async init(): Promise<void> {
|
||||
await this.model.init();
|
||||
|
|
|
@ -289,6 +289,14 @@ export class Git {
|
|||
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> {
|
||||
const result = await this.exec(path, ['rev-parse', '--show-toplevel']);
|
||||
return result.stdout.trim();
|
||||
|
|
|
@ -249,6 +249,10 @@ export class Model implements Disposable {
|
|||
return anyEvent(this.onRunOperation as Event<any>, this.onDidRunOperation as Event<any>);
|
||||
}
|
||||
|
||||
get git(): Git {
|
||||
return this._git;
|
||||
}
|
||||
|
||||
private _mergeGroup = new MergeGroup([]);
|
||||
get mergeGroup(): MergeGroup { return this._mergeGroup; }
|
||||
|
||||
|
@ -314,7 +318,7 @@ export class Model implements Disposable {
|
|||
private disposables: Disposable[] = [];
|
||||
|
||||
constructor(
|
||||
private git: Git,
|
||||
private _git: Git,
|
||||
private rootPath: string,
|
||||
private askpass: Askpass
|
||||
) {
|
||||
|
@ -497,9 +501,9 @@ export class Model implements Disposable {
|
|||
this.repositoryDisposable.dispose();
|
||||
|
||||
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();
|
||||
this.repository = this.git.open(repositoryRoot, askpassEnv);
|
||||
this.repository = this._git.open(repositoryRoot, askpassEnv);
|
||||
|
||||
const dotGitPath = path.join(repositoryRoot, '.git');
|
||||
const { event: onRawGitChange, disposable: watcher } = watch(dotGitPath);
|
||||
|
|
Loading…
Reference in a new issue