mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-15 07:28:05 +00:00
Git - add extension API to get a patch for a commit range (#286159)
* Git - add extension API to get a patch for a commit range * Turns out `git diff` does not support the `--root` flag
This commit is contained in:
@@ -200,6 +200,10 @@ export class ApiRepository implements Repository {
|
||||
return this.#repository.diffBetween(ref1, ref2, path);
|
||||
}
|
||||
|
||||
diffBetweenPatch(ref1: string, ref2: string, path?: string): Promise<string> {
|
||||
return this.#repository.diffBetweenPatch(ref1, ref2, path);
|
||||
}
|
||||
|
||||
diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise<DiffChange[]> {
|
||||
return this.#repository.diffBetweenWithStats(ref1, ref2, path);
|
||||
}
|
||||
|
||||
1
extensions/git/src/api/git.d.ts
vendored
1
extensions/git/src/api/git.d.ts
vendored
@@ -261,6 +261,7 @@ export interface Repository {
|
||||
diffBlobs(object1: string, object2: string): Promise<string>;
|
||||
diffBetween(ref1: string, ref2: string): Promise<Change[]>;
|
||||
diffBetween(ref1: string, ref2: string, path: string): Promise<string>;
|
||||
diffBetweenPatch(ref1: string, ref2: string, path?: string): Promise<string>;
|
||||
diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise<DiffChange[]>;
|
||||
|
||||
hashObject(data: string): Promise<string>;
|
||||
|
||||
@@ -1772,6 +1772,17 @@ export class Repository {
|
||||
return result.stdout.trim();
|
||||
}
|
||||
|
||||
async diffBetweenPatch(ref: string, options: { path?: string }): Promise<string> {
|
||||
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<DiffChange[]> {
|
||||
const args = ['diff', '--raw', '--numstat', '--diff-filter=ADMR', '-z',];
|
||||
|
||||
|
||||
@@ -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<string> {
|
||||
return this.run(Operation.Diff, () =>
|
||||
this.repository.diffBetweenPatch(`${ref1}...${ref2}`, { path }));
|
||||
}
|
||||
|
||||
diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise<DiffChange[]> {
|
||||
if (ref1 === this._EMPTY_TREE) {
|
||||
// Use git diff-tree to get the
|
||||
|
||||
Reference in New Issue
Block a user