Skip to content

Commit 501241e

Browse files
committed
💄
1 parent 9a7fdb4 commit 501241e

3 files changed

Lines changed: 37 additions & 42 deletions

File tree

extensions/git/src/api/api1.ts

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,12 @@ class ApiInputBox implements InputBox {
1717

1818
export class ApiChange implements Change {
1919

20-
constructor(private readonly resource: Resource) { }
21-
22-
public get resourceUri(): Uri {
23-
return this.resource.resourceUri;
24-
}
25-
26-
public get status(): Status {
27-
return this.resource.type;
28-
}
29-
30-
public get original(): Uri {
31-
return this.resource.original;
32-
}
20+
get uri(): Uri { return this.resource.resourceUri; }
21+
get originalUri(): Uri { return this.resource.original; }
22+
get renameUri(): Uri | undefined { return this.resource.renameResourceUri; }
23+
get status(): Status { return this.resource.type; }
3324

34-
public get renameResourceUri(): Uri | undefined {
35-
return this.resource.renameResourceUri;
36-
}
25+
constructor(private readonly resource: Resource) { }
3726
}
3827

3928
export class ApiRepositoryState implements RepositoryState {
@@ -83,14 +72,6 @@ export class ApiRepository implements Repository {
8372
return this._repository.setConfig(key, value);
8473
}
8574

86-
show(ref: string, path: string): Promise<string> {
87-
return this._repository.show(ref, path);
88-
}
89-
90-
getCommit(ref: string): Promise<Commit> {
91-
return this._repository.getCommit(ref);
92-
}
93-
9475
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number; }> {
9576
return this._repository.getObjectDetails(treeish, path);
9677
}
@@ -103,6 +84,18 @@ export class ApiRepository implements Repository {
10384
return this._repository.buffer(ref, filePath);
10485
}
10586

87+
show(ref: string, path: string): Promise<string> {
88+
return this._repository.show(ref, path);
89+
}
90+
91+
getCommit(ref: string): Promise<Commit> {
92+
return this._repository.getCommit(ref);
93+
}
94+
95+
clean(paths: string[]) {
96+
return this._repository.clean(paths.map(p => Uri.file(p)));
97+
}
98+
10699
diffWithHEAD(path: string): Promise<string> {
107100
return this._repository.diffWithHEAD(path);
108101
}
@@ -174,10 +167,6 @@ export class ApiRepository implements Repository {
174167
pull(): Promise<void> {
175168
return this._repository.pull();
176169
}
177-
178-
clean(filePaths: string[]) {
179-
return this._repository.clean(filePaths.map(p => Uri.file(p)));
180-
}
181170
}
182171

183172
export class ApiGit implements Git {

extensions/git/src/api/git.d.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ export const enum Status {
7878
}
7979

8080
export interface Change {
81-
readonly resourceUri: Uri;
81+
82+
/**
83+
* Returns either `originalUri` or `renameUri`, depending
84+
* on whether this change is a rename change. When
85+
* in doubt always use `uri` over the other two alternatives.
86+
*/
87+
readonly uri: Uri;
88+
readonly originalUri: Uri;
89+
readonly renameUri: Uri | undefined;
8290
readonly status: Status;
83-
readonly original: Uri;
84-
readonly renameResourceUri: Uri | undefined;
8591
}
8692

8793
export interface RepositoryState {
@@ -114,11 +120,13 @@ export interface Repository {
114120
getConfig(key: string): Promise<string>;
115121
setConfig(key: string, value: string): Promise<string>;
116122

117-
show(ref: string, path: string): Promise<string>;
118-
getCommit(ref: string): Promise<Commit>;
119123
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>;
120124
detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }>;
121-
buffer(ref: string, filePath: string): Promise<Buffer>;
125+
buffer(ref: string, path: string): Promise<Buffer>;
126+
show(ref: string, path: string): Promise<string>;
127+
getCommit(ref: string): Promise<Commit>;
128+
129+
clean(paths: string[]): Promise<void>;
122130

123131
diffWithHEAD(path: string): Promise<string>;
124132
diffWith(ref: string, path: string): Promise<string>;
@@ -144,8 +152,6 @@ export interface Repository {
144152

145153
fetch(remote?: string, ref?: string): Promise<void>;
146154
pull(): Promise<void>;
147-
148-
clean(filePaths: string[]): Promise<void>;
149155
}
150156

151157
export interface API {

extensions/git/src/repository.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class Resource implements SourceControlResourceState {
8383
}
8484
};
8585

86-
private getIconPath(theme: string): Uri | undefined {
86+
private getIconPath(theme: string): Uri {
8787
switch (this.type) {
8888
case Status.INDEX_MODIFIED: return Resource.Icons[theme].Modified;
8989
case Status.MODIFIED: return Resource.Icons[theme].Modified;
@@ -101,7 +101,7 @@ export class Resource implements SourceControlResourceState {
101101
case Status.DELETED_BY_US: return Resource.Icons[theme].Conflict;
102102
case Status.BOTH_ADDED: return Resource.Icons[theme].Conflict;
103103
case Status.BOTH_MODIFIED: return Resource.Icons[theme].Conflict;
104-
default: return;
104+
default: throw new Error('Unknown git status: ' + this.type);
105105
}
106106
}
107107

@@ -160,7 +160,7 @@ export class Resource implements SourceControlResourceState {
160160
return { strikeThrough, faded, tooltip, light, dark, letter, color, source: 'git.resource' /*todo@joh*/ };
161161
}
162162

163-
get letter(): string | undefined {
163+
get letter(): string {
164164
switch (this.type) {
165165
case Status.INDEX_MODIFIED:
166166
case Status.MODIFIED:
@@ -188,11 +188,11 @@ export class Resource implements SourceControlResourceState {
188188
case Status.BOTH_MODIFIED:
189189
return 'C';
190190
default:
191-
return;
191+
throw new Error('Unknown git status: ' + this.type);
192192
}
193193
}
194194

195-
get color(): ThemeColor | undefined {
195+
get color(): ThemeColor {
196196
switch (this.type) {
197197
case Status.INDEX_MODIFIED:
198198
case Status.MODIFIED:
@@ -217,7 +217,7 @@ export class Resource implements SourceControlResourceState {
217217
case Status.BOTH_MODIFIED:
218218
return new ThemeColor('gitDecoration.conflictingResourceForeground');
219219
default:
220-
return;
220+
throw new Error('Unknown git status: ' + this.type);
221221
}
222222
}
223223

0 commit comments

Comments
 (0)