Files
orca/src/main/git/commit-object-ref.ts
T
OrcaWinandOrcaWin 5655698147 fix(git): recognize full SHA-256 commit IDs as local workspace bases (#35010)
isFullGitObjectId only matched 40-hex IDs, so a saved 64-hex commit base in a SHA-256 repo was treated as missing, triggering an unneeded origin fetch and a fallback to the default branch.

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-30 06:50:25 -07:00

21 lines
572 B
TypeScript

type GitExec = (args: string[]) => Promise<unknown>
const FULL_GIT_OBJECT_ID_PATTERN = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i
export function isFullGitObjectId(value: string): boolean {
return FULL_GIT_OBJECT_ID_PATTERN.test(value.trim())
}
export async function hasCommitObjectViaGitExec(gitExec: GitExec, ref: string): Promise<boolean> {
const candidate = ref.trim()
if (!isFullGitObjectId(candidate)) {
return false
}
try {
await gitExec(['rev-parse', '--verify', '--quiet', `${candidate}^{commit}`])
return true
} catch {
return false
}
}