mirror of
https://github.com/stablyai/orca.git
synced 2026-10-27 16:02:42 +00:00
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import type { GitRuntimeOptions } from '../git-runtime-options'
|
|
import { gitOptionsForWorktree } from '../git-runtime-options'
|
|
import { gitExecFileAsync, gitOptionalLocksDisabledEnv } from '../runner'
|
|
|
|
export async function readGitlinkOidFromTree(
|
|
worktreePath: string,
|
|
ref: string,
|
|
submodulePath: string,
|
|
options: GitRuntimeOptions
|
|
): Promise<string> {
|
|
try {
|
|
const { stdout } = await gitExecFileAsync(['ls-tree', ref, '--', submodulePath], {
|
|
...gitOptionsForWorktree(worktreePath, options),
|
|
env: gitOptionalLocksDisabledEnv()
|
|
})
|
|
return stdout.match(/^160000 commit ([0-9a-f]+)\t/m)?.[1] ?? ''
|
|
} catch {
|
|
return ''
|
|
}
|
|
}
|
|
|
|
export async function readGitlinkOidFromIndex(
|
|
worktreePath: string,
|
|
submodulePath: string,
|
|
options: GitRuntimeOptions
|
|
): Promise<string> {
|
|
try {
|
|
const { stdout } = await gitExecFileAsync(['ls-files', '-s', '--', submodulePath], {
|
|
...gitOptionsForWorktree(worktreePath, options),
|
|
env: gitOptionalLocksDisabledEnv()
|
|
})
|
|
return stdout.match(/^160000 ([0-9a-f]+) /m)?.[1] ?? ''
|
|
} catch {
|
|
return ''
|
|
}
|
|
}
|
|
|
|
export async function readWorkingSubmoduleHead(
|
|
submoduleWorktreePath: string,
|
|
options: GitRuntimeOptions
|
|
): Promise<string> {
|
|
try {
|
|
const { stdout } = await gitExecFileAsync(['rev-parse', 'HEAD'], {
|
|
...gitOptionsForWorktree(submoduleWorktreePath, options),
|
|
env: gitOptionalLocksDisabledEnv()
|
|
})
|
|
return stdout.trim()
|
|
} catch {
|
|
return ''
|
|
}
|
|
}
|