Files
orca/src/main/runtime/runtime-github-worktree-base.ts
T
OrcaWinandm4air c5224f70d8 refactor(providers): delete the SSH git and filesystem providers and relay-only wiring (#27644)
* refactor(providers): delete the SSH git and filesystem providers and relay-only wiring

* refactor(ssh): drop relay-protocol exports only the deleted stream readers used

---------

Co-authored-by: m4air <m4air@Mac.localdomain>
2026-10-11 17:48:43 -07:00

77 lines
2.7 KiB
TypeScript

import type { GitHubPrStartPoint } from '../../shared/worktree/types'
import type { Repo } from '../../shared/repo-types'
import {
fetchPrHeadTrackingRef,
fetchGitHubPullRequestHeadRef
} from '../github/pr-head-tracking-ref'
import { resolveGitHubPrStartPoint } from '../github/pr-start-point'
import { resolveGitHubReviewHeadRemote } from '../github/review-head-remote'
import { gitExecFileAsync } from '../git/runner'
import {
getLocalProjectGitExecOptions,
getLocalProjectGhExecOptions
} from '../project-runtime-git-options'
import { SshHostNotServedError } from '../providers/ssh-host-not-served-error'
import { isFolderRepo } from '../../shared/repo-kind'
import type { Store } from '../persistence'
export type RuntimeGitHubWorktreeBaseArgs = {
repoSelector: string
prNumber: number
headRefName?: string
baseRefName?: string
isCrossRepository?: boolean
}
export async function resolveRuntimeGitHubWorktreeBase(
args: RuntimeGitHubWorktreeBaseArgs,
deps: { store: Store | null; resolveRepo: (selector: string) => Promise<Repo> }
): Promise<GitHubPrStartPoint | { error: string }> {
if (!deps.store) {
throw new Error('runtime_unavailable')
}
let repo: Repo
try {
repo = await deps.resolveRepo(args.repoSelector)
} catch {
return { error: 'Repo not found' }
}
if (isFolderRepo(repo)) {
return { error: 'Folder mode does not support creating worktrees.' }
}
if (repo.connectionId) {
throw new SshHostNotServedError(repo.connectionId)
}
const localGitExecOptions = getLocalProjectGitExecOptions(deps.store, repo)
const localGhOptions = getLocalProjectGhExecOptions(deps.store, repo)
const gitExec = (gitArgs: string[]) => gitExecFileAsync(gitArgs, localGitExecOptions)
const resolveRemote = (): Promise<string> =>
resolveGitHubReviewHeadRemote({
repoPath: repo.path,
issueSourcePreference: repo.issueSourcePreference,
connectionId: null,
localGitOptions: localGhOptions,
gitExec
})
const fetchRemoteTrackingRef = (remote: string, branch: string): Promise<void> =>
fetchPrHeadTrackingRef(repo, remote, branch, { localGitExecOptions })
const fetchPullRequestHeadRef = (remote: string, prNumber: number): Promise<string> =>
fetchGitHubPullRequestHeadRef(repo, remote, prNumber, {
localGitExecOptions
})
return resolveGitHubPrStartPoint({
repoPath: repo.path,
prNumber: args.prNumber,
headRefName: args.headRefName,
baseRefName: args.baseRefName,
isCrossRepository: args.isCrossRepository,
issueSourcePreference: repo.issueSourcePreference,
connectionId: null,
localGitOptions: localGhOptions,
gitExec,
fetchRemoteTrackingRef,
fetchPullRequestHeadRef,
resolveRemote
})
}