This commit is contained in:
Joao Moreno
2018-03-20 10:17:01 +01:00
parent 344e93c617
commit ee25b62029
3 changed files with 43 additions and 25 deletions

View File

@@ -6,37 +6,55 @@
'use strict';
import { Model } from './model';
import { Uri } from 'vscode';
import { Repository as ModelRepository } from './repository';
import { Uri, SourceControlInputBox } from 'vscode';
export interface InputBox {
value: string;
}
export class InputBoxImpl implements InputBox {
set value(value: string) { this.inputBox.value = value; }
get value(): string { return this.inputBox.value; }
constructor(private inputBox: SourceControlInputBox) { }
}
export interface Repository {
readonly rootUri: Uri;
readonly inputBox: InputBox;
}
export interface API {
getRepositories(): Promise<Repository[]>;
export class RepositoryImpl implements Repository {
readonly rootUri: Uri;
readonly inputBox: InputBox;
constructor(repository: ModelRepository) {
this.rootUri = Uri.file(repository.root);
this.inputBox = new InputBoxImpl(repository.inputBox);
}
}
export function createApi(modelPromise: Promise<Model>) {
return {
async getRepositories(): Promise<Repository[]> {
const model = await modelPromise;
export interface API {
getRepositories(): Promise<Repository[]>;
getGitPath(): Promise<string>;
}
return model.repositories.map(repository => ({
rootUri: Uri.file(repository.root),
inputBox: {
set value(value: string) {
repository.inputBox.value = value;
},
get value(): string {
return repository.inputBox.value;
}
}
}));
}
};
export class APIImpl implements API {
constructor(private modelPromise: Promise<Model>) { }
async getGitPath(): Promise<string> {
const model = await this.modelPromise;
return model.git.path;
}
async getRepositories(): Promise<Repository[]> {
const model = await this.modelPromise;
return model.repositories.map(repository => new RepositoryImpl(repository));
}
}
export function createApi(modelPromise: Promise<Model>): API {
return new APIImpl(modelPromise);
}

View File

@@ -366,14 +366,14 @@ function getGitErrorCode(stderr: string): string | undefined {
export class Git {
private gitPath: string;
readonly path: string;
private env: any;
private _onOutput = new EventEmitter();
get onOutput(): EventEmitter { return this._onOutput; }
constructor(options: IGitOptions) {
this.gitPath = options.gitPath;
this.path = options.gitPath;
this.env = options.env || {};
}
@@ -447,7 +447,7 @@ export class Git {
}
spawn(args: string[], options: SpawnOptions = {}): cp.ChildProcess {
if (!this.gitPath) {
if (!this.path) {
throw new Error('git could not be found in the system.');
}
@@ -469,7 +469,7 @@ export class Git {
this.log(`> git ${args.join(' ')}\n`);
}
return cp.spawn(this.gitPath, args, options);
return cp.spawn(this.path, args, options);
}
private log(output: string): void {

View File

@@ -66,7 +66,7 @@ export class Model {
private disposables: Disposable[] = [];
constructor(private git: Git, private globalState: Memento, private outputChannel: OutputChannel) {
constructor(readonly git: Git, private globalState: Memento, private outputChannel: OutputChannel) {
workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders, this, this.disposables);
this.onDidChangeWorkspaceFolders({ added: workspace.workspaceFolders || [], removed: [] });