git: getAPI

This commit is contained in:
Joao Moreno
2018-08-21 16:04:00 +02:00
parent 0633c77f80
commit ad4fecadeb
7 changed files with 80 additions and 10 deletions

View File

@@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Model } from '../model';
import { Repository as ModelRepository } from '../repository';
import { Uri, SourceControlInputBox } from 'vscode';
import { GitExtension } from './git';
import { getAPI } from './api';
class InputBoxImpl implements GitExtension.InputBox {
set value(value: string) { this.inputBox.value = value; }
get value(): string { return this.inputBox.value; }
constructor(private inputBox: SourceControlInputBox) { }
}
class RepositoryImpl implements GitExtension.Repository {
readonly rootUri: Uri;
readonly inputBox: GitExtension.InputBox;
constructor(repository: ModelRepository) {
this.rootUri = Uri.file(repository.root);
this.inputBox = new InputBoxImpl(repository.inputBox);
}
}
export function createGitExtension(model?: Model): GitExtension {
if (!model) {
return {
getGitPath() { throw new Error('Git model not found'); },
getRepositories() { throw new Error('Git model not found'); },
getAPI() { throw new Error('Git model not found'); }
};
}
return {
async getGitPath() { return model.git.path; },
async getRepositories() { return model.repositories.map(repository => new RepositoryImpl(repository)); },
getAPI(range: string) { return getAPI(model, range); }
};
}