@@ -31,6 +31,23 @@ const logger = createLogger('repo-compile-utils');
3131const MAX_CONCURRENT_GIT_OPERATIONS = 100 ;
3232const gitOperationLimit = pLimit ( MAX_CONCURRENT_GIT_OPERATIONS ) ;
3333
34+ /**
35+ * Extracts the host with port from an HTTP(S) URL string, preserving the port
36+ * even if it's a default port (e.g., 443 for https, 80 for http).
37+ *
38+ * This is needed because JavaScript URL parsers normalize URLs and strip default
39+ * ports, but Go's url.Parse preserves them. Since zoekt uses Go, we need to match
40+ * its behavior for repo name derivation.
41+ *
42+ * @param url - The URL string to extract host:port from
43+ * @returns The host with port if present (e.g., "example.com:443"), or null if not an HTTP(S) URL
44+ */
45+ const extractHostWithPort = ( url : string ) : string | null => {
46+ // Match http(s):// URLs: protocol://host(:port)/path
47+ const match = url . match ( / ^ h t t p s ? : \/ \/ ( [ ^ / ? # ] + ) / i) ;
48+ return match ? match [ 1 ] : null ;
49+ } ;
50+
3451type CompileResult = {
3552 repoData : RepoData [ ] ,
3653 warnings : string [ ] ,
@@ -515,7 +532,12 @@ export const compileGenericGitHostConfig_file = async (
515532
516533 // @note : matches the naming here:
517534 // https://github.com/sourcebot-dev/zoekt/blob/main/gitindex/index.go#L293
518- const repoName = path . join ( remoteUrl . host , remoteUrl . pathname . replace ( / \. g i t $ / , '' ) ) ;
535+ // Go's url.URL.Host includes the port if present (even default ports like 443),
536+ // but JS URL parsers normalize and strip default ports. We need to extract
537+ // the host:port directly from the raw URL to match zoekt's behavior.
538+ // For non-HTTP URLs, remoteUrl.host preserves non-default ports (e.g., ssh://host:22/).
539+ const hostWithPort = extractHostWithPort ( origin ) ?? remoteUrl . host ;
540+ const repoName = path . join ( hostWithPort , remoteUrl . pathname . replace ( / \. g i t $ / , '' ) ) ;
519541
520542 const repo : RepoData = {
521543 external_codeHostType : 'genericGitHost' ,
0 commit comments