Skip to content

Commit 323e6df

Browse files
authored
Git - improve repositories quick pick (microsoft#184794)
1 parent 89ec834 commit 323e6df

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

extensions/git/src/commands.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ class FetchAllRemotesItem implements QuickPickItem {
196196
}
197197

198198
class RepositoryItem implements QuickPickItem {
199-
get label(): string {
200-
return `$(repo) ${this.path}`;
201-
}
199+
get label(): string { return `$(repo) ${getRepositoryLabel(this.path)}`; }
200+
201+
get description(): string { return this.path; }
202202

203203
constructor(public readonly path: string) { }
204204
}
@@ -358,6 +358,15 @@ function getCheckoutProcessor(repository: Repository, type: string): CheckoutPro
358358
return undefined;
359359
}
360360

361+
function getRepositoryLabel(repositoryRoot: string): string {
362+
const workspaceFolder = workspace.getWorkspaceFolder(Uri.file(repositoryRoot));
363+
return workspaceFolder?.uri.toString() === repositoryRoot ? workspaceFolder.name : path.basename(repositoryRoot);
364+
}
365+
366+
function compareRepositoryLabel(repositoryRoot1: string, repositoryRoot2: string): number {
367+
return getRepositoryLabel(repositoryRoot1).localeCompare(getRepositoryLabel(repositoryRoot2));
368+
}
369+
361370
function sanitizeBranchName(name: string, whitespaceChar: string): string {
362371
return name ? name.trim().replace(/^-+/, '').replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$|\[|\]$/g, whitespaceChar) : name;
363372
}
@@ -896,7 +905,8 @@ export class CommandCenter {
896905

897906
const allRepositoriesLabel = l10n.t('All Repositories');
898907
const allRepositoriesQuickPickItem: QuickPickItem = { label: allRepositoriesLabel };
899-
const repositoriesQuickPickItems: QuickPickItem[] = this.model.closedRepositories.sort().map(r => new RepositoryItem(r));
908+
const repositoriesQuickPickItems: QuickPickItem[] = this.model.closedRepositories
909+
.sort(compareRepositoryLabel).map(r => new RepositoryItem(r));
900910

901911
const items = this.model.closedRepositories.length === 1 ? [...repositoriesQuickPickItems] :
902912
[...repositoriesQuickPickItems, { label: '', kind: QuickPickItemKind.Separator }, allRepositoriesQuickPickItem];
@@ -3459,7 +3469,8 @@ export class CommandCenter {
34593469

34603470
const allRepositoriesLabel = l10n.t('All Repositories');
34613471
const allRepositoriesQuickPickItem: QuickPickItem = { label: allRepositoriesLabel };
3462-
const repositoriesQuickPickItems: QuickPickItem[] = Array.from(this.model.parentRepositories.keys()).sort().map(r => new RepositoryItem(r));
3472+
const repositoriesQuickPickItems: QuickPickItem[] = Array.from(this.model.parentRepositories.keys())
3473+
.sort(compareRepositoryLabel).map(r => new RepositoryItem(r));
34633474

34643475
const items = this.model.parentRepositories.size === 1 ? [...repositoriesQuickPickItems] :
34653476
[...repositoriesQuickPickItems, { label: '', kind: QuickPickItemKind.Separator }, allRepositoriesQuickPickItem];
@@ -3492,7 +3503,8 @@ export class CommandCenter {
34923503

34933504
const allRepositoriesLabel = l10n.t('All Repositories');
34943505
const allRepositoriesQuickPickItem: QuickPickItem = { label: allRepositoriesLabel };
3495-
const repositoriesQuickPickItems: QuickPickItem[] = Array.from(this.model.unsafeRepositories.keys()).sort().map(r => new RepositoryItem(r));
3506+
const repositoriesQuickPickItems: QuickPickItem[] = Array.from(this.model.unsafeRepositories.keys())
3507+
.sort(compareRepositoryLabel).map(r => new RepositoryItem(r));
34963508

34973509
quickpick.items = this.model.unsafeRepositories.size === 1 ? [...repositoriesQuickPickItems] :
34983510
[...repositoriesQuickPickItems, { label: '', kind: QuickPickItemKind.Separator }, allRepositoriesQuickPickItem];

0 commit comments

Comments
 (0)