git api: deprecation

This commit is contained in:
Joao Moreno
2018-08-21 16:41:34 +02:00
parent b00d1b40bc
commit 257878e3b1
2 changed files with 53 additions and 13 deletions

View File

@@ -9,7 +9,7 @@ import { Model } from '../model';
import { Repository as ModelRepository } from '../repository';
import { Uri, SourceControlInputBox } from 'vscode';
import { GitExtension } from './git';
import { getAPI } from './api';
import { getAPI, deprecated } from './api';
class InputBoxImpl implements GitExtension.InputBox {
set value(value: string) { this.inputBox.value = value; }
@@ -28,18 +28,46 @@ class RepositoryImpl implements GitExtension.Repository {
}
}
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'); }
};
class NoModelGitExtension implements GitExtension {
@deprecated
async getGitPath(): Promise<string> {
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); }
};
@deprecated
async getRepositories(): Promise<GitExtension.Repository[]> {
throw new Error('Git model not found');
}
getAPI(): GitExtension.API {
throw new Error('Git model not found');
}
}
class GitExtensionImpl implements GitExtension {
constructor(private _model: Model) { }
@deprecated
async getGitPath(): Promise<string> {
return this._model.git.path;
}
@deprecated
async getRepositories(): Promise<GitExtension.Repository[]> {
return this._model.repositories.map(repository => new RepositoryImpl(repository));
}
getAPI(range: string): GitExtension.API {
return getAPI(this._model, range);
}
}
export function createGitExtension(model?: Model): GitExtension {
if (!model) {
return new NoModelGitExtension();
}
return new GitExtensionImpl(model);
}