diff --git a/src/main/git/repo-detection.test.ts b/src/main/git/repo-detection.test.ts index fff1b0840..56ae4a0fd 100644 --- a/src/main/git/repo-detection.test.ts +++ b/src/main/git/repo-detection.test.ts @@ -3,7 +3,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' -import { getGitRepoRoot, isGitRepo } from './repo' +import { getGitRepoRoot, isGitRepo, normalizeGitRepoRootForInputPath } from './repo' function git(cwd: string, args: string[]): string { return execFileSync('git', args, { cwd, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }) @@ -48,6 +48,15 @@ describe('isGitRepo', () => { expect(getGitRepoRoot(nestedDir)).toBe(expectedRoot) }) + it('keeps WSL UNC identity when git reports a Linux worktree root', () => { + expect( + normalizeGitRepoRootForInputPath( + String.raw`\\wsl.localhost\Ubuntu\home\alice\repo\packages\web`, + '/home/alice/repo' + ) + ).toBe(String.raw`\\wsl.localhost\Ubuntu\home\alice\repo`) + }) + it('preserves bare repository paths when no worktree root exists', () => { const bareRepo = path.join(tmpDir, 'bare.git') git(tmpDir, ['init', '--bare', '--quiet', bareRepo]) diff --git a/src/main/git/repo.ts b/src/main/git/repo.ts index f5b739353..c2219c4f6 100644 --- a/src/main/git/repo.ts +++ b/src/main/git/repo.ts @@ -6,6 +6,8 @@ import { gitExecFileSync, gitExecFileAsync } from './runner' import type { BaseRefSearchResult } from '../../shared/types' import { parseGitRevListAheadBehindCounts } from '../../shared/git-rev-list-output' import { normalizeRuntimePathSeparators } from '../../shared/cross-platform-path' +import { parseWslUncPath } from '../../shared/wsl-paths' +import { toWindowsWslPath } from '../wsl' import { buildHostedRemoteCommitUrl, buildHostedRemoteFileUrl, @@ -99,11 +101,10 @@ export function getGitRepoRoot(path: string): string { cwd: path }).trim() if (insideWorkTree === 'true') { - return normalizeRuntimePathSeparators( - gitExecFileSync(['rev-parse', '--show-toplevel'], { - cwd: path - }).trim() - ) + const root = gitExecFileSync(['rev-parse', '--show-toplevel'], { + cwd: path + }).trim() + return normalizeGitRepoRootForInputPath(path, root) } } catch { // Fall through to preserving the original path. @@ -111,6 +112,16 @@ export function getGitRepoRoot(path: string): string { return path } +export function normalizeGitRepoRootForInputPath(inputPath: string, rootPath: string): string { + const inputWsl = parseWslUncPath(inputPath) + if (inputWsl && rootPath.startsWith('/')) { + // Why: WSL git reports Linux-native roots; Orca must persist the UNC path so + // later local git calls keep routing through the WSL-aware runner. + return toWindowsWslPath(rootPath, inputWsl.distro) + } + return normalizeRuntimePathSeparators(rootPath) +} + /** * Get a human-readable name for the repo from its path. */