From ee25b62029dbc5eebbc16fff352a6e755f868435 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Tue, 20 Mar 2018 10:17:01 +0100 Subject: [PATCH] fixes #46144 --- extensions/git/src/api.ts | 58 ++++++++++++++++++++++++------------- extensions/git/src/git.ts | 8 ++--- extensions/git/src/model.ts | 2 +- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/extensions/git/src/api.ts b/extensions/git/src/api.ts index 8d94502e041..6832fda9531 100644 --- a/extensions/git/src/api.ts +++ b/extensions/git/src/api.ts @@ -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; +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) { - return { - async getRepositories(): Promise { - const model = await modelPromise; +export interface API { + getRepositories(): Promise; + getGitPath(): Promise; +} - 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) { } + + async getGitPath(): Promise { + const model = await this.modelPromise; + return model.git.path; + } + + async getRepositories(): Promise { + const model = await this.modelPromise; + return model.repositories.map(repository => new RepositoryImpl(repository)); + } +} + +export function createApi(modelPromise: Promise): API { + return new APIImpl(modelPromise); } \ No newline at end of file diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 094bf3fe577..1ae77fd7072 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -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 { diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index ab66dfb6548..3ceb2dc3fc9 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -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: [] });