Skip to content

Commit 48bc94d

Browse files
authored
Git - 💄 make stash picker async (microsoft#202573)
1 parent 6111294 commit 48bc94d

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

extensions/git/src/commands.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ class RepositoryItem implements QuickPickItem {
262262
constructor(public readonly path: string) { }
263263
}
264264

265+
class StashItem implements QuickPickItem {
266+
get label(): string { return `#${this.stash.index}: ${this.stash.description}`; }
267+
268+
get description(): string | undefined { return this.stash.branchName; }
269+
270+
constructor(readonly stash: Stash) { }
271+
}
272+
265273
interface ScmCommandOptions {
266274
repository?: boolean;
267275
diff?: boolean;
@@ -3690,17 +3698,15 @@ export class CommandCenter {
36903698
}
36913699

36923700
private async pickStash(repository: Repository, placeHolder: string): Promise<Stash | undefined> {
3693-
const stashes = await repository.getStashes();
3694-
3695-
if (stashes.length === 0) {
3696-
window.showInformationMessage(l10n.t('There are no stashes in the repository.'));
3697-
return;
3698-
}
3699-
3700-
const picks = stashes.map(stash => ({ label: `#${stash.index}: ${stash.description}`, description: stash.branchName, stash }));
3701-
const result = await window.showQuickPick(picks, { placeHolder });
3701+
const getStashQuickPickItems = async (): Promise<StashItem[] | QuickPickItem[]> => {
3702+
const stashes = await repository.getStashes();
3703+
return stashes.length > 0 ?
3704+
stashes.map(stash => new StashItem(stash)) :
3705+
[{ label: l10n.t('$(info) This repository has no stashes.') }];
3706+
};
37023707

3703-
return result?.stash;
3708+
const result = await window.showQuickPick<StashItem | QuickPickItem>(getStashQuickPickItems(), { placeHolder });
3709+
return result instanceof StashItem ? result.stash : undefined;
37043710
}
37053711

37063712
private async getStashFromUri(uri: Uri | undefined): Promise<{ repository: Repository; stash: Stash } | undefined> {

0 commit comments

Comments
 (0)