Skip to content

Commit 2c9a70e

Browse files
authored
fix(local-repo): Fix autocomplete when repo includes default port (#762)
* support default ports in repoName * changelog
1 parent cf6fc3d commit 2c9a70e

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Bumped AI SDK and associated packages version. [#752](https://github.com/sourcebot-dev/sourcebot/pull/752)
1212
- Bumped Node.js version to v24. [#753](https://github.com/sourcebot-dev/sourcebot/pull/753)
1313

14-
### Fixed
14+
### Fixes
15+
- Fix autocomplete when repo includes default port [#762](https://github.com/sourcebot-dev/sourcebot/pull/762)
1516
- Fixed "Repository not found for file: x" error when searching in orphaned shards. [#761](https://github.com/sourcebot-dev/sourcebot/pull/761)
1617

1718
## [4.10.12] - 2026-01-16

packages/backend/src/repoCompileUtils.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ describe('compileGenericGitHostConfig_file', () => {
9999
expect(result.repoData[0].name).toBe('github.com/test/repo');
100100
});
101101

102+
test('should include port in repo name when origin url has a port', async () => {
103+
mockedGlob.mockResolvedValue(['/path/to/valid/repo']);
104+
mockedIsPathAValidGitRepoRoot.mockResolvedValue(true);
105+
mockedGetOriginUrl.mockResolvedValue('https://git.kernel.org:443/pub/scm/bluetooth/bluez.git');
106+
107+
const config = {
108+
type: 'git' as const,
109+
url: 'file:///path/to/valid/repo',
110+
};
111+
112+
const result = await compileGenericGitHostConfig_file(config, 1);
113+
114+
expect(result.repoData).toHaveLength(1);
115+
expect(result.warnings).toHaveLength(0);
116+
expect(result.repoData[0].cloneUrl).toBe('file:///path/to/valid/repo');
117+
// The name should include the port to match what zoekt derives from the origin URL
118+
expect(result.repoData[0].name).toBe('git.kernel.org:443/pub/scm/bluetooth/bluez');
119+
});
120+
102121
test('should return warnings for invalid repos and success for valid ones', async () => {
103122
mockedGlob.mockResolvedValue(['/path/to/valid/repo', '/path/to/invalid/repo']);
104123
mockedIsPathAValidGitRepoRoot.mockImplementation(async ({ path }) => {

packages/backend/src/repoCompileUtils.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ const logger = createLogger('repo-compile-utils');
3131
const MAX_CONCURRENT_GIT_OPERATIONS = 100;
3232
const 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(/^https?:\/\/([^/?#]+)/i);
48+
return match ? match[1] : null;
49+
};
50+
3451
type 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(/\.git$/, ''));
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(/\.git$/, ''));
519541

520542
const repo: RepoData = {
521543
external_codeHostType: 'genericGitHost',

0 commit comments

Comments
 (0)