mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-22 19:29:17 +00:00
Git - improve logic to pick a worktree to migrate changes from (#276048)
This commit is contained in:
@@ -3397,23 +3397,33 @@ export class CommandCenter {
|
||||
}
|
||||
|
||||
@command('git.migrateWorktreeChanges', { repository: true, repositoryFilter: ['repository', 'submodule'] })
|
||||
async migrateWorktreeChanges(repository: Repository): Promise<void> {
|
||||
const worktreePicks = async (): Promise<WorktreeItem[] | QuickPickItem[]> => {
|
||||
async migrateWorktreeChanges(repository: Repository, worktreeUri?: Uri): Promise<void> {
|
||||
let worktreeRepository: Repository | undefined;
|
||||
if (worktreeUri !== undefined) {
|
||||
worktreeRepository = this.model.getRepository(worktreeUri);
|
||||
} else {
|
||||
const worktrees = await repository.getWorktrees();
|
||||
return worktrees.length === 0
|
||||
? [{ label: l10n.t('$(info) This repository has no worktrees.') }]
|
||||
: worktrees.map(worktree => new WorktreeItem(worktree));
|
||||
};
|
||||
if (worktrees.length === 1) {
|
||||
worktreeRepository = this.model.getRepository(worktrees[0].path);
|
||||
} else {
|
||||
const worktreePicks = async (): Promise<WorktreeItem[] | QuickPickItem[]> => {
|
||||
return worktrees.length === 0
|
||||
? [{ label: l10n.t('$(info) This repository has no worktrees.') }]
|
||||
: worktrees.map(worktree => new WorktreeItem(worktree));
|
||||
};
|
||||
|
||||
const placeHolder = l10n.t('Select a worktree to migrate changes from');
|
||||
const choice = await this.pickRef<WorktreeItem | QuickPickItem>(worktreePicks(), placeHolder);
|
||||
const placeHolder = l10n.t('Select a worktree to migrate changes from');
|
||||
const choice = await this.pickRef<WorktreeItem | QuickPickItem>(worktreePicks(), placeHolder);
|
||||
|
||||
if (!choice || !(choice instanceof WorktreeItem)) {
|
||||
return;
|
||||
if (!choice || !(choice instanceof WorktreeItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
worktreeRepository = this.model.getRepository(choice.worktree.path);
|
||||
}
|
||||
}
|
||||
|
||||
const worktreeRepository = this.model.getRepository(choice.worktree.path);
|
||||
if (!worktreeRepository) {
|
||||
if (!worktreeRepository || worktreeRepository.kind !== 'worktree') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user