mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 03:39:23 +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'] })
|
@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();
|
||||||
return worktrees.length === 0
|
if (worktrees.length === 1) {
|
||||||
? [{ label: l10n.t('$(info) This repository has no worktrees.') }]
|
worktreeRepository = this.model.getRepository(worktrees[0].path);
|
||||||
: worktrees.map(worktree => new WorktreeItem(worktree));
|
} 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 placeHolder = l10n.t('Select a worktree to migrate changes from');
|
||||||
const choice = await this.pickRef<WorktreeItem | QuickPickItem>(worktreePicks(), placeHolder);
|
const choice = await this.pickRef<WorktreeItem | QuickPickItem>(worktreePicks(), placeHolder);
|
||||||
|
|
||||||
if (!choice || !(choice instanceof WorktreeItem)) {
|
if (!choice || !(choice instanceof WorktreeItem)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
worktreeRepository = this.model.getRepository(choice.worktree.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const worktreeRepository = this.model.getRepository(choice.worktree.path);
|
if (!worktreeRepository || worktreeRepository.kind !== 'worktree') {
|
||||||
if (!worktreeRepository) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user