Merge pull request #63069 from Microsoft/rmacfarlane/gitapi

Expose 'apply' and 'diff --cached' from git extension API
This commit is contained in:
João Moreno 2018-11-16 09:40:04 +01:00 committed by GitHub
commit 850bbb275e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View file

@ -60,6 +60,10 @@ export class ApiRepository implements Repository {
constructor(private _repository: BaseRepository) { }
apply(patch: string, reverse?: boolean): Promise<void> {
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<string> {
return this._repository.diffWithHEAD(path);
}

View file

@ -128,6 +128,8 @@ export interface Repository {
clean(paths: string[]): Promise<void>;
apply(patch: string, reverse?: boolean): Promise<void>;
diff(cached?: boolean): Promise<string>;
diffWithHEAD(path: string): Promise<string>;
diffWith(ref: string, path: string): Promise<string>;
diffIndexWithHEAD(path: string): Promise<string>;

View file

@ -822,15 +822,23 @@ export class Repository {
}
}
async diff(path: string, cached = false): Promise<string> {
async apply(patch: string, reverse?: boolean): Promise<void> {
const args = ['apply', patch];
if (reverse) {
args.push('-R');
}
await this.run(args);
}
async diff(cached = false): Promise<string> {
const args = ['diff'];
if (cached) {
args.push('--cached');
}
args.push('--', path);
const result = await this.run(args);
return result.stdout;
}

View file

@ -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<string> {
return this.run(Operation.Diff, () => this.repository.diff(cached));
}
diffWithHEAD(path: string): Promise<string> {
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<void> {
return await this.run(Operation.Apply, () => this.repository.apply(patch, reverse));
}
async getStashes(): Promise<Stash[]> {
return await this.repository.getStashes();
}