mirror of
https://github.com/stablyai/orca.git
synced 2026-10-20 16:03:20 +00:00
* fix(worktrees): fall back from stale default base refs (#7312) * docs(worktrees): explain base fallback policy * fix(worktrees): harden stale base fallback edge cases --------- Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { getActiveMultiplexer } from './ssh'
|
|
|
|
const SSH_CONNECTION_UNAVAILABLE_MESSAGE =
|
|
'SSH connection is not available. Please reconnect and try again.'
|
|
|
|
type SshRootRegistrationMux = {
|
|
request: (method: 'session.registerRoot', payload: { rootPath: string }) => Promise<unknown>
|
|
notify: (method: 'session.registerRoot', payload: { rootPath: string }) => void
|
|
}
|
|
|
|
async function registerSshWorktreeCreateRoots(
|
|
mux: SshRootRegistrationMux,
|
|
rootPaths: string[]
|
|
): Promise<void> {
|
|
try {
|
|
await Promise.all(
|
|
rootPaths.map((rootPath) => mux.request('session.registerRoot', { rootPath }))
|
|
)
|
|
} catch (err) {
|
|
if (err instanceof Error && err.message.includes('Method not found')) {
|
|
for (const rootPath of rootPaths) {
|
|
mux.notify('session.registerRoot', { rootPath })
|
|
}
|
|
return
|
|
}
|
|
throw err
|
|
}
|
|
}
|
|
|
|
export async function registerOptionalSshWorktreeCreateRoots(
|
|
connectionId: string,
|
|
rootPaths: string[]
|
|
): Promise<void> {
|
|
const mux = getActiveMultiplexer(connectionId)
|
|
if (!mux) {
|
|
return
|
|
}
|
|
await registerSshWorktreeCreateRoots(mux, rootPaths)
|
|
}
|
|
|
|
export async function registerRequiredSshWorktreeCreateRoots(
|
|
connectionId: string,
|
|
rootPaths: string[]
|
|
): Promise<void> {
|
|
const mux = getActiveMultiplexer(connectionId)
|
|
if (!mux) {
|
|
throw new Error(SSH_CONNECTION_UNAVAILABLE_MESSAGE)
|
|
}
|
|
await registerSshWorktreeCreateRoots(mux, rootPaths)
|
|
}
|