diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 1553a73acd2..b331766ad12 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -3411,9 +3411,7 @@ export class CommandCenter { } await repository.migrateChanges(worktreeRepository.root, { - confirmation: true, - deleteFromSource: false, - untracked: true + confirmation: true, deleteFromSource: true, untracked: true }); } diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 44654bd4897..6862d17664b 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -2461,13 +2461,19 @@ export class Repository { } } - async popStash(index?: number): Promise { + async popStash(index?: number, options?: { reinstateStagedChanges?: boolean }): Promise { const args = ['stash', 'pop']; + if (options?.reinstateStagedChanges) { + args.push('--index'); + } await this.popOrApplyStash(args, index); } - async applyStash(index?: number): Promise { + async applyStash(index?: number, options?: { reinstateStagedChanges?: boolean }): Promise { const args = ['stash', 'apply']; + if (options?.reinstateStagedChanges) { + args.push('--index'); + } await this.popOrApplyStash(args, index); } diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 3e32384074c..f4e23699d98 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -2268,16 +2268,16 @@ export class Repository implements Disposable { }); } - async popStash(index?: number): Promise { - return await this.run(Operation.Stash, () => this.repository.popStash(index)); + async popStash(index?: number, options?: { reinstateStagedChanges?: boolean }): Promise { + return await this.run(Operation.Stash, () => this.repository.popStash(index, options)); } async dropStash(index?: number): Promise { return await this.run(Operation.Stash, () => this.repository.dropStash(index)); } - async applyStash(index?: number): Promise { - return await this.run(Operation.Stash, () => this.repository.applyStash(index)); + async applyStash(index?: number, options?: { reinstateStagedChanges?: boolean }): Promise { + return await this.run(Operation.Stash, () => this.repository.applyStash(index, options)); } async showStash(index: number): Promise { @@ -2500,17 +2500,16 @@ export class Repository implements Disposable { } } - const stashName = `migration-${sourceRepository.HEAD?.name ?? sourceRepository.HEAD?.commit}-${this.HEAD?.name ?? this.HEAD?.commit}`; + const stashName = `migration:${sourceRepository.HEAD?.name ?? sourceRepository.HEAD?.commit}-${this.HEAD?.name ?? this.HEAD?.commit}`; await sourceRepository.createStash(stashName, options?.untracked); const stashes = await sourceRepository.getStashes(); try { - await this.applyStash(stashes[0].index); - if (options?.deleteFromSource) { - await sourceRepository.dropStash(stashes[0].index); + await this.popStash(stashes[0].index); } else { - await sourceRepository.popStash(); + await this.applyStash(stashes[0].index); + await sourceRepository.popStash(stashes[0].index, { reinstateStagedChanges: true }); } } catch (err) { if (err.gitErrorCode === GitErrorCodes.StashConflict) { @@ -2523,11 +2522,11 @@ export class Repository implements Disposable { await commands.executeCommand('workbench.view.scm'); } - await sourceRepository.popStash(); + await sourceRepository.popStash(stashes[0].index, { reinstateStagedChanges: true }); return; } - await sourceRepository.popStash(); + await sourceRepository.popStash(stashes[0].index, { reinstateStagedChanges: true }); throw err; } } @@ -2872,7 +2871,7 @@ export class Repository implements Disposable { const result = await runOperation(); return result; } finally { - await this.repository.popStash(); + await this.repository.popStash(undefined, { reinstateStagedChanges: true }); } }