Skip to content

Commit 99af592

Browse files
committed
fix: convert Windows paths to POSIX for Git Bash commands
Add toPosixPath() utility that uses cygpath to convert Windows paths (C:\foo\bar) to POSIX format (/c/foo/bar) for Git Bash compatibility. Apply to: - LocalBaseRuntime.spawnBackground: exitCodePath, cwd, stdoutPath, stderrPath - WorktreeRuntime.deleteWorkspace: deletedPath for rm -rf - runtimeFactory.getDefaultBgOutputDir: refactored to use shared utility
1 parent 9d4b49d commit 99af592

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

src/node/runtime/LocalBaseRuntime.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
import { LocalBackgroundHandle } from "./LocalBackgroundHandle";
3535
import { buildWrapperScript, buildSpawnCommand } from "./backgroundCommands";
3636
import { log } from "@/node/services/log";
37+
import { toPosixPath } from "@/node/utils/paths";
3738

3839
/**
3940
* Abstract base class for local runtimes (both WorktreeRuntime and LocalRuntime).
@@ -359,17 +360,18 @@ export abstract class LocalBaseRuntime implements Runtime {
359360
await fsPromises.writeFile(stderrPath, "");
360361

361362
// Build wrapper script and spawn command using shared builders (same as SSH for parity)
363+
// On Windows, convert paths to POSIX format for Git Bash (C:\foo → /c/foo)
362364
const wrapperScript = buildWrapperScript({
363-
exitCodePath,
364-
cwd: options.cwd,
365+
exitCodePath: toPosixPath(exitCodePath),
366+
cwd: toPosixPath(options.cwd),
365367
env: { ...options.env, ...NON_INTERACTIVE_ENV_VARS },
366368
script,
367369
});
368370

369371
const spawnCommand = buildSpawnCommand({
370372
wrapperScript,
371-
stdoutPath,
372-
stderrPath,
373+
stdoutPath: toPosixPath(stdoutPath),
374+
stderrPath: toPosixPath(stderrPath),
373375
bashPath: getBashPath(),
374376
niceness: options.niceness,
375377
useSetsid: process.platform !== "win32",

src/node/runtime/WorktreeRuntime.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getProjectName } from "@/node/utils/runtime/helpers";
1717
import { getErrorMessage } from "@/common/utils/errors";
1818
import { expandTilde } from "./tildeExpansion";
1919
import { LocalBaseRuntime } from "./LocalBaseRuntime";
20+
import { toPosixPath } from "@/node/utils/paths";
2021

2122
/**
2223
* Worktree runtime implementation that executes commands and file operations
@@ -285,7 +286,8 @@ export class WorktreeRuntime extends LocalBaseRuntime {
285286
}
286287

287288
// Force delete the directory (use bash shell for rm -rf on Windows)
288-
using rmProc = execAsync(`rm -rf "${deletedPath}"`, { shell: getBashPath() });
289+
// Convert to POSIX path for Git Bash compatibility on Windows
290+
using rmProc = execAsync(`rm -rf "${toPosixPath(deletedPath)}"`, { shell: getBashPath() });
289291
await rmProc.result;
290292

291293
return { success: true, deletedPath };

src/node/runtime/runtimeFactory.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { execSync } from "child_process";
21
import * as os from "os";
32

43
import type { Runtime } from "./Runtime";
@@ -8,6 +7,7 @@ import { SSHRuntime } from "./SSHRuntime";
87
import type { RuntimeConfig } from "@/common/types/runtime";
98
import { hasSrcBaseDir } from "@/common/types/runtime";
109
import { isIncompatibleRuntimeConfig } from "@/common/utils/runtimeCompatibility";
10+
import { toPosixPath } from "@/node/utils/paths";
1111

1212
// Re-export for backward compatibility with existing imports
1313
export { isIncompatibleRuntimeConfig };
@@ -19,17 +19,7 @@ export { isIncompatibleRuntimeConfig };
1919
*/
2020
function getDefaultBgOutputDir(): string {
2121
const tempDir = os.tmpdir();
22-
if (process.platform === "win32") {
23-
try {
24-
// cygpath converts Windows paths to POSIX format for Git Bash / MSYS2
25-
const posixPath = execSync(`cygpath -u "${tempDir}"`, { encoding: "utf8" }).trim();
26-
return `${posixPath}/mux-bashes`;
27-
} catch {
28-
// Fallback if cygpath unavailable (shouldn't happen with Git Bash)
29-
return "/tmp/mux-bashes";
30-
}
31-
}
32-
return `${tempDir}/mux-bashes`;
22+
return `${toPosixPath(tempDir)}/mux-bashes`;
3323
}
3424

3525
/**

src/node/utils/paths.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { execSync } from "child_process";
2+
3+
/**
4+
* Convert a path to POSIX format for Git Bash on Windows.
5+
* On non-Windows platforms, returns the path unchanged.
6+
*
7+
* Use this when building shell command strings that will run in Git Bash,
8+
* where Windows-style paths (C:\foo\bar) don't work.
9+
*/
10+
export function toPosixPath(windowsPath: string): string {
11+
if (process.platform !== "win32") return windowsPath;
12+
try {
13+
// cygpath converts Windows paths to POSIX format for Git Bash / MSYS2
14+
return execSync(`cygpath -u "${windowsPath}"`, { encoding: "utf8" }).trim();
15+
} catch {
16+
// Fallback if cygpath unavailable (shouldn't happen with Git Bash)
17+
return windowsPath;
18+
}
19+
}

0 commit comments

Comments
 (0)