The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 01:45 UTC
fix(server): changed files keep their real paths for renames and non-ASCII names (#20175)
Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Atharvsinh Jadav committed
Oct 19, 2026 at 22:37 UTC
771fd93fc591de5fe1bfd66cf1b4faa39eb8547c
5 files changed
+231
-89
apps/server/src/vcs/GitVcsDriverCore.test.ts
+92
-1
@@ -333,7 +333,7 @@ it.effect("uses stable diagnostics for every parsed non-repository command", ()
333
334
assert.deepStrictEqual(commands, [
335
{ args: ["rev-parse", "--git-path", "index"], lcAll: "C" },
336
- { args: ["status", "--porcelain=2", "--branch"], lcAll: "C" },
336
+ { args: ["status", "--porcelain=2", "--branch", "-z"], lcAll: "C" },
337
{ args: ["rev-parse", "--abbrev-ref", "HEAD"], lcAll: "C" },
338
{ args: ["rev-parse", "--git-common-dir"], lcAll: "C" },
339
]);
@@ -2643,6 +2643,97 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
2643
}),
2644
);
2645
2646
+ it.effect("reports renamed and non-ASCII files by paths that can be committed", () =>
2647
+ Effect.gen(function* () {
2648
+ const cwd = yield* makeTmpDir();
2649
+ yield* initRepoWithCommit(cwd);
2650
+ yield* writeTextFile(cwd, "src/old.ts", "one\ntwo\nthree\n");
2651
+ yield* writeTextFile(cwd, "café notes.md", "draft\n");
2652
+ yield* git(cwd, ["add", "."]);
2653
+ yield* git(cwd, ["commit", "-m", "add files"]);
2654
+ yield* git(cwd, ["mv", "src/old.ts", "src/new.ts"]);
2655
+ yield* writeTextFile(cwd, "src/new.ts", "one\ntwo\nthree\nfour\n");
2656
+ yield* writeTextFile(cwd, "café notes.md", "draft\nedit\n");
2657
+ const driver = yield* GitVcsDriver.GitVcsDriver;
2658
+
2659
+ const status = yield* driver.statusDetails(cwd);
2660
+
2661
+ assert.deepEqual(status.workingTree.files, [
2662
+ { path: "café notes.md", insertions: 1, deletions: 0 },
2663
+ { path: "src/new.ts", insertions: 1, deletions: 0 },
2664
+ { path: "src/old.ts", insertions: 0, deletions: 0 },
2665
+ ]);
2666
+ yield* driver.commit(cwd, "Commit selection", "", {
2667
+ stage: { filePaths: status.workingTree.files.map((file) => file.path) },
2668
+ });
2669
+ assert.equal(yield* git(cwd, ["status", "--porcelain"]), "");
2670
+ }),
2671
+ );
2672
+
2673
+ it.effect("commits selected files from a nested project directory", () =>
2674
+ Effect.gen(function* () {
2675
+ const path = yield* Path.Path;
2676
+ // A root basename ending in whitespace catches a root lookup that trims Git's output.
2677
+ const cwd = path.join(yield* makeTmpDir(), "repo ");
2678
+ yield* (yield* FileSystem.FileSystem).makeDirectory(cwd);
2679
+ yield* initRepoWithCommit(cwd);
2680
+ yield* writeTextFile(cwd, "nested/tracked.txt", "one\n");
2681
+ yield* git(cwd, ["add", "."]);
2682
+ yield* git(cwd, ["commit", "-m", "add nested file"]);
2683
+ yield* writeTextFile(cwd, "nested/tracked.txt", "one\ntwo\n");
2684
+ yield* writeTextFile(cwd, "nested/new.txt", "new\n");
2685
+ yield* writeTextFile(cwd, "README.md", "# test\nleft out\n");
2686
+ const nestedCwd = path.join(cwd, "nested");
2687
+ const driver = yield* GitVcsDriver.GitVcsDriver;
2688
+
2689
+ const status = yield* driver.statusDetails(nestedCwd);
2690
+
2691
+ assert.deepEqual(status.workingTree.files, [
2692
+ { path: "nested/new.txt", insertions: 0, deletions: 0 },
2693
+ { path: "nested/tracked.txt", insertions: 1, deletions: 0 },
2694
+ { path: "README.md", insertions: 1, deletions: 0 },
2695
+ ]);
2696
+ // The root is what the paths above are relative to, not the nested cwd, and it keeps
2697
+ // the trailing space so the resolved editor target is the file that exists.
2698
+ assert.equal(status.workingTree.rootPath, NodeFS.realpathSync.native(cwd));
2699
+ assert.equal(
2700
+ NodeFS.existsSync(path.join(status.workingTree.rootPath!, "nested", "new.txt")),
2701
+ true,
2702
+ );
2703
+ yield* driver.commit(nestedCwd, "Commit nested selection", "", {
2704
+ stage: { filePaths: ["nested/new.txt", "nested/tracked.txt"] },
2705
+ });
2706
+ assert.equal(yield* git(cwd, ["status", "--porcelain"]), "M README.md");
2707
+ }),
2708
+ );
2709
+
2710
+ it.effect("reports the linked worktree as the root of a nested directory in it", () =>
2711
+ Effect.gen(function* () {
2712
+ const cwd = yield* makeTmpDir();
2713
+ const worktreePath = yield* makeTmpDir("git-vcs-driver-linked-");
2714
+ yield* initRepoWithCommit(cwd);
2715
+ yield* writeTextFile(cwd, "nested/tracked.txt", "one\n");
2716
+ yield* git(cwd, ["add", "."]);
2717
+ yield* git(cwd, ["commit", "-m", "add nested file"]);
2718
+ yield* git(cwd, ["worktree", "add", "-b", "feature/linked", worktreePath]);
2719
+ yield* writeTextFile(worktreePath, "nested/tracked.txt", "one\ntwo\n");
2720
+ yield* writeTextFile(worktreePath, "nested/new.txt", "new\n");
2721
+ const nestedCwd = (yield* Path.Path).join(worktreePath, "nested");
2722
+ const driver = yield* GitVcsDriver.GitVcsDriver;
2723
+
2724
+ const status = yield* driver.statusDetails(nestedCwd);
2725
+
2726
+ assert.deepEqual(status.workingTree.files, [
2727
+ { path: "nested/new.txt", insertions: 0, deletions: 0 },
2728
+ { path: "nested/tracked.txt", insertions: 1, deletions: 0 },
2729
+ ]);
2730
+ assert.equal(
2731
+ NodeFS.realpathSync.native(status.workingTree.rootPath!),
2732
+ NodeFS.realpathSync.native(worktreePath),
2733
+ );
2734
+ }),
2735
+ );
2736
+
2737
it.effect("reports default-branch delta separately from upstream delta", () =>
2738
Effect.gen(function* () {
2739
const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+47
-69
@@ -185,30 +185,6 @@ function parseBranchAb(value: string): { ahead: number; behind: number } {
185
};
186
}
187
188
-function parseNumstatEntries(
189
- stdout: string,
190
-): Array<{ path: string; insertions: number; deletions: number }> {
191
- const entries: Array<{ path: string; insertions: number; deletions: number }> = [];
192
- for (const line of stdout.split(/\r?\n/g)) {
193
- if (line.trim().length === 0) continue;
194
- const [addedRaw, deletedRaw, ...pathParts] = line.split("\t");
195
- const rawPath =
196
- pathParts.length > 1 ? (pathParts.at(-1) ?? "").trim() : pathParts.join("\t").trim();
197
- if (rawPath.length === 0) continue;
198
- const added = Number.parseInt(addedRaw ?? "0", 10);
199
- const deleted = Number.parseInt(deletedRaw ?? "0", 10);
200
- const renameArrowIndex = rawPath.indexOf(" => ");
201
- const normalizedPath =
202
- renameArrowIndex >= 0 ? rawPath.slice(renameArrowIndex + " => ".length).trim() : rawPath;
203
- entries.push({
204
- path: normalizedPath.length > 0 ? normalizedPath : rawPath,
205
- insertions: Number.isFinite(added) ? added : 0,
206
- deletions: Number.isFinite(deleted) ? deleted : 0,
207
- });
208
- }
209
- return entries;
210
-}
211
-
188
function parseReviewNumstat(stdout: string): ReviewDiffFileStat[] {
189
const fields = stdout.split("\0");
190
const files: ReviewDiffFileStat[] = [];
@@ -228,25 +204,20 @@ function parseReviewNumstat(stdout: string): ReviewDiffFileStat[] {
204
return files;
205
}
206
231
-function parsePorcelainPath(line: string): string | null {
232
- if (line.startsWith("? ") || line.startsWith("! ")) {
233
- const simple = line.slice(2).trim();
234
- return simple.length > 0 ? simple : null;
235
- }
236
-
237
- if (!(line.startsWith("1 ") || line.startsWith("2 ") || line.startsWith("u "))) {
238
- return null;
239
- }
240
-
241
- const tabIndex = line.indexOf("\t");
242
- if (tabIndex >= 0) {
243
- const fromTab = line.slice(tabIndex + 1);
244
- const [filePath] = fromTab.split("\t");
245
- return filePath?.trim().length ? filePath.trim() : null;
246
- }
207
+// Space-separated fields precede the path in each porcelain v2 record type. The path itself
208
+// may contain spaces, so it is everything after them.
209
+const PORCELAIN_V2_FIELDS_BEFORE_PATH: Record<string, number> = {
210
+ "1": 8,
211
+ "2": 9,
212
+ u: 10,
213
+ "?": 1,
214
+ "!": 1,
215
+};
216
248
- const parts = line.trim().split(/\s+/g);
249
- const filePath = parts.at(-1) ?? "";
217
+function parsePorcelainPath(record: string): string | null {
218
+ const fieldsBeforePath = PORCELAIN_V2_FIELDS_BEFORE_PATH[record[0] ?? ""];
219
+ if (fieldsBeforePath === undefined) return null;
220
+ const filePath = record.split(" ").slice(fieldsBeforePath).join(" ");
221
return filePath.length > 0 ? filePath : null;
222
}
223
@@ -1347,7 +1318,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1318
],
1319
{ concurrency: 2 },
1320
);
1350
- const worktreeRootOutput = worktreeRootResult.stdout.trim();
1321
+ // Git terminates --show-toplevel with exactly one "\n" on every platform (stdout is
1322
+ // binary mode on Windows). Whitespace before it belongs to the path and must survive,
1323
+ // because this root becomes the editor target for every repository-relative status path.
1324
+ const worktreeRootOutput = worktreeRootResult.stdout.endsWith("\n")
1325
+ ? worktreeRootResult.stdout.slice(0, -1)
1326
+ : worktreeRootResult.stdout;
1327
const worktreeRoot =
1328
worktreeRootResult.exitCode === 0 && worktreeRootOutput.length > 0
1329
? path.normalize(
@@ -1891,6 +1867,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1867
"status",
1868
"--porcelain=2",
1869
"--branch",
1870
+ "-z",
1871
...(includeDivergence ? [] : ["--no-ahead-behind"]),
1872
];
1873
const indexResult = yield* executeGitWithStableDiagnostics(
@@ -1968,48 +1945,37 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1945
Effect.catchTags({ GitCommandError: () => Effect.succeed(null) }),
1946
);
1947
const statusCacheKey = repositoryPaths?.gitCommonDir;
1971
- const [numstatStdout, defaultBranch, hasPrimaryRemote] = yield* Effect.all(
1948
+ const [numstatEntries, defaultBranch, hasPrimaryRemote] = yield* Effect.all(
1949
[
1950
// Plumbing, because porcelain `git diff` rewrites the index even with
1951
// GIT_OPTIONAL_LOCKS=0. -M keeps porcelain's rename detection.
1952
executeGitWithStableDiagnostics(
1953
"GitVcsDriver.statusDetails.numstat",
1954
cwd,
1978
- ["diff-index", "-M", "--numstat", "HEAD", "--"],
1955
+ ["diff-index", "-M", "--numstat", "-z", "HEAD", "--"],
1956
{ allowNonZeroExit: true },
1957
).pipe(
1958
Effect.flatMap((result) => {
1982
- if (result.exitCode === 0) return Effect.succeed(result.stdout);
1959
+ if (result.exitCode === 0) return Effect.succeed(parseReviewNumstat(result.stdout));
1960
if (isUnbornHeadStderr(result.stderr)) {
1961
return Effect.map(
1962
Effect.all([
1963
runGitStdout("GitVcsDriver.statusDetails.numstat.unborn", cwd, [
1964
"diff-files",
1965
"--numstat",
1966
+ "-z",
1967
]),
1968
runGitStdout("GitVcsDriver.statusDetails.numstat.unborn.staged", cwd, [
1969
"diff",
1970
"--cached",
1971
"--numstat",
1972
+ "-z",
1973
]),
1974
]),
1996
- ([unstagedStdout, stagedStdout]) => {
1997
- const staged = parseNumstatEntries(stagedStdout);
1998
- const unstaged = parseNumstatEntries(unstagedStdout);
1999
- const map = new Map<string, { insertions: number; deletions: number }>();
2000
- for (const entry of [...staged, ...unstaged]) {
2001
- const existing = map.get(entry.path) ?? {
2002
- insertions: 0,
2003
- deletions: 0,
2004
- };
2005
- existing.insertions += entry.insertions;
2006
- existing.deletions += entry.deletions;
2007
- map.set(entry.path, existing);
2008
- }
2009
- return Array.from(map.entries())
2010
- .map(([p, s]) => `${s.insertions}\t${s.deletions}\t${p}`)
2011
- .join("\n");
2012
- },
1975
+ ([unstagedStdout, stagedStdout]) => [
1976
+ ...parseReviewNumstat(stagedStdout),
1977
+ ...parseReviewNumstat(unstagedStdout),
1978
+ ],
1979
);
1980
}
1981
return Effect.fail(
@@ -2017,7 +1983,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1983
...gitCommandContext({
1984
operation: "GitVcsDriver.statusDetails.numstat",
1985
cwd,
2020
- args: ["diff-index", "-M", "--numstat", "HEAD", "--"],
1986
+ args: ["diff-index", "-M", "--numstat", "-z", "HEAD", "--"],
1987
}),
1988
detail: "git diff-index HEAD --numstat failed.",
1989
exitCode: result.exitCode,
@@ -2046,7 +2012,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2012
let hasWorkingTreeChanges = false;
2013
const changedFilesWithoutNumstat = new Set<string>();
2014
2049
- for (const line of statusStdout.split(/\r?\n/g)) {
2015
+ const statusRecords = statusStdout.split("\0");
2016
+ for (let index = 0; index < statusRecords.length; index++) {
2017
+ const line = statusRecords[index]!;
2018
if (line.startsWith("# branch.head ")) {
2019
const value = line.slice("# branch.head ".length).trim();
2020
refName = value.startsWith("(") ? null : value;
@@ -2064,10 +2032,16 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2032
behindCount = parsed.behind;
2033
continue;
2034
}
2067
- if (line.trim().length > 0 && !line.startsWith("#")) {
2035
+ if (line.length > 0 && !line.startsWith("#")) {
2036
hasWorkingTreeChanges = true;
2037
const pathValue = parsePorcelainPath(line);
2038
if (pathValue) changedFilesWithoutNumstat.add(pathValue);
2039
+ // A rename record is followed by its original path as a separate record. Listing it
2040
+ // keeps the deletion selectable when committing only some files.
2041
+ if (line.startsWith("2 ")) {
2042
+ const originalPath = statusRecords[++index];
2043
+ if (originalPath) changedFilesWithoutNumstat.add(originalPath);
2044
+ }
2045
}
2046
}
2047
@@ -2092,10 +2066,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2066
: yield* computeAheadCountAgainstBase(cwd, refName).pipe(Effect.orElseSucceed(() => 0));
2067
}
2068
2095
- const numstatEntries = parseNumstatEntries(numstatStdout);
2069
const fileStatMap = new Map<string, { insertions: number; deletions: number }>();
2070
for (const entry of numstatEntries) {
2098
- fileStatMap.set(entry.path, { insertions: entry.insertions, deletions: entry.deletions });
2071
+ const stat = fileStatMap.get(entry.path) ?? { insertions: 0, deletions: 0 };
2072
+ stat.insertions += entry.additions;
2073
+ stat.deletions += entry.deletions;
2074
+ fileStatMap.set(entry.path, stat);
2075
}
2076
2077
let insertions = 0;
@@ -2128,6 +2104,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2104
upstreamRef,
2105
hasWorkingTreeChanges,
2106
workingTree: {
2107
+ ...(repositoryPaths?.worktreeRoot ? { rootPath: repositoryPaths.worktreeRoot } : {}),
2108
files,
2109
insertions,
2110
deletions,
@@ -2221,7 +2198,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2198
yield* runGit(
2199
"GitVcsDriver.commit.addSelected",
2200
cwd,
2224
- [...config, "--literal-pathspecs", "add", "-A", "--", ...filePaths],
2201
+ // Status paths are repository-relative, while cwd can be a subdirectory.
2202
+ [...config, "add", "-A", "--", ...filePaths.map((file) => `:(top,literal)${file}`)],
2203
env ? { env } : {},
2204
);
2205
} else {
apps/web/src/components/GitActionsControl.browser.test.tsx
+83
-16
@@ -29,6 +29,9 @@ const state = vi.hoisted(() => ({
29
metadataRequests: [] as { environmentId: string; branch: string }[],
30
toasts: [] as Toast[],
31
afterGitAction: undefined as (() => void) | undefined,
32
+ workingTreeRoot: undefined as string | undefined,
33
+ files: [{ path: "file.ts", insertions: 1, deletions: 0 }],
34
+ editorOpens: [] as { environmentId: string; input: { cwd: string; editor: string } }[],
35
}));
36
37
vi.mock(import("~/state/session"), async (original) => {
@@ -61,7 +64,8 @@ vi.mock(import("~/state/query"), async (original) => ({
64
hasPrimaryRemote: true,
65
hasWorkingTreeChanges: true,
66
workingTree: {
64
- files: [{ path: "file.ts", insertions: 1, deletions: 0 }],
67
+ ...(state.workingTreeRoot === undefined ? {} : { rootPath: state.workingTreeRoot }),
68
+ files: state.files,
69
insertions: 1,
70
deletions: 0,
71
},
@@ -73,21 +77,45 @@ vi.mock(import("~/state/query"), async (original) => ({
77
error: null,
78
})) as never,
79
}));
76
-vi.mock(import("~/state/use-atom-command"), async (original) => ({
77
- ...(await original()),
78
- // The only command whose result matters here is the thread's branch metadata update.
79
- useAtomCommand: ((_command: unknown, options: unknown) =>
80
- options === "thread branch metadata update"
81
- ? async ({ environmentId, input }: { environmentId: string; input: { branch: string } }) => {
82
- state.metadataRequests.push({ environmentId, branch: input.branch });
83
- if (!state.scopes.has(AuthOrchestrationOperateScope))
84
- return AsyncResult.failure(Cause.fail(new Error("Task denied")));
85
- if (state.shell) state.shell = { branch: input.branch };
86
- if (state.detail) state.detail = { branch: input.branch };
87
- return AsyncResult.success(undefined);
88
- }
89
- : async () => AsyncResult.success(undefined)) as never,
90
-}));
80
+vi.mock(import("~/state/use-atom-command"), async (original) => {
81
+ const { shellEnvironment } = await import("~/state/shell");
82
+ return {
83
+ ...(await original()),
84
+ // Only the thread's branch metadata update and editor opens are observed here.
85
+ useAtomCommand: ((command: unknown, options: unknown) =>
86
+ options === "thread branch metadata update"
87
+ ? async ({
88
+ environmentId,
89
+ input,
90
+ }: {
91
+ environmentId: string;
92
+ input: { branch: string };
93
+ }) => {
94
+ state.metadataRequests.push({ environmentId, branch: input.branch });
95
+ if (!state.scopes.has(AuthOrchestrationOperateScope))
96
+ return AsyncResult.failure(Cause.fail(new Error("Task denied")));
97
+ if (state.shell) state.shell = { branch: input.branch };
98
+ if (state.detail) state.detail = { branch: input.branch };
99
+ return AsyncResult.success(undefined);
100
+ }
101
+ : command === shellEnvironment.openInEditor
102
+ ? async (request: (typeof state.editorOpens)[number]) => {
103
+ state.editorOpens.push(request);
104
+ return AsyncResult.success(undefined);
105
+ }
106
+ : async () => AsyncResult.success(undefined)) as never,
107
+ };
108
+});
109
+// The preferred-editor flow needs one editor the environment reports as installed.
110
+vi.mock(import("~/state/server"), async (original) => {
111
+ const actual = await original();
112
+ const { Atom } = await import("effect/reactivity");
113
+ const config = Atom.make(() => ({ availableEditors: ["cursor"] }));
114
+ return {
115
+ ...actual,
116
+ serverEnvironment: { ...actual.serverEnvironment, configValueAtom: (() => config) as never },
117
+ };
118
+});
119
vi.mock(import("~/lib/sourceControlActions"), async (original) => ({
120
...(await original()),
121
useSourceControlActionRunning: () => false,
@@ -180,6 +208,9 @@ beforeEach(() => {
208
state.metadataRequests = [];
209
state.toasts = [];
210
state.afterGitAction = undefined;
211
+ state.workingTreeRoot = undefined;
212
+ state.files = [{ path: "file.ts", insertions: 1, deletions: 0 }];
213
+ state.editorOpens = [];
214
useComposerDraftStore.setState({
215
getDraftSession: () => state.draft as never,
216
getDraftThreadByRef: () => state.draft as never,
@@ -312,6 +343,42 @@ describe("Git actions while thread details load", () => {
343
});
344
});
345
346
+describe("Changed-file editor targets", () => {
347
+ beforeEach(() => {
348
+ state.scopes.add(AuthOrchestrationOperateScope);
349
+ state.files = [
350
+ { path: "nested/new.txt", insertions: 0, deletions: 0 },
351
+ { path: "nested/tracked.txt", insertions: 1, deletions: 0 },
352
+ ];
353
+ });
354
+
355
+ it("resolves repository-relative paths against the status root, not the project cwd", async () => {
356
+ state.workingTreeRoot = "/repo";
357
+ await render("thread", "/repo/nested");
358
+ await openCommitDialog();
359
+
360
+ await userEvent.click(button("Open nested/new.txt in editor"));
361
+ await userEvent.click(button("Open nested/tracked.txt in editor"));
362
+
363
+ await vi.waitFor(() => expect(state.editorOpens).toHaveLength(2));
364
+ expect(state.editorOpens).toEqual([
365
+ { environmentId: "environment", input: { cwd: "/repo/nested/new.txt", editor: "cursor" } },
366
+ {
367
+ environmentId: "environment",
368
+ input: { cwd: "/repo/nested/tracked.txt", editor: "cursor" },
369
+ },
370
+ ]);
371
+ });
372
+
373
+ it("does not guess a file location when the server reports no root", async () => {
374
+ await render("thread", "/repo/nested");
375
+ await openCommitDialog();
376
+
377
+ await expect.element(button("Open nested/new.txt in editor")).toBeDisabled();
378
+ expect(state.editorOpens).toEqual([]);
379
+ });
380
+});
381
+
382
describe("Default branch prompt", () => {
383
beforeEach(() => {
384
state.isDefaultRef = true;
apps/web/src/components/GitActionsControl.tsx
+6
-3
@@ -1091,6 +1091,9 @@ export default function GitActionsControl({
1091
const changesTotals = gitStatusForActions?.branchChanges ?? gitStatusForActions?.workingTree;
1092
1093
const allFiles = gitStatusForActions?.workingTree.files ?? [];
1094
+ // Changed-file paths are repository-relative, so they must resolve against
1095
+ // the worktree root from the same status snapshot, not the project cwd.
1096
+ const workingTreeRoot = gitStatusForActions?.workingTree.rootPath ?? null;
1097
const selectedFiles = allFiles.filter((f) => !excludedFiles.has(f.path));
1098
const allSelected = excludedFiles.size === 0;
1099
const noneSelected = selectedFiles.length === 0;
@@ -1498,7 +1501,7 @@ export default function GitActionsControl({
1501
};
1502
1503
const openChangedFileInEditor = (filePath: string) => {
1501
- if (!gitCwd) {
1504
+ if (workingTreeRoot === null) {
1505
toastManager.add({
1506
type: "error",
1507
title: "Editor opening is unavailable.",
@@ -1506,7 +1509,7 @@ export default function GitActionsControl({
1509
});
1510
return;
1511
}
1509
- const target = resolvePathLinkTarget(filePath, gitCwd);
1512
+ const target = resolvePathLinkTarget(filePath, workingTreeRoot);
1513
void (async () => {
1514
const result = await openInPreferredEditor(target);
1515
if (result._tag === "Success" || isAtomCommandInterrupted(result)) {
@@ -1944,7 +1947,7 @@ export default function GitActionsControl({
1947
<button
1948
type="button"
1949
className="flex min-w-0 flex-1 items-center justify-between gap-3 text-left"
1947
- disabled={!canOperateThread}
1950
+ disabled={!canOperateThread || workingTreeRoot === null}
1951
aria-label={`Open ${file.path} in editor`}
1952
onClick={() => openChangedFileInEditor(file.path)}
1953
>
packages/contracts/src/git.ts
+3
@@ -218,6 +218,9 @@ const VcsStatusLocalShape = {
218
refName: Schema.NullOr(TrimmedNonEmptyStringSchema),
219
hasWorkingTreeChanges: Schema.Boolean,
220
workingTree: Schema.Struct({
221
+ // Absolute worktree root on the environment that every files[].path is
222
+ // relative to. Absent when the server could not resolve it.
223
+ rootPath: Schema.optional(GitFilePath),
224
files: Schema.Array(
225
Schema.Struct({
226
path: GitFilePath,