Skip to content

Commit dcbbab9

Browse files
feat(backend): skip getCommitHashForRefName for empty repos
Adds isRepoEmpty utility to git.ts and uses it in repoIndexManager to avoid calling getCommitHashForRefName on repos with no commits, preventing noisy debug log output for empty repositories. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9b98cf1 commit dcbbab9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/backend/src/git.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,23 @@ export const getLatestCommitTimestamp = async ({
415415
}
416416
}
417417

418+
/**
419+
* Returns true if the git repository at the given path has no commits.
420+
*/
421+
export const isRepoEmpty = async ({
422+
path,
423+
}: {
424+
path: string,
425+
}): Promise<boolean> => {
426+
const git = createGitClientForPath(path);
427+
try {
428+
const result = await git.raw(['log', '--all', '-1', '--format=%H']);
429+
return result.trim() === '';
430+
} catch {
431+
return true;
432+
}
433+
}
434+
418435
/**
419436
* Writes or updates the commit-graph file for the repository.
420437
* This pre-computes commit metadata to speed up operations like

packages/backend/src/repoIndexManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Redis } from 'ioredis';
88
import micromatch from 'micromatch';
99
import Redlock, { ExecutionError } from 'redlock';
1010
import { INDEX_CACHE_DIR, WORKER_STOP_GRACEFUL_TIMEOUT_MS } from './constants.js';
11-
import { cloneRepository, fetchRepository, getBranches, getCommitHashForRefName, getLatestCommitTimestamp, getLocalDefaultBranch, getTags, isPathAValidGitRepoRoot, unsetGitConfig, upsertGitConfig } from './git.js';
11+
import { cloneRepository, fetchRepository, getBranches, getCommitHashForRefName, getLatestCommitTimestamp, getLocalDefaultBranch, getTags, isPathAValidGitRepoRoot, isRepoEmpty, unsetGitConfig, upsertGitConfig } from './git.js';
1212
import { captureEvent } from './posthog.js';
1313
import { PromClient } from './promClient.js';
1414
import { RepoWithConnections, Settings } from "./types.js";
@@ -531,7 +531,8 @@ export class RepoIndexManager {
531531

532532
if (jobData.type === RepoIndexingJobType.INDEX) {
533533
const { path: repoPath } = getRepoPath(jobData.repo);
534-
const commitHash = await getCommitHashForRefName({
534+
const isEmpty = await isRepoEmpty({ path: repoPath });
535+
const commitHash = isEmpty ? undefined : await getCommitHashForRefName({
535536
path: repoPath,
536537
refName: 'HEAD',
537538
});

0 commit comments

Comments
 (0)