Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Fixed issue with filtering on generic git repo indexed from http/https [#742](https://github.com/sourcebot-dev/sourcebot/pull/742)

## [4.10.10] - 2026-01-16

### Added
Expand Down
74 changes: 72 additions & 2 deletions packages/backend/src/repoCompileUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { expect, test, vi, describe, beforeEach, afterEach } from 'vitest';
import { compileGenericGitHostConfig_file } from './repoCompileUtils';
import { compileGenericGitHostConfig_file, compileGenericGitHostConfig_url } from './repoCompileUtils';

// Mock the git module
vi.mock('./git.js', () => ({
isPathAValidGitRepoRoot: vi.fn(),
getOriginUrl: vi.fn(),
isUrlAValidGitRepo: vi.fn(),
}));

// Mock the glob module
vi.mock('glob', () => ({
glob: vi.fn(),
}));

import { isPathAValidGitRepoRoot, getOriginUrl } from './git.js';
import { isPathAValidGitRepoRoot, getOriginUrl, isUrlAValidGitRepo } from './git.js';
import { glob } from 'glob';

const mockedGlob = vi.mocked(glob);
const mockedIsPathAValidGitRepoRoot = vi.mocked(isPathAValidGitRepoRoot);
const mockedGetOriginUrl = vi.mocked(getOriginUrl);
const mockedIsUrlAValidGitRepo = vi.mocked(isUrlAValidGitRepo);

describe('compileGenericGitHostConfig_file', () => {
beforeEach(() => {
Expand Down Expand Up @@ -122,3 +124,71 @@ describe('compileGenericGitHostConfig_file', () => {
expect(result.warnings[0]).toContain('not a git repository');
});
});

describe('compileGenericGitHostConfig_url', () => {
beforeEach(() => {
vi.clearAllMocks();
});

afterEach(() => {
vi.resetAllMocks();
});

test('should return warning when url is not a valid git repo', async () => {
mockedIsUrlAValidGitRepo.mockResolvedValue(false);

const config = {
type: 'git' as const,
url: 'https://example.com/not-a-repo',
};

const result = await compileGenericGitHostConfig_url(config, 1);

expect(result.repoData).toHaveLength(0);
expect(result.warnings).toHaveLength(1);
expect(result.warnings[0]).toContain('not a git repository');
});

test('should successfully compile with gitConfig when valid git repo url is found', async () => {
mockedIsUrlAValidGitRepo.mockResolvedValue(true);

const config = {
type: 'git' as const,
url: 'https://git.kernel.org/pub/scm/bluetooth/bluez.git',
};

const result = await compileGenericGitHostConfig_url(config, 1);

expect(result.repoData).toHaveLength(1);
expect(result.warnings).toHaveLength(0);
expect(result.repoData[0].cloneUrl).toBe('https://git.kernel.org/pub/scm/bluetooth/bluez.git');
expect(result.repoData[0].name).toBe('git.kernel.org/pub/scm/bluetooth/bluez');

// Verify gitConfig is set properly (this is the key fix for SOU-218)
const metadata = result.repoData[0].metadata as { gitConfig?: Record<string, string> };
expect(metadata.gitConfig).toBeDefined();
expect(metadata.gitConfig!['zoekt.name']).toBe('git.kernel.org/pub/scm/bluetooth/bluez');
expect(metadata.gitConfig!['zoekt.web-url']).toBe('https://git.kernel.org/pub/scm/bluetooth/bluez.git');
expect(metadata.gitConfig!['zoekt.display-name']).toBe('git.kernel.org/pub/scm/bluetooth/bluez');
expect(metadata.gitConfig!['zoekt.archived']).toBe('0');
expect(metadata.gitConfig!['zoekt.fork']).toBe('0');
expect(metadata.gitConfig!['zoekt.public']).toBe('1');
});

test('should handle url with trailing .git correctly', async () => {
mockedIsUrlAValidGitRepo.mockResolvedValue(true);

const config = {
type: 'git' as const,
url: 'https://github.com/test/repo.git',
};

const result = await compileGenericGitHostConfig_url(config, 1);

expect(result.repoData).toHaveLength(1);
expect(result.repoData[0].name).toBe('github.com/test/repo');

const metadata = result.repoData[0].metadata as { gitConfig?: Record<string, string> };
expect(metadata.gitConfig!['zoekt.name']).toBe('github.com/test/repo');
});
});
10 changes: 9 additions & 1 deletion packages/backend/src/repoCompileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,17 @@ export const compileGenericGitHostConfig_url = async (
}
},
metadata: {
gitConfig: {
'zoekt.name': repoName,
'zoekt.web-url': remoteUrl.toString(),
'zoekt.archived': marshalBool(false),
'zoekt.fork': marshalBool(false),
'zoekt.public': marshalBool(true),
'zoekt.display-name': repoName,
},
branches: config.revisions?.branches ?? undefined,
tags: config.revisions?.tags ?? undefined,
}
} satisfies RepoMetadata,
};

return {
Expand Down