From ad5f5ea36592e7d49cd390a4c2b336b6d7f9219f Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Tue, 13 Nov 2018 16:18:18 -0800 Subject: [PATCH] Expose 'apply' and 'diff --cached' from git extension API --- extensions/git/src/api/api1.ts | 8 ++++++++ extensions/git/src/api/git.d.ts | 2 ++ extensions/git/src/git.ts | 14 +++++++++++--- extensions/git/src/repository.ts | 9 +++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/extensions/git/src/api/api1.ts b/extensions/git/src/api/api1.ts index 68622e7ac91..9469580d97b 100644 --- a/extensions/git/src/api/api1.ts +++ b/extensions/git/src/api/api1.ts @@ -60,6 +60,10 @@ export class ApiRepository implements Repository { constructor(private _repository: BaseRepository) { } + apply(patch: string, reverse?: boolean): Promise { + return this._repository.apply(patch, reverse); + } + getConfigs(): Promise<{ key: string; value: string; }[]> { return this._repository.getConfigs(); } @@ -96,6 +100,10 @@ export class ApiRepository implements Repository { return this._repository.clean(paths.map(p => Uri.file(p))); } + diff(cached?: boolean) { + return this._repository.diff(cached); + } + diffWithHEAD(path: string): Promise { return this._repository.diffWithHEAD(path); } diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index 9005dafa938..ea4d1f97d6c 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -128,6 +128,8 @@ export interface Repository { clean(paths: string[]): Promise; + apply(patch: string, reverse?: boolean): Promise; + diff(cached?: boolean): Promise; diffWithHEAD(path: string): Promise; diffWith(ref: string, path: string): Promise; diffIndexWithHEAD(path: string): Promise; diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 0deb723c9d0..80191125245 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -822,15 +822,23 @@ export class Repository { } } - async diff(path: string, cached = false): Promise { + async apply(patch: string, reverse?: boolean): Promise { + const args = ['apply', patch]; + + if (reverse) { + args.push('-R'); + } + + await this.run(args); + } + + async diff(cached = false): Promise { const args = ['diff']; if (cached) { args.push('--cached'); } - args.push('--', path); - const result = await this.run(args); return result.stdout; } diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index b6d604c11bc..a4557a0a74f 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -295,6 +295,7 @@ export const enum Operation { GetObjectDetails = 'GetObjectDetails', SubmoduleUpdate = 'SubmoduleUpdate', RebaseContinue = 'RebaseContinue', + Apply = 'Apply' } function isReadOnly(operation: Operation): boolean { @@ -705,6 +706,10 @@ export class Repository implements Disposable { await this.run(Operation.Status); } + diff(cached?: boolean): Promise { + return this.run(Operation.Diff, () => this.repository.diff(cached)); + } + diffWithHEAD(path: string): Promise { return this.run(Operation.Diff, () => this.repository.diffWithHEAD(path)); } @@ -1050,6 +1055,10 @@ export class Repository implements Disposable { return this.run(Operation.Show, () => this.repository.detectObjectType(object)); } + async apply(patch: string, reverse?: boolean): Promise { + return await this.run(Operation.Apply, () => this.repository.apply(patch, reverse)); + } + async getStashes(): Promise { return await this.repository.getStashes(); }