Skip to content

Commit ee25b62

Browse files
committed
1 parent 344e93c commit ee25b62

3 files changed

Lines changed: 42 additions & 24 deletions

File tree

‎extensions/git/src/api.ts‎

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,55 @@
66
'use strict';
77

88
import { Model } from './model';
9-
import { Uri } from 'vscode';
9+
import { Repository as ModelRepository } from './repository';
10+
import { Uri, SourceControlInputBox } from 'vscode';
1011

1112
export interface InputBox {
1213
value: string;
1314
}
1415

16+
export class InputBoxImpl implements InputBox {
17+
set value(value: string) { this.inputBox.value = value; }
18+
get value(): string { return this.inputBox.value; }
19+
constructor(private inputBox: SourceControlInputBox) { }
20+
}
21+
1522
export interface Repository {
1623
readonly rootUri: Uri;
1724
readonly inputBox: InputBox;
1825
}
1926

27+
export class RepositoryImpl implements Repository {
28+
29+
readonly rootUri: Uri;
30+
readonly inputBox: InputBox;
31+
32+
constructor(repository: ModelRepository) {
33+
this.rootUri = Uri.file(repository.root);
34+
this.inputBox = new InputBoxImpl(repository.inputBox);
35+
}
36+
}
37+
2038
export interface API {
2139
getRepositories(): Promise<Repository[]>;
40+
getGitPath(): Promise<string>;
41+
}
42+
43+
export class APIImpl implements API {
44+
45+
constructor(private modelPromise: Promise<Model>) { }
46+
47+
async getGitPath(): Promise<string> {
48+
const model = await this.modelPromise;
49+
return model.git.path;
50+
}
51+
52+
async getRepositories(): Promise<Repository[]> {
53+
const model = await this.modelPromise;
54+
return model.repositories.map(repository => new RepositoryImpl(repository));
55+
}
2256
}
2357

24-
export function createApi(modelPromise: Promise<Model>) {
25-
return {
26-
async getRepositories(): Promise<Repository[]> {
27-
const model = await modelPromise;
28-
29-
return model.repositories.map(repository => ({
30-
rootUri: Uri.file(repository.root),
31-
inputBox: {
32-
set value(value: string) {
33-
repository.inputBox.value = value;
34-
},
35-
get value(): string {
36-
return repository.inputBox.value;
37-
}
38-
}
39-
}));
40-
}
41-
};
58+
export function createApi(modelPromise: Promise<Model>): API {
59+
return new APIImpl(modelPromise);
4260
}

‎extensions/git/src/git.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,14 @@ function getGitErrorCode(stderr: string): string | undefined {
366366

367367
export class Git {
368368

369-
private gitPath: string;
369+
readonly path: string;
370370
private env: any;
371371

372372
private _onOutput = new EventEmitter();
373373
get onOutput(): EventEmitter { return this._onOutput; }
374374

375375
constructor(options: IGitOptions) {
376-
this.gitPath = options.gitPath;
376+
this.path = options.gitPath;
377377
this.env = options.env || {};
378378
}
379379

@@ -447,7 +447,7 @@ export class Git {
447447
}
448448

449449
spawn(args: string[], options: SpawnOptions = {}): cp.ChildProcess {
450-
if (!this.gitPath) {
450+
if (!this.path) {
451451
throw new Error('git could not be found in the system.');
452452
}
453453

@@ -469,7 +469,7 @@ export class Git {
469469
this.log(`> git ${args.join(' ')}\n`);
470470
}
471471

472-
return cp.spawn(this.gitPath, args, options);
472+
return cp.spawn(this.path, args, options);
473473
}
474474

475475
private log(output: string): void {

‎extensions/git/src/model.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class Model {
6666

6767
private disposables: Disposable[] = [];
6868

69-
constructor(private git: Git, private globalState: Memento, private outputChannel: OutputChannel) {
69+
constructor(readonly git: Git, private globalState: Memento, private outputChannel: OutputChannel) {
7070
workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders, this, this.disposables);
7171
this.onDidChangeWorkspaceFolders({ added: workspace.workspaceFolders || [], removed: [] });
7272

0 commit comments

Comments
 (0)