mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
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>
21 lines
572 B
TypeScript
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
|
|
}
|
|
}
|