Files
orca/src/main/ipc/local-worktree-runtime-options.ts
T
0ec3882cb8 Add project Windows runtime selection (#5519)
* Add project Windows runtime selection

* Fix project Windows runtime selection

Co-authored-by: Orca <help@stably.ai>

* fix: preserve WSL shell variables

---------

Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Neil <neil@stably.ai>
2026-06-17 16:08:14 -07:00

62 lines
1.9 KiB
TypeScript

import { resolve } from 'path'
import type { Store } from '../persistence'
import {
getLocalProjectWorktreeGitOptions,
type LocalProjectWorktreeGitOptions
} from '../project-runtime-git-options'
import { splitWorktreeId } from '../../shared/worktree-id'
function comparableLocalPath(value: string): string {
const normalized = resolve(value)
return process.platform === 'win32' ? normalized.toLowerCase() : normalized
}
function getCandidateLocalWorktreePaths(
worktreePath: string,
resolvedWorktreePath: string
): Set<string> {
return new Set([worktreePath, resolvedWorktreePath].map(comparableLocalPath))
}
function hasRegisteredWorktreeMetaForRepo(
store: Store,
repoId: string,
candidatePaths: Set<string>
): boolean {
const worktreeMeta =
typeof store.getAllWorktreeMeta === 'function' ? store.getAllWorktreeMeta() : {}
for (const worktreeId of Object.keys(worktreeMeta)) {
const parsed = splitWorktreeId(worktreeId)
if (parsed?.repoId === repoId && candidatePaths.has(comparableLocalPath(parsed.worktreePath))) {
return true
}
}
return false
}
export function getLocalGitOptionsForRegisteredWorktree(
store: Store,
worktreePath: string,
resolvedWorktreePath: string
): LocalProjectWorktreeGitOptions {
if (typeof store.getProjects !== 'function' || typeof store.getSettings !== 'function') {
return {}
}
const candidatePaths = getCandidateLocalWorktreePaths(worktreePath, resolvedWorktreePath)
for (const repo of store.getRepos()) {
if (repo.connectionId) {
continue
}
if (
candidatePaths.has(comparableLocalPath(repo.path)) ||
hasRegisteredWorktreeMetaForRepo(store, repo.id, candidatePaths)
) {
// Why: file discovery must use the same resolved runtime as project git,
// terminals, and agents even when the worktree path is a Windows path.
return getLocalProjectWorktreeGitOptions(store, repo)
}
}
return {}
}