@devries-cameron20 / t3code-1 / commits / 78d0668a3d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): mark the thread worktree's branch as current (#23436)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 30, 2026 at 16:45 UTC 78d0668a3d585a36f2cf122028a63baea5714c7f
3 files changed +109 -2
apps/mobile/src/state/use-selected-thread-git-state.test.tsx new
+106
@@ -0,0 +1,106 @@
1 +import * as NodeChildProcess from "node:child_process";
2 +import * as NodeFS from "node:fs";
3 +import * as NodeOS from "node:os";
4 +import * as NodePath from "node:path";
5 +import { act, useLayoutEffect } from "react";
6 +import { createRoot } from "react-dom/client";
7 +import { expect, it, vi } from "vite-plus/test";
8 +
9 +const harness = vi.hoisted(() => ({
10 + root: "",
11 + cwd: "",
12 +}));
13 +
14 +vi.mock("./use-thread-selection", () => ({
15 + useThreadSelection: () => ({
16 + selectedThread: { environmentId: "environment-1" },
17 + selectedThreadProject: { workspaceRoot: harness.root },
18 + }),
19 +}));
20 +vi.mock("./use-selected-thread-worktree", () => ({
21 + useSelectedThreadWorktree: () => ({ selectedThreadCwd: harness.cwd }),
22 +}));
23 +vi.mock("./use-vcs-action-state", () => ({
24 + useVcsActionState: () => ({ currentLabel: null }),
25 +}));
26 +vi.mock("./sourceControl", () => ({
27 + sourceControlEnvironment: { discovery: () => null },
28 +}));
29 +vi.mock("./query", () => ({ useEnvironmentQuery: () => ({ data: null }) }));
30 +vi.mock("./queries", () => ({
31 + useBranches: ({ cwd }: { cwd: string }) => ({
32 + data: {
33 + refs: NodeChildProcess.execFileSync(
34 + "git",
35 + ["for-each-ref", "--format=%(refname:short) %(HEAD)", "refs/heads"],
36 + {
37 + cwd,
38 + encoding: "utf8",
39 + },
40 + )
41 + .trim()
42 + .split("\n")
43 + .map((line) => ({
44 + name: line.split(" ")[0],
45 + current: line.endsWith("*"),
46 + isRemote: false,
47 + })),
48 + },
49 + isPending: false,
50 + }),
51 +}));
52 +
53 +import { useSelectedThreadGitState } from "./use-selected-thread-git-state";
54 +
55 +it("marks the selected checkout's branch current when switching threads in one project", () => {
56 + const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "mobile-branches-"));
57 + const git = (...args: string[]) =>
58 + NodeChildProcess.execFileSync("git", ["-c", "commit.gpgsign=false", ...args], {
59 + cwd: directory,
60 + encoding: "utf8",
61 + stdio: "pipe",
62 + });
63 + const root = createRoot(document.createElement("div"));
64 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
65 + let currentBranches: string[] = [];
66 + function Consumer() {
67 + const { selectedThreadBranches } = useSelectedThreadGitState();
68 + useLayoutEffect(() => {
69 + currentBranches = selectedThreadBranches
70 + .filter((branch) => branch.current)
71 + .map((branch) => branch.name);
72 + }, [selectedThreadBranches]);
73 + return null;
74 + }
75 +
76 + try {
77 + git("init", "--initial-branch=main");
78 + git(
79 + "-c",
80 + "user.name=Test",
81 + "-c",
82 + "user.email=test@example.com",
83 + "commit",
84 + "--allow-empty",
85 + "-m",
86 + "initial",
87 + );
88 + const worktree = NodePath.join(directory, "linked");
89 + git("worktree", "add", "-b", "feature/mobile", worktree);
90 + harness.root = directory;
91 + harness.cwd = directory;
92 + act(() => root.render(<Consumer />));
93 + expect(currentBranches).toEqual(["main"]);
94 +
95 + harness.cwd = worktree;
96 + act(() => root.render(<Consumer />));
97 + expect(currentBranches).toEqual(["feature/mobile"]);
98 +
99 + harness.cwd = directory;
100 + act(() => root.render(<Consumer />));
101 + expect(currentBranches).toEqual(["main"]);
102 + } finally {
103 + act(() => root.unmount());
104 + NodeFS.rmSync(directory, { recursive: true, force: true });
105 + }
106 +});
apps/mobile/src/state/use-selected-thread-git-state.ts
+2 -2
@@ -10,7 +10,7 @@ import { useThreadSelection } from "./use-thread-selection";
10 import { useSelectedThreadWorktree } from "./use-selected-thread-worktree";
11
12 export function useSelectedThreadGitState() {
13 - const { selectedThread, selectedThreadProject } = useThreadSelection();
13 + const { selectedThread } = useThreadSelection();
14 const { selectedThreadCwd } = useSelectedThreadWorktree();
15
16 const selectedThreadGitTarget = {
@@ -29,7 +29,7 @@ export function useSelectedThreadGitState() {
29
30 const selectedThreadBranchTarget = {
31 environmentId: selectedThread?.environmentId ?? null,
32 - cwd: selectedThreadProject?.workspaceRoot ?? null,
32 + cwd: selectedThreadCwd,
33 query: null,
34 };
35 const selectedThreadBranchState = useBranches(selectedThreadBranchTarget);
apps/mobile/vite.config.ts
+1
@@ -28,6 +28,7 @@ const reactTests = [
28 "src/native/useRetryingImageSource.test.tsx",
29 "src/state/queries.debounce.test.tsx",
30 "src/state/use-selected-thread-git-actions.test.tsx",
31 + "src/state/use-selected-thread-git-state.test.tsx",
32 "src/features/terminal/useTerminalExitNavigation.test.tsx",
33 "src/features/threads/use-thread-list-now.test.tsx",
34 "src/features/home/home-list-options.test.tsx",