From 426e703a0b197425efaeb9754e5871fa061ed3bd Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 12 Sep 2025 22:05:04 +0000 Subject: [PATCH] refactor: improve git URL normalization and error handling - Add better error handling in normalizeGitUrl method - Remove unused import of getGitRepositoryInfo - Improve URL credential removal logic --- .../code-index/vector-store/qdrant-client.ts | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/services/code-index/vector-store/qdrant-client.ts b/src/services/code-index/vector-store/qdrant-client.ts index 3564dd4128..a47996cab2 100644 --- a/src/services/code-index/vector-store/qdrant-client.ts +++ b/src/services/code-index/vector-store/qdrant-client.ts @@ -7,7 +7,6 @@ import { IVectorStore } from "../interfaces/vector-store" import { Payload, VectorStoreSearchResult } from "../interfaces" import { DEFAULT_MAX_SEARCH_RESULTS, DEFAULT_SEARCH_MIN_SCORE } from "../constants" import { t } from "../../../i18n" -import { getGitRepositoryInfo } from "../../../utils/git" /** * Qdrant implementation of the vector store interface @@ -102,7 +101,8 @@ export class QdrantVectorStore implements IVectorStore { if (gitInfo?.repositoryUrl) { // Use repository URL to generate a deterministic name // This ensures the same collection name across worktrees and developers - const hash = createHash("sha256").update(gitInfo.repositoryUrl).digest("hex") + const normalizedUrl = this.normalizeGitUrl(gitInfo.repositoryUrl) + const hash = createHash("sha256").update(normalizedUrl).digest("hex") return `repo-${hash.substring(0, 16)}` } @@ -158,9 +158,7 @@ export class QdrantVectorStore implements IVectorStore { const urlMatch = configContent.match(/url\s*=\s*(.+?)(?:\r?\n|$)/m) if (urlMatch && urlMatch[1]) { const url = urlMatch[1].trim() - // Normalize the URL to ensure consistency - const normalizedUrl = this.normalizeGitUrl(url) - return { repositoryUrl: normalizedUrl } + return { repositoryUrl: url } } } } catch (error) { @@ -176,23 +174,40 @@ export class QdrantVectorStore implements IVectorStore { * @returns Normalized URL */ private normalizeGitUrl(url: string): string { - // Remove credentials - let normalized = url.replace(/^https?:\/\/[^@]+@/, "https://") + try { + // Remove credentials from HTTPS URLs + let normalized = url + if (url.startsWith("https://") || url.startsWith("http://")) { + try { + const urlObj = new URL(url) + urlObj.username = "" + urlObj.password = "" + normalized = urlObj.toString() + } catch { + // If URL parsing fails, just remove obvious credentials + normalized = url.replace(/^https?:\/\/[^@]+@/, "https://") + } + } - // Convert SSH to HTTPS format for consistency - if (normalized.startsWith("git@")) { - normalized = normalized.replace(/^git@([^:]+):/, "https://$1/") - } else if (normalized.startsWith("ssh://")) { - normalized = normalized.replace(/^ssh:\/\/(?:git@)?([^\/]+)\//, "https://$1/") + // Convert SSH to HTTPS format for consistency + if (normalized.startsWith("git@")) { + normalized = normalized.replace(/^git@([^:]+):/, "https://$1/") + } else if (normalized.startsWith("ssh://")) { + normalized = normalized.replace(/^ssh:\/\/(?:git@)?([^\/]+)\//, "https://$1/") + } + + // Remove .git suffix + normalized = normalized.replace(/\.git$/, "") + + // Convert to lowercase for consistency + normalized = normalized.toLowerCase() + + return normalized + } catch (error) { + // If normalization fails, return the original URL + console.warn(`[QdrantVectorStore] Could not normalize git URL:`, error) + return url.toLowerCase() } - - // Remove .git suffix - normalized = normalized.replace(/\.git$/, "") - - // Convert to lowercase for consistency - normalized = normalized.toLowerCase() - - return normalized } /**