mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 18:47:40 +00:00
* [comment audit] Shorten daemon, hook, and emulator comments [skip ci] * [comment audit] Shorten VM, conversation, SQLite, and theme-import comments [skip ci] * [comment audit] Tighten Git execution and source-control comment contracts [skip ci] * [comment audit] Clarify repository probes and maintenance comments [skip ci] * [comment audit] Shorten status, diff-cache, and checkout comments [skip ci] * [comment audit] Clarify worktree lifecycle and WSL routing comments [skip ci] * [comment audit] Shorten forge identity and review-refresh comments [skip ci] * [comment audit] Tighten hosted-review client comment contracts [skip ci] * [comment audit] Clarify GitLab compatibility and review comments [skip ci] * [comment audit] Tighten hook ownership and watchdog rationale [skip ci] * [comment audit] Condense host and integration compatibility comments [skip ci] * [comment audit] Clarify IPC authority and remote-routing rationale [skip ci] * [comment audit] Finalize file-import and containment comment cleanup * [comment audit] Fix stale Jira type imports blocking full CI --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import type { GitAdmissionTier } from '../../shared/rpc-contract/git-admission-tier-params'
|
|
import { gitExecFileAsync } from './runner'
|
|
import { isShowRefNoMatchError } from './exact-ref-probe'
|
|
import { hasCommitObjectViaGitExec } from './commit-object-ref'
|
|
import { isSafeGitRefName } from '../../shared/git-status-upstream-ref'
|
|
import { resolveWorktreeAddBaseRef } from '../../shared/worktree/base-ref'
|
|
|
|
type GitExecOptions = {
|
|
wslDistro?: string
|
|
admissionTier?: GitAdmissionTier
|
|
}
|
|
|
|
/** Return the probe's commit OID so callers need not resolve it again. */
|
|
export async function resolveWorktreeBaseCommitOid(
|
|
repoPath: string,
|
|
qualifiedRef: string,
|
|
options: GitExecOptions = {}
|
|
): Promise<string | null> {
|
|
try {
|
|
const { stdout } = await gitExecFileAsync(
|
|
['rev-parse', '--verify', '--quiet', `${qualifiedRef}^{commit}`],
|
|
{
|
|
cwd: repoPath,
|
|
...options
|
|
}
|
|
)
|
|
const oid = stdout.trim()
|
|
return oid.length > 0 ? oid : null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export async function hasWorktreeBaseCommitRef(
|
|
repoPath: string,
|
|
qualifiedRef: string,
|
|
options: GitExecOptions = {}
|
|
): Promise<boolean> {
|
|
return (await resolveWorktreeBaseCommitOid(repoPath, qualifiedRef, options)) !== null
|
|
}
|
|
|
|
/** Compare resolved qualified refs so aliases such as main and refs/heads/main share one base. */
|
|
export function resolveLocalWorktreeBaseRef(
|
|
repoPath: string,
|
|
baseRef: string,
|
|
options: GitExecOptions = {}
|
|
): Promise<string> {
|
|
return resolveWorktreeAddBaseRef(baseRef, (qualifiedRef) =>
|
|
hasWorktreeBaseCommitRef(repoPath, qualifiedRef, options)
|
|
)
|
|
}
|
|
|
|
/** Creation and prefetch share this presence check so they agree on reusable local bases. */
|
|
export async function hasLocalWorktreeBaseRef(
|
|
repoPath: string,
|
|
baseRef: string,
|
|
options: GitExecOptions = {}
|
|
): Promise<boolean> {
|
|
const refExists = (qualifiedRef: string) =>
|
|
hasWorktreeBaseCommitRef(repoPath, qualifiedRef, options)
|
|
const resolvedBaseRef = await resolveWorktreeAddBaseRef(baseRef, refExists)
|
|
if (resolvedBaseRef !== baseRef) {
|
|
return true
|
|
}
|
|
if (baseRef.startsWith('refs/')) {
|
|
return refExists(baseRef)
|
|
}
|
|
return hasCommitObjectViaGitExec(
|
|
(gitArgs) => gitExecFileAsync(gitArgs, { cwd: repoPath, ...options }),
|
|
baseRef
|
|
)
|
|
}
|
|
|
|
export type WorktreeBaseRefPresence = 'present' | 'absent' | 'unknown'
|
|
|
|
/** Exact ref probes preserve unknown on execution failure; inject the runner to support relay hosts too. */
|
|
export async function probeWorktreeBaseRefPresence(
|
|
runGit: (args: string[]) => Promise<{ stdout: string }>,
|
|
qualifiedRef: string
|
|
): Promise<WorktreeBaseRefPresence> {
|
|
if (!isSafeGitRefName(qualifiedRef)) {
|
|
return 'unknown'
|
|
}
|
|
try {
|
|
await runGit(['show-ref', '--verify', '--quiet', '--', qualifiedRef])
|
|
return 'present'
|
|
} catch (error) {
|
|
return isShowRefNoMatchError(error) ? 'absent' : 'unknown'
|
|
}
|
|
}
|