git: implement API

This commit is contained in:
Joao Moreno
2018-08-24 12:04:29 +02:00
parent 28d2b5d2d6
commit 103715c3cc
5 changed files with 238 additions and 17 deletions

View File

@@ -6,8 +6,8 @@
'use strict';
import { Model } from '../model';
import { Repository as BaseRepository } from '../repository';
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, Ref, Submodule, Commit } from './git';
import { Repository as BaseRepository, Resource } from '../repository';
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, Ref, Submodule, Commit, Change } from './git';
import { Event, SourceControlInputBox, Uri } from 'vscode';
import { mapEvent } from '../util';
@@ -17,6 +17,11 @@ class ApiInputBox implements InputBox {
constructor(private _inputBox: SourceControlInputBox) { }
}
export class ApiChange implements Change {
constructor(_resource: Resource) { }
}
export class ApiRepositoryState implements RepositoryState {
get HEAD(): Branch | undefined { return this._repository.HEAD; }
@@ -25,6 +30,10 @@ export class ApiRepositoryState implements RepositoryState {
get submodules(): Submodule[] { return [...this._repository.submodules]; }
get rebaseCommit(): Commit | undefined { return this._repository.rebaseCommit; }
get mergeChanges(): Change[] { return this._repository.mergeGroup.resourceStates.map(r => new ApiChange(r)); }
get indexChanges(): Change[] { return this._repository.indexGroup.resourceStates.map(r => new ApiChange(r)); }
get workingTreeChanges(): Change[] { return this._repository.workingTreeGroup.resourceStates.map(r => new ApiChange(r)); }
readonly onDidChange: Event<void> = this._repository.onDidRunGitStatus;
constructor(private _repository: BaseRepository) { }
@@ -38,9 +47,101 @@ export class ApiRepository implements Repository {
constructor(private _repository: BaseRepository) { }
getConfigs(): Promise<{ key: string; value: string; }[]> {
return this._repository.getConfigs();
}
getConfig(key: string): Promise<string> {
return this._repository.getConfig(key);
}
setConfig(key: string, value: string): Promise<string> {
return this._repository.setConfig(key, value);
}
show(ref: string, path: string): Promise<string> {
return this._repository.show(ref, path);
}
getCommit(ref: string): Promise<Commit> {
return this._repository.getCommit(ref);
}
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number; }> {
return this._repository.getObjectDetails(treeish, path);
}
diffWithHEAD(path: string): Promise<string> {
return this._repository.diffWithHEAD(path);
}
diffWith(ref: string, path: string): Promise<string> {
return this._repository.diffWith(ref, path);
}
diffIndexWithHEAD(path: string): Promise<string> {
return this._repository.diffIndexWithHEAD(path);
}
diffIndexWith(ref: string, path: string): Promise<string> {
return this._repository.diffIndexWith(ref, path);
}
diffBlobs(object1: string, object2: string): Promise<string> {
return this._repository.diffBlobs(object1, object2);
}
diffBetween(ref1: string, ref2: string, path: string): Promise<string> {
return this._repository.diffBetween(ref1, ref2, path);
}
hashObject(data: string): Promise<string> {
return this._repository.hashObject(data);
}
createBranch(name: string, checkout: boolean, ref?: string | undefined): Promise<void> {
return this._repository.branch(name, checkout, ref);
}
deleteBranch(name: string): Promise<void> {
return this._repository.deleteBranch(name);
}
getBranch(name: string): Promise<Branch> {
return this._repository.getBranch(name);
}
setBranchUpstream(name: string, upstream: string): Promise<void> {
return this._repository.setBranchUpstream(name, upstream);
}
getMergeBase(ref1: string, ref2: string): Promise<string> {
throw new Error('Method not implemented.');
}
status(): Promise<void> {
return this._repository.status();
}
checkout(treeish: string): Promise<void> {
return this._repository.checkout(treeish);
}
addRemote(name: string, url: string): Promise<void> {
return this._repository.addRemote(name, url);
}
removeRemote(name: string): Promise<void> {
return this._repository.removeRemote(name);
}
fetch(remote?: string | undefined, ref?: string | undefined): Promise<void> {
return this._repository.fetch(remote, ref);
}
pull(): Promise<void> {
return this._repository.pull();
}
}
export class ApiGit implements Git {

View File

@@ -74,21 +74,15 @@ export interface RepositoryState {
readonly onDidChange: Event<void>;
}
export const enum ConfigScope {
System,
Global,
Local
}
export interface Repository {
readonly rootUri: Uri;
readonly inputBox: InputBox;
readonly state: RepositoryState;
getConfigs(scope: ConfigScope): Promise<{ key: string; value: string; }[]>;
getConfig(scope: ConfigScope, key: string): Promise<string>;
setConfig(scope: ConfigScope, key: string, value: string): Promise<string>;
getConfigs(): Promise<{ key: string; value: string; }[]>;
getConfig(key: string): Promise<string>;
setConfig(key: string, value: string): Promise<string>;
show(ref: string, path: string): Promise<string>;
getCommit(ref: string): Promise<Commit>;