mirror of
https://github.com/stablyai/orca.git
synced 2026-10-27 16:02:42 +00:00
refactor(git): split status.ts into source-control modules (#16393)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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 ''
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user