mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Merge pull request #63069 from Microsoft/rmacfarlane/gitapi
Expose 'apply' and 'diff --cached' from git extension API
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user