diff --git a/extensions/git/src/api/api1.ts b/extensions/git/src/api/api1.ts index c6d7312604e..b12f5dcd6e2 100644 --- a/extensions/git/src/api/api1.ts +++ b/extensions/git/src/api/api1.ts @@ -17,23 +17,12 @@ class ApiInputBox implements InputBox { export class ApiChange implements Change { + get uri(): Uri { return this.resource.resourceUri; } + get originalUri(): Uri { return this.resource.original; } + get renameUri(): Uri | undefined { return this.resource.renameResourceUri; } + get status(): Status { return this.resource.type; } + constructor(private readonly resource: Resource) { } - - public get resourceUri(): Uri { - return this.resource.resourceUri; - } - - public get status(): Status { - return this.resource.type; - } - - public get original(): Uri { - return this.resource.original; - } - - public get renameResourceUri(): Uri | undefined { - return this.resource.renameResourceUri; - } } export class ApiRepositoryState implements RepositoryState { @@ -83,14 +72,6 @@ export class ApiRepository implements Repository { return this._repository.setConfig(key, value); } - show(ref: string, path: string): Promise { - return this._repository.show(ref, path); - } - - getCommit(ref: string): Promise { - return this._repository.getCommit(ref); - } - getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number; }> { return this._repository.getObjectDetails(treeish, path); } @@ -103,6 +84,18 @@ export class ApiRepository implements Repository { return this._repository.buffer(ref, filePath); } + show(ref: string, path: string): Promise { + return this._repository.show(ref, path); + } + + getCommit(ref: string): Promise { + return this._repository.getCommit(ref); + } + + clean(paths: string[]) { + return this._repository.clean(paths.map(p => Uri.file(p))); + } + diffWithHEAD(path: string): Promise { return this._repository.diffWithHEAD(path); } @@ -174,10 +167,6 @@ export class ApiRepository implements Repository { pull(): Promise { return this._repository.pull(); } - - clean(filePaths: string[]) { - return this._repository.clean(filePaths.map(p => Uri.file(p))); - } } export class ApiGit implements Git { diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index 96771ece10e..ced0b597afe 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -78,10 +78,16 @@ export const enum Status { } export interface Change { - readonly resourceUri: Uri; + + /** + * Returns either `originalUri` or `renameUri`, depending + * on whether this change is a rename change. When + * in doubt always use `uri` over the other two alternatives. + */ + readonly uri: Uri; + readonly originalUri: Uri; + readonly renameUri: Uri | undefined; readonly status: Status; - readonly original: Uri; - readonly renameResourceUri: Uri | undefined; } export interface RepositoryState { @@ -114,11 +120,13 @@ export interface Repository { getConfig(key: string): Promise; setConfig(key: string, value: string): Promise; - show(ref: string, path: string): Promise; - getCommit(ref: string): Promise; getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>; detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }>; - buffer(ref: string, filePath: string): Promise; + buffer(ref: string, path: string): Promise; + show(ref: string, path: string): Promise; + getCommit(ref: string): Promise; + + clean(paths: string[]): Promise; diffWithHEAD(path: string): Promise; diffWith(ref: string, path: string): Promise; @@ -144,8 +152,6 @@ export interface Repository { fetch(remote?: string, ref?: string): Promise; pull(): Promise; - - clean(filePaths: string[]): Promise; } export interface API { diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 12b79a3298d..52bbb1ec666 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -83,7 +83,7 @@ export class Resource implements SourceControlResourceState { } }; - private getIconPath(theme: string): Uri | undefined { + private getIconPath(theme: string): Uri { switch (this.type) { case Status.INDEX_MODIFIED: return Resource.Icons[theme].Modified; case Status.MODIFIED: return Resource.Icons[theme].Modified; @@ -101,7 +101,7 @@ export class Resource implements SourceControlResourceState { case Status.DELETED_BY_US: return Resource.Icons[theme].Conflict; case Status.BOTH_ADDED: return Resource.Icons[theme].Conflict; case Status.BOTH_MODIFIED: return Resource.Icons[theme].Conflict; - default: return; + default: throw new Error('Unknown git status: ' + this.type); } } @@ -160,7 +160,7 @@ export class Resource implements SourceControlResourceState { return { strikeThrough, faded, tooltip, light, dark, letter, color, source: 'git.resource' /*todo@joh*/ }; } - get letter(): string | undefined { + get letter(): string { switch (this.type) { case Status.INDEX_MODIFIED: case Status.MODIFIED: @@ -188,11 +188,11 @@ export class Resource implements SourceControlResourceState { case Status.BOTH_MODIFIED: return 'C'; default: - return; + throw new Error('Unknown git status: ' + this.type); } } - get color(): ThemeColor | undefined { + get color(): ThemeColor { switch (this.type) { case Status.INDEX_MODIFIED: case Status.MODIFIED: @@ -217,7 +217,7 @@ export class Resource implements SourceControlResourceState { case Status.BOTH_MODIFIED: return new ThemeColor('gitDecoration.conflictingResourceForeground'); default: - return; + throw new Error('Unknown git status: ' + this.type); } }