({
path,
}: {
path: string,
})
| 404 | * @returns The branch name (e.g., "main", "master") or undefined if HEAD is not a symbolic ref |
| 405 | */ |
| 406 | export 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. |
no test coverage detected