* 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>
62 lines
1.9 KiB
TypeScript
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 {}
|
|
}
|