Files
orca/src/main/project-runtime-git-options.ts
T
bfbdcd7e80 feat(wsl): run Git for Windows for a WSL project on a Windows drive (D1c-2) (#33090)
* feat(wsl): run Git for Windows for a WSL project on a Windows drive

A project on C:\ whose runtime is WSL ran every Orca Git command through wsl.exe on
/mnt/c: ~300x slower than Windows Git, and blind to Windows-side edits. The project's
WSL runtime preference gains an optional `git: 'windows-host'`. With it, Orca's Git
(and where new worktrees go) is Windows; terminals, agents, accounts and hooks still
resolve to WSL, so nothing else changes. Older builds drop the field and go back to WSL
Git.

The conversion checks first, then the caller saves the returned preference through the
normal project update:
- Git for Windows must exist.
- New worktrees must not be set to go inside the distro.
- No linked worktree may have a Linux-path link. WSL Git made those; Windows Git sees
  them as prunable, and Orca's prune after a worktree removal would delete their
  metadata.
- Optionally writes core.autocrlf=true into the repo when Windows Git uses it, so WSL
  Git in the project's terminals stops seeing CRLF changes. Never core.checkStat.

IPC is refused off Windows and with the internal WSL hosts gate closed.

Co-Authored-By: Claude <noreply@anthropic.com>

* test(wsl): mock the drive-project IPC in the core handler registration test

Co-Authored-By: Claude <noreply@anthropic.com>

* test(wsl): pin WSL Git for a drive project that never chose Windows Git, and record which Git ran

* fix(wsl): base-ref lookups and the remote-identity sweep run Git where the project's runtime does

* fix(wsl): route base-ref and remote-identity reads by runtime only with WSL hosts on

These reads ran host Git on main. Routing them into a WSL-runtime project's
distro is part of D1c, so with the WSL hosts gate closed they run host Git
exactly as before.

(cherry picked from commit 2ed82987dc5b82c3a86ea7e03ce05e9efc3e77fb)

* refactor(ipc): register the filesystem handlers in one call, keeping core registration under its line cap

The optional commit-message resolvers pass straight through, so the call is the same with or
without them. #34059 left this file at the 300-line cap and the WSL drive-project wiring adds to it.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(wsl): skip folder repos in the Windows Git check, and read worktree links with the prune guard's reader

Folder repos run no Git, so rev-parse on them always failed the preview. The link reader and
the WSL-authored test now come from worktree-prune-guard.ts; the copy's startsWith('/') wrongly
refused //wsl.localhost links, which Windows Git writes itself.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(wsl): the remote-identity sweep checks the distro a drive project's Git runs in, so it never boots a stopped one

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-28 15:15:26 -07:00

127 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Repo } from '../shared/repo-types'
import { isFolderRepo } from '../shared/repo-kind'
import {
resolveLocalProjectRuntimeForRepo,
type ProjectRuntimeResolutionStore
} from './local-project-runtime-resolution'
import type { ProjectExecutionRuntimeResolution } from '../shared/project-execution-runtime'
import { wslHostsGateOpen } from './wsl/wsl-host-gate'
export {
resolveLocalProjectRuntimeForRepo,
resolveLocalProjectRuntimesForRepos
} from './local-project-runtime-resolution'
export type LocalProjectGitExecOptions = {
cwd: string
wslDistro?: string
}
export type LocalProjectWorktreeGitOptions = {
wslDistro?: string
}
export type LocalProjectGhExecOptions = LocalProjectWorktreeGitOptions & {
ghAccount?: Repo['ghAccount']
}
export function getLocalProjectGitExecOptions(
store: ProjectRuntimeResolutionStore,
repo: Repo
): LocalProjectGitExecOptions {
// Keep Git aligned with agent/terminal runtimes; repair states must not silently select host Git.
return getLocalProjectGitExecOptionsForRuntime(
repo,
resolveLocalProjectRuntimeForRepo(store, repo)
)
}
function getLocalProjectGitExecOptionsForRuntime(
repo: Repo,
projectRuntime: ProjectExecutionRuntimeResolution | undefined
): LocalProjectGitExecOptions {
if (!projectRuntime) {
return { cwd: repo.path }
}
if (projectRuntime.status === 'repair-required') {
throw new Error(
`Project runtime requires repair before git execution: ${projectRuntime.repair.reason}`
)
}
if (projectRuntime.runtime.kind === 'wsl' && projectRuntime.runtime.git !== 'windows-host') {
return { cwd: repo.path, wslDistro: projectRuntime.runtime.distro }
}
return { cwd: repo.path }
}
export function getLocalProjectWorktreeGitOptions(
store: ProjectRuntimeResolutionStore,
repo: Repo
): LocalProjectWorktreeGitOptions {
const { wslDistro } = getLocalProjectGitExecOptions(store, repo)
return wslDistro ? { wslDistro } : {}
}
/** Include the repo’s gh account binding; worktree Git options alone use the ambient login. */
export function getLocalProjectGhExecOptions(
store: ProjectRuntimeResolutionStore,
repo: Repo
): LocalProjectGhExecOptions {
return {
...getLocalProjectWorktreeGitOptions(store, repo),
...(repo.ghAccount ? { ghAccount: repo.ghAccount } : {})
}
}
/** Speculative prefetch falls back to host Git for unresolved runtimes instead of raising a repair error. */
export function getWorktreeCreatePrefetchGitOptions(
store: ProjectRuntimeResolutionStore,
repo: Repo
): LocalProjectWorktreeGitOptions {
if (isFolderRepo(repo)) {
return {}
}
const projectRuntime = resolveLocalProjectRuntimeForRepo(store, repo)
if (!projectRuntime || projectRuntime.status !== 'resolved') {
return {}
}
return getLocalProjectWorktreeGitOptionsForRuntime(repo, projectRuntime)
}
/** Base-ref and remote-identity reads follow the runtime only with WSL hosts on; before, host Git. */
export function getProjectRuntimeReadGitOptions(
store: ProjectRuntimeResolutionStore,
repo: Repo
): LocalProjectWorktreeGitOptions {
return wslHostsGateOpen() ? getWorktreeCreatePrefetchGitOptions(store, repo) : {}
}
export function getLocalProjectWorktreeGitOptionsForRuntime(
repo: Repo,
projectRuntime: ProjectExecutionRuntimeResolution | undefined
): LocalProjectWorktreeGitOptions {
// Reuse batch-resolved runtimes to avoid rescanning projects per repo during polls.
const { wslDistro } = getLocalProjectGitExecOptionsForRuntime(repo, projectRuntime)
return wslDistro ? { wslDistro } : {}
}
/** Unresolved runtimes retain Windows-side worktree placement instead of blocking creation. */
export function getWorktreeMirrorDistro(
store: ProjectRuntimeResolutionStore,
repo: Repo
): string | undefined {
return getWorktreeMirrorDistroForRuntime(resolveLocalProjectRuntimeForRepo(store, repo))
}
export function getWorktreeMirrorDistroForRuntime(
projectRuntime: ProjectExecutionRuntimeResolution | undefined
): string | undefined {
if (!projectRuntime || projectRuntime.status !== 'resolved') {
return undefined
}
// Windows Git can't use a worktree WSL Git would create inside the distro.
return projectRuntime.runtime.kind === 'wsl' && projectRuntime.runtime.git !== 'windows-host'
? projectRuntime.runtime.distro
: undefined
}