mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Merge pull request #63069 from Microsoft/rmacfarlane/gitapi
Expose 'apply' and 'diff --cached' from git extension API
This commit is contained in:
commit
850bbb275e
|
@ -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);
|
||||
}
|
||||
|
|
2
extensions/git/src/api/git.d.ts
vendored
2
extensions/git/src/api/git.d.ts
vendored
|
@ -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>;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue