diff --git a/extensions/git/src/api/api1.ts b/extensions/git/src/api/api1.ts index 22b2a87aef1..b4dba92db69 100644 --- a/extensions/git/src/api/api1.ts +++ b/extensions/git/src/api/api1.ts @@ -179,6 +179,10 @@ export class ApiRepository implements Repository { push(remoteName?: string, branchName?: string, setUpstream: boolean = false): Promise { return this._repository.pushTo(remoteName, branchName, setUpstream); } + + blame(path: string): Promise { + return this._repository.blame(path); + } } export class ApiGit implements Git { diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index 1a67f8e23f5..5943ebe4b96 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -156,6 +156,7 @@ export interface Repository { fetch(remote?: string, ref?: string, depth?: number): Promise; pull(unshallow?: boolean): Promise; push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise; + blame(path: string): Promise; } export interface API { diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 26f5ae804d8..4a7cf7b8fe8 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -1282,6 +1282,19 @@ export class Repository { } } + async blame(path: string): Promise { + try { + const args = ['blame']; + args.push(path); + + let result = await this.run(args); + + return result.stdout.trim(); + } catch (err) { + throw err; + } + } + async createStash(message?: string, includeUntracked?: boolean): Promise { try { const args = ['stash', 'save']; diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 1fb29e03f67..8c32162f3f1 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -299,7 +299,8 @@ export const enum Operation { GetObjectDetails = 'GetObjectDetails', SubmoduleUpdate = 'SubmoduleUpdate', RebaseContinue = 'RebaseContinue', - Apply = 'Apply' + Apply = 'Apply', + Blame = 'Blame' } function isReadOnly(operation: Operation): boolean { @@ -999,6 +1000,10 @@ export class Repository implements Disposable { await this.run(Operation.Push, () => this.repository.push(remote, undefined, false, true, forcePushMode)); } + async blame(path: string): Promise { + return await this.run(Operation.Blame, () => this.repository.blame(path)); + } + @throttle sync(head: Branch): Promise { return this._sync(head, false);