MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / getLocalDefaultBranch

Function getLocalDefaultBranch

packages/backend/src/git.ts:406–425  ·  view source on GitHub ↗
({
    path,
}: {
    path: string,
})

Source from the content-addressed store, hash-verified

404 * @returns The branch name (e.g., "main", "master") or undefined if HEAD is not a symbolic ref
405 */
406export const getLocalDefaultBranch = async ({
407 path,
408}: {
409 path: string,
410}) => {
411 const git = createGitClientForPath(path);
412
413 try {
414 const ref = await git.raw(['symbolic-ref', 'HEAD']);
415 // Returns something like "refs/heads/main\n", so trim and remove prefix
416 const trimmed = ref.trim();
417 const match = trimmed.match(/^refs\/heads\/(.+)$/);
418 if (match) {
419 return match[1];
420 }
421 } catch (error: unknown) {
422 console.error(`Failed to get local default branch for repository: ${path}`);
423 return undefined;
424 }
425}
426
427/**
428 * Gets the timestamp of the most recent commit across all branches.

Callers 3

indexRepositoryMethod · 0.85
onJobCompletedMethod · 0.85

Calls 1

createGitClientForPathFunction · 0.85

Tested by

no test coverage detected