From f61f185c935f2f23e2d790e9c8d39e74f145172f Mon Sep 17 00:00:00 2001 From: liangfung Date: Wed, 18 Dec 2024 18:06:40 +0700 Subject: [PATCH] update --- ee/tabby-ui/lib/utils/repository.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ee/tabby-ui/lib/utils/repository.ts b/ee/tabby-ui/lib/utils/repository.ts index 87e9a956edc4..35ae1c468042 100644 --- a/ee/tabby-ui/lib/utils/repository.ts +++ b/ee/tabby-ui/lib/utils/repository.ts @@ -10,19 +10,23 @@ export function findClosestGitRepository( return undefined } - const repos = repositories.filter(repo => { + const filteredRepos = repositories.filter(repo => { const search = gitUrlParse(repo.url) const isSameResource = search.resource === targetSearch.resource || search.protocol === 'file' return isSameResource && search.name === targetSearch.name }) - // If there're multiple matches, we pick the one with highest alphabetical order - return repos.sort((a, b) => { - const canonicalUrlA = canonicalizeUrl(a.url) - const canonicalUrlB = canonicalizeUrl(b.url) - return canonicalUrlB.localeCompare(canonicalUrlA) - })[0] + if (filteredRepos.length === 0) { + return undefined + } else { + // If there're multiple matches, we pick the one with highest alphabetical order + return filteredRepos.reduce((min, current) => { + const minUrl = canonicalizeUrl(min.url) + const currentUrl = canonicalizeUrl(current.url) + return minUrl > currentUrl ? min : current + }) + } } export function canonicalizeUrl(url: string): string {