Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/git/src/api/api1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export class ApiRepository implements Repository {
return this.#repository.clean(paths.map(p => Uri.file(p)));
}

restore(paths: string[], options?: { staged?: boolean; ref?: string }) {
return this.#repository.restore(paths.map(p => Uri.file(p)), options);
}

diff(cached?: boolean) {
return this.#repository.diff(cached);
}
Expand Down
1 change: 1 addition & 0 deletions extensions/git/src/api/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export interface Repository {
add(paths: string[]): Promise<void>;
revert(paths: string[]): Promise<void>;
clean(paths: string[]): Promise<void>;
restore(paths: string[], options?: { staged?: boolean; ref?: string }): Promise<void>;

apply(patch: string, reverse?: boolean): Promise<void>;
apply(patch: string, options?: { allowEmpty?: boolean; reverse?: boolean; threeWay?: boolean; }): Promise<void>;
Expand Down
20 changes: 20 additions & 0 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,26 @@ export class Repository {
}
}

async restore(paths: string[], options?: { staged?: boolean; ref?: string }): Promise<void> {
const args = ['restore'];

Comment thread
lszomoru marked this conversation as resolved.
if (options?.staged) {
args.push('--staged');
}

if (options?.ref) {
args.push('--source', options.ref);
}

if (paths.length > 0) {
for (const chunk of splitInChunks(paths.map(p => this.sanitizeRelativePath(p)), MAX_CLI_LENGTH)) {
await this.exec([...args, '--', ...chunk]);
}
} else {
await this.exec([...args, '--', '.']);
}
}

async addRemote(name: string, url: string): Promise<void> {
const args = ['remote', 'add', name, url];
await this.exec(args);
Expand Down
5 changes: 4 additions & 1 deletion extensions/git/src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const enum OperationKind {
RebaseAbort = 'RebaseAbort',
RebaseContinue = 'RebaseContinue',
Refresh = 'Refresh',
Restore = 'Restore',
RevertFiles = 'RevertFiles',
RevList = 'RevList',
RevParse = 'RevParse',
Expand All @@ -72,7 +73,7 @@ export type Operation = AddOperation | ApplyOperation | BlameOperation | BranchO
GetBranchOperation | GetBranchesOperation | GetCommitTemplateOperation | GetObjectDetailsOperation | GetObjectFilesOperation | GetRefsOperation |
GetRemoteRefsOperation | HashObjectOperation | IgnoreOperation | LogOperation | LogFileOperation | MergeOperation | MergeAbortOperation |
MergeBaseOperation | MoveOperation | PostCommitCommandOperation | PullOperation | PushOperation | RemoteOperation | RenameBranchOperation |
RemoveOperation | ResetOperation | RebaseOperation | RebaseAbortOperation | RebaseContinueOperation | RefreshOperation | RevertFilesOperation |
RemoveOperation | ResetOperation | RebaseOperation | RebaseAbortOperation | RebaseContinueOperation | RefreshOperation | RestoreOperation | RevertFilesOperation |
RevListOperation | RevParseOperation | SetBranchUpstreamOperation | ShowOperation | StageOperation | StatusOperation | StashOperation |
SubmoduleUpdateOperation | SyncOperation | TagOperation | WorktreeOperation;

Expand Down Expand Up @@ -121,6 +122,7 @@ export type RebaseOperation = BaseOperation & { kind: OperationKind.Rebase };
export type RebaseAbortOperation = BaseOperation & { kind: OperationKind.RebaseAbort };
export type RebaseContinueOperation = BaseOperation & { kind: OperationKind.RebaseContinue };
export type RefreshOperation = BaseOperation & { kind: OperationKind.Refresh };
export type RestoreOperation = BaseOperation & { kind: OperationKind.Restore };
export type RevertFilesOperation = BaseOperation & { kind: OperationKind.RevertFiles };
export type RevListOperation = BaseOperation & { kind: OperationKind.RevList };
export type RevParseOperation = BaseOperation & { kind: OperationKind.RevParse };
Expand Down Expand Up @@ -179,6 +181,7 @@ export const Operation = {
RebaseAbort: { kind: OperationKind.RebaseAbort, blocking: false, readOnly: false, remote: false, retry: false, showProgress: true } as RebaseAbortOperation,
RebaseContinue: { kind: OperationKind.RebaseContinue, blocking: false, readOnly: false, remote: false, retry: false, showProgress: true } as RebaseContinueOperation,
Refresh: { kind: OperationKind.Refresh, blocking: false, readOnly: false, remote: false, retry: false, showProgress: true } as RefreshOperation,
Restore: (showProgress: boolean) => ({ kind: OperationKind.Restore, blocking: false, readOnly: false, remote: false, retry: false, showProgress } as RestoreOperation),
RevertFiles: (showProgress: boolean) => ({ kind: OperationKind.RevertFiles, blocking: false, readOnly: false, remote: false, retry: false, showProgress } as RevertFilesOperation),
RevList: { kind: OperationKind.RevList, blocking: false, readOnly: true, remote: false, retry: false, showProgress: false } as RevListOperation,
RevParse: { kind: OperationKind.RevParse, blocking: false, readOnly: true, remote: false, retry: false, showProgress: false } as RevParseOperation,
Expand Down
17 changes: 17 additions & 0 deletions extensions/git/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,23 @@ export class Repository implements Disposable {
});
}

async restore(resources: Uri[], options?: { staged?: boolean; ref?: string }): Promise<void> {
await this.run(
Operation.Restore(!this.optimisticUpdateEnabled()),
async () => {
const resourcePaths = resources.map(r => r.fsPath);
await this.repository.restore(resourcePaths, options);

if (options?.staged) {
// Index was modified;
this.closeDiffEditors([], resourcePaths);
} else {
// Working tree was modified;
this.closeDiffEditors(resourcePaths, []);
}
});
}

async commit(message: string | undefined, opts: CommitOptions = Object.create(null)): Promise<void> {
const indexResources = [...this.indexGroup.resourceStates.map(r => r.resourceUri.fsPath)];
const workingGroupResources = opts.all && opts.all !== 'tracked' ?
Expand Down
Loading