Git - improve logic to pick a worktree to migrate changes from (#276048)

This commit is contained in:
Ladislau Szomoru
2025-11-07 11:38:52 +00:00
committed by GitHub
parent 426a6a56f3
commit 7bdbccd240

View File

@@ -3397,9 +3397,16 @@ export class CommandCenter {
} }
@command('git.migrateWorktreeChanges', { repository: true, repositoryFilter: ['repository', 'submodule'] }) @command('git.migrateWorktreeChanges', { repository: true, repositoryFilter: ['repository', 'submodule'] })
async migrateWorktreeChanges(repository: Repository): Promise<void> { async migrateWorktreeChanges(repository: Repository, worktreeUri?: Uri): Promise<void> {
const worktreePicks = async (): Promise<WorktreeItem[] | QuickPickItem[]> => { let worktreeRepository: Repository | undefined;
if (worktreeUri !== undefined) {
worktreeRepository = this.model.getRepository(worktreeUri);
} else {
const worktrees = await repository.getWorktrees(); const worktrees = await repository.getWorktrees();
if (worktrees.length === 1) {
worktreeRepository = this.model.getRepository(worktrees[0].path);
} else {
const worktreePicks = async (): Promise<WorktreeItem[] | QuickPickItem[]> => {
return worktrees.length === 0 return worktrees.length === 0
? [{ label: l10n.t('$(info) This repository has no worktrees.') }] ? [{ label: l10n.t('$(info) This repository has no worktrees.') }]
: worktrees.map(worktree => new WorktreeItem(worktree)); : worktrees.map(worktree => new WorktreeItem(worktree));
@@ -3412,8 +3419,11 @@ export class CommandCenter {
return; return;
} }
const worktreeRepository = this.model.getRepository(choice.worktree.path); worktreeRepository = this.model.getRepository(choice.worktree.path);
if (!worktreeRepository) { }
}
if (!worktreeRepository || worktreeRepository.kind !== 'worktree') {
return; return;
} }