diff --git a/extensions/git/src/api/api1.ts b/extensions/git/src/api/api1.ts index 8e083199ac1..d8ae8777166 100644 --- a/extensions/git/src/api/api1.ts +++ b/extensions/git/src/api/api1.ts @@ -200,6 +200,10 @@ export class ApiRepository implements Repository { return this.#repository.diffBetween(ref1, ref2, path); } + diffBetweenPatch(ref1: string, ref2: string, path?: string): Promise { + return this.#repository.diffBetweenPatch(ref1, ref2, path); + } + diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise { return this.#repository.diffBetweenWithStats(ref1, ref2, path); } diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index dd42714ab09..285d76ee55b 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -261,6 +261,7 @@ export interface Repository { diffBlobs(object1: string, object2: string): Promise; diffBetween(ref1: string, ref2: string): Promise; diffBetween(ref1: string, ref2: string, path: string): Promise; + diffBetweenPatch(ref1: string, ref2: string, path?: string): Promise; diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise; hashObject(data: string): Promise; diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index e4e0b662897..5cd79ce82d5 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -1772,6 +1772,17 @@ export class Repository { return result.stdout.trim(); } + async diffBetweenPatch(ref: string, options: { path?: string }): Promise { + const args = ['diff', ref, '--']; + + if (options.path) { + args.push(this.sanitizeRelativePath(options.path)); + } + + const result = await this.exec(args); + return result.stdout; + } + async diffBetweenWithStats(ref: string, options: { path?: string; similarityThreshold?: number }): Promise { const args = ['diff', '--raw', '--numstat', '--diff-filter=ADMR', '-z',]; diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 50ff7ac8ba2..6a978f7d860 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -1253,6 +1253,11 @@ export class Repository implements Disposable { return this.run(Operation.Diff, () => this.repository.diffBetween(ref1, ref2, path)); } + diffBetweenPatch(ref1: string, ref2: string, path?: string): Promise { + return this.run(Operation.Diff, () => + this.repository.diffBetweenPatch(`${ref1}...${ref2}`, { path })); + } + diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise { if (ref1 === this._EMPTY_TREE) { // Use git diff-tree to get the