mirror of
https://github.com/stablyai/orca.git
synced 2026-10-03 16:02:11 +00:00
* Split speech session lifecycle * Split terminal output scheduler pipeline * Split mobile browser pane modules * Prune resolved max-lines suppressions * Split pane tree equalization logic * Extract mobile troubleshoot screen styles * Split external automation manager * Split main window service attachments * Split hosted review creation checks * Split automation dispatch event handling * Split settings navigation metadata * Split daemon initialization lifecycle * Split GitLab item dialog * Split relay dispatcher layers * Split mobile host screen * Retarget mobile view settings source test * Split runtime file client layers * Split ports panel layers * Split runtime environments pane layers * Split local PTY provider responsibilities * Split CDP bridge responsibilities * Split relay Git handler responsibilities * Track moved relay Git fetch audit * Fix F3-speech for #17123 * Fix F1-cycle for #17131 * Fix F4-navtest for #17157 * Fix F2-allowlist for #17161
77 lines
3.2 KiB
TypeScript
77 lines
3.2 KiB
TypeScript
import type { RequestContext } from './dispatcher'
|
|
import { GitHandlerOperationContext } from './git-handler-operation-context'
|
|
import { validateGitExecArgs } from './git-handler-ops'
|
|
import { gitExecMutatesRepository } from '../shared/git-exec-mutation'
|
|
import { normalizeGitErrorMessage } from '../shared/git-remote-error'
|
|
import { forceDeletePreservedRelayBranch } from './git-handler-branch-cleanup'
|
|
|
|
export class GitHandlerExecOperations extends GitHandlerOperationContext {
|
|
async exec(params: Record<string, unknown>, context?: RequestContext) {
|
|
const args = params.args as string[]
|
|
const cwd = params.cwd as string
|
|
|
|
validateGitExecArgs(args)
|
|
const run = () => this.git(args, cwd, { signal: context?.signal })
|
|
const { stdout, stderr } = gitExecMutatesRepository(args)
|
|
? await this.runWithGitReadCacheClear(run)
|
|
: await run()
|
|
return this.maybeStreamResponse({ stdout, stderr }, params, context)
|
|
}
|
|
|
|
async clone(params: Record<string, unknown>, context?: RequestContext) {
|
|
const args = params.args as string[]
|
|
const cwd = params.cwd as string
|
|
const progressId = params.progressId
|
|
validateGitExecArgs(args)
|
|
if (typeof progressId !== 'string' || progressId.length === 0) {
|
|
throw new Error('Missing clone progress id.')
|
|
}
|
|
if (args[0] !== 'clone') {
|
|
throw new Error('git.clone only supports clone commands.')
|
|
}
|
|
return await this.runWithGitReadCacheClear(() =>
|
|
this.spawnClone(args, cwd, progressId, context)
|
|
)
|
|
}
|
|
|
|
async renameCurrentBranch(params: Record<string, unknown>) {
|
|
return this.runWithGitReadCacheClear(async () => {
|
|
const worktreePath = params.worktreePath
|
|
const newBranch = params.newBranch
|
|
if (typeof worktreePath !== 'string' || typeof newBranch !== 'string') {
|
|
throw new Error('Invalid branch rename request.')
|
|
}
|
|
if (newBranch.startsWith('-')) {
|
|
throw new Error('Branch name must not start with "-".')
|
|
}
|
|
try {
|
|
// Why: generic git.exec blocks destructive branch flags; this narrow RPC permits only the already-checked current-branch rename.
|
|
await this.git(['check-ref-format', '--branch', newBranch], worktreePath)
|
|
await this.git(['branch', '-m', newBranch], worktreePath)
|
|
} catch (error) {
|
|
throw new Error(normalizeGitErrorMessage(error))
|
|
}
|
|
})
|
|
}
|
|
|
|
async forceDeletePreservedBranch(params: Record<string, unknown>) {
|
|
const repoPath = params.repoPath
|
|
const branchName = params.branchName
|
|
const expectedHead = params.expectedHead
|
|
if (
|
|
typeof repoPath !== 'string' ||
|
|
typeof branchName !== 'string' ||
|
|
typeof expectedHead !== 'string'
|
|
) {
|
|
throw new Error('Invalid preserved branch force-delete request.')
|
|
}
|
|
// Why: empty repoPath would target the relay's own cwd with a destructive update-ref, and NUL bytes can't reach git safely — reject both.
|
|
if (!repoPath || repoPath.includes('\0') || expectedHead.includes('\0')) {
|
|
throw new Error('Invalid preserved branch force-delete request.')
|
|
}
|
|
return this.runWithGitReadCacheClear(() =>
|
|
forceDeletePreservedRelayBranch(this.git.bind(this), repoPath, branchName, expectedHead)
|
|
)
|
|
}
|
|
}
|