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>
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import type { GitRuntimeOptions } from './git-runtime-options'
|
|
import { gitOptionsForWorktree } from './git-runtime-options'
|
|
import { gitExecFileAsync } from './runner'
|
|
import { runWithGitReadCacheInvalidation } from './status'
|
|
|
|
/** Reject empty and option-like names here too: relay callers can bypass RPC schema validation. */
|
|
export function assertValidBranchName(branch: string): void {
|
|
if (branch.length === 0 || branch.startsWith('-')) {
|
|
throw new Error('invalid_branch_name')
|
|
}
|
|
}
|
|
|
|
/** Leave conflicting changes to Git; trailing -- disambiguates the branch from pathspecs. */
|
|
export async function checkoutBranch(
|
|
worktreePath: string,
|
|
branch: string,
|
|
options: GitRuntimeOptions = {}
|
|
): Promise<void> {
|
|
assertValidBranchName(branch)
|
|
await runWithGitReadCacheInvalidation(() =>
|
|
gitExecFileAsync(['checkout', branch, '--'], gitOptionsForWorktree(worktreePath, options))
|
|
)
|
|
}
|
|
|
|
/** for-each-ref avoids localized branch decoration; return the current branch first. */
|
|
export async function listLocalBranches(
|
|
worktreePath: string,
|
|
options: GitRuntimeOptions = {}
|
|
): Promise<{ current: string | null; branches: string[] }> {
|
|
const { stdout } = await gitExecFileAsync(
|
|
['for-each-ref', '--format=%(HEAD)%09%(refname:short)', 'refs/heads/'],
|
|
gitOptionsForWorktree(worktreePath, options)
|
|
)
|
|
let current: string | null = null
|
|
const branches: string[] = []
|
|
for (const line of stdout.split('\n')) {
|
|
if (line.length === 0) {
|
|
continue
|
|
}
|
|
const [marker, name] = line.split('\t')
|
|
if (!name) {
|
|
continue
|
|
}
|
|
if (marker === '*') {
|
|
current = name
|
|
}
|
|
branches.push(name)
|
|
}
|
|
branches.sort((a, b) => {
|
|
if (a === current) {
|
|
return -1
|
|
}
|
|
if (b === current) {
|
|
return 1
|
|
}
|
|
return 0
|
|
})
|
|
return { current, branches }
|
|
}
|