Skip to content

Commit e5a596b

Browse files
committed
add git blame api
1 parent fe5f523 commit e5a596b

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

extensions/git/src/api/api1.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ export class ApiRepository implements Repository {
179179
push(remoteName?: string, branchName?: string, setUpstream: boolean = false): Promise<void> {
180180
return this._repository.pushTo(remoteName, branchName, setUpstream);
181181
}
182+
183+
blame(path: string): Promise<string> {
184+
return this._repository.blame(path);
185+
}
182186
}
183187

184188
export class ApiGit implements Git {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export interface Repository {
156156
fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
157157
pull(unshallow?: boolean): Promise<void>;
158158
push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise<void>;
159+
blame(path: string): Promise<string>;
159160
}
160161

161162
export interface API {

extensions/git/src/git.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,19 @@ export class Repository {
12821282
}
12831283
}
12841284

1285+
async blame(path: string): Promise<string> {
1286+
try {
1287+
const args = ['blame'];
1288+
args.push(path);
1289+
1290+
let result = await this.run(args);
1291+
1292+
return result.stdout.trim();
1293+
} catch (err) {
1294+
throw err;
1295+
}
1296+
}
1297+
12851298
async createStash(message?: string, includeUntracked?: boolean): Promise<void> {
12861299
try {
12871300
const args = ['stash', 'save'];

extensions/git/src/repository.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ export const enum Operation {
299299
GetObjectDetails = 'GetObjectDetails',
300300
SubmoduleUpdate = 'SubmoduleUpdate',
301301
RebaseContinue = 'RebaseContinue',
302-
Apply = 'Apply'
302+
Apply = 'Apply',
303+
Blame = 'Blame'
303304
}
304305

305306
function isReadOnly(operation: Operation): boolean {
@@ -999,6 +1000,10 @@ export class Repository implements Disposable {
9991000
await this.run(Operation.Push, () => this.repository.push(remote, undefined, false, true, forcePushMode));
10001001
}
10011002

1003+
async blame(path: string): Promise<string> {
1004+
return await this.run(Operation.Blame, () => this.repository.blame(path));
1005+
}
1006+
10021007
@throttle
10031008
sync(head: Branch): Promise<void> {
10041009
return this._sync(head, false);

0 commit comments

Comments
 (0)