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

Function getRemoteDefaultBranch

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

Source from the content-addressed store, hash-verified

374 * @returns The branch name (e.g., "main", "master") or undefined if it cannot be determined
375 */
376export const getRemoteDefaultBranch = async ({
377 path,
378 cloneUrl,
379}: {
380 path: string,
381 cloneUrl: string,
382}) => {
383 const git = createGitClientForPath(path);
384 try {
385 const remoteHead = await git.raw(['ls-remote', '--symref', cloneUrl, 'HEAD']);
386 const match = remoteHead.match(/^ref: refs\/heads\/(\S+)\s+HEAD/m);
387 if (match) {
388 return match[1];
389 }
390 } catch (error: unknown) {
391 // Avoid printing error here since cloneUrl may contain credentials.
392 console.error(`Failed to get remote default branch for repository: ${path}`);
393 return undefined;
394 }
395}
396
397/**
398 * Gets the branch name that the local HEAD symbolic ref points to.

Callers 1

fetchRepositoryFunction · 0.85

Calls 1

createGitClientForPathFunction · 0.85

Tested by

no test coverage detected