@devries-cameron20 / t3code Mirror · read-only / commits / fa2a2dc774
Fork 0

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 22, 13:15 UTC

fix(mobile): recognize this thread's main checkout (#23764)

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

Victor Vogel committed Oct 29, 2026 at 13:00 UTC fa2a2dc7749eded7352c04f72c7c48167e6f2b78
3 files changed +103 -2
apps/mobile/src/features/threads/git/GitBranchesSheet.occupancy.test.tsx new
+100
@@ -0,0 +1,100 @@
1 +import { act, type ReactNode } from "react";
2 +import { createRoot } from "react-dom/client";
3 +import { expect, it, vi } from "vite-plus/test";
4 +
5 +const checkout = vi.hoisted(() => ({
6 + projectRoot: "",
7 + worktreePath: null as string | null,
8 + branches: [] as Array<{ name: string; worktreePath: string | null }>,
9 +}));
10 +
11 +vi.mock("react-native", () => ({
12 + Platform: { OS: "android" },
13 + View: ({ children }: { children: ReactNode }) => <div>{children}</div>,
14 + ScrollView: ({ children }: { children: ReactNode }) => <div>{children}</div>,
15 + Pressable: ({ children, disabled }: { children: ReactNode; disabled: boolean }) => (
16 + <button disabled={disabled}>{children}</button>
17 + ),
18 + useWindowDimensions: () => ({ height: 800 }),
19 +}));
20 +vi.mock("@react-navigation/native", () => ({ useNavigation: () => ({}) }));
21 +vi.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ bottom: 0 }) }));
22 +vi.mock("../../../components/ui/AndroidScreenHeader", () => ({ AndroidSheetHeader: () => null }));
23 +vi.mock("../../../components/ui/SheetHeader", () => ({ SheetHeader: () => null }));
24 +vi.mock("../../../components/ui/ScreenContent", () => ({
25 + ScreenContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
26 +}));
27 +vi.mock("../../../native/StackHeader", () => ({ NativeStackScreenOptions: () => null }));
28 +vi.mock("../../../components/ui/AppText", () => ({
29 + AppText: ({ children }: { children: ReactNode }) => <span>{children}</span>,
30 + AppTextInput: () => null,
31 +}));
32 +vi.mock("./gitSheetComponents", () => ({ SheetActionButton: () => null }));
33 +vi.mock("../../../state/use-thread-selection", () => ({
34 + useThreadSelection: () => ({
35 + selectedThread: { environmentId: "environment-1", worktreePath: checkout.worktreePath },
36 + selectedThreadProject: { workspaceRoot: checkout.projectRoot },
37 + }),
38 +}));
39 +vi.mock("../../../state/use-thread-detail", () => ({
40 + useSelectedThreadWorktreePath: () => checkout.worktreePath,
41 +}));
42 +vi.mock("../../../state/use-selected-thread-git-state", () => ({
43 + useSelectedThreadGitState: () => ({
44 + selectedThreadBranches: checkout.branches,
45 + selectedThreadBranchesLoading: false,
46 + gitOperationLabel: null,
47 + }),
48 +}));
49 +vi.mock("../../../state/use-selected-thread-git-actions", () => ({
50 + useSelectedThreadGitActions: () => ({ canChangeThreadBranch: true }),
51 +}));
52 +vi.mock("../../../state/query", () => ({ useEnvironmentQuery: () => ({ data: null }) }));
53 +vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { status: () => null } }));
54 +
55 +import { GitBranchesSheet } from "./GitBranchesSheet";
56 +
57 +it("recognizes both the main checkout and a linked worktree as this thread's checkout", () => {
58 + const directory = "/repo";
59 + const linked = "/repo-linked";
60 + checkout.projectRoot = directory;
61 + checkout.branches = [
62 + { name: "feature/available", worktreePath: null },
63 + { name: "feature/linked", worktreePath: linked },
64 + { name: "main", worktreePath: directory },
65 + ];
66 + (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
67 + const container = document.createElement("div");
68 + const root = createRoot(container);
69 + const rows = () => {
70 + act(() => {
71 + root.render(
72 + <GitBranchesSheet
73 + route={{ params: { environmentId: "environment-1", threadId: "thread-1" } }}
74 + />,
75 + );
76 + });
77 + return [...container.querySelectorAll("button")].map((button) => ({
78 + name: button.querySelectorAll("span")[0]?.textContent,
79 + subtitle: button.querySelectorAll("span")[1]?.textContent,
80 + disabled: button.disabled,
81 + }));
82 + };
83 + try {
84 + checkout.worktreePath = null;
85 + expect(rows()).toEqual([
86 + { name: "feature/available", subtitle: "Local branch", disabled: false },
87 + { name: "feature/linked", subtitle: "Checked out in another worktree", disabled: true },
88 + { name: "main", subtitle: "Checked out in this thread", disabled: false },
89 + ]);
90 +
91 + checkout.worktreePath = linked;
92 + expect(rows()).toEqual([
93 + { name: "feature/available", subtitle: "Local branch", disabled: false },
94 + { name: "feature/linked", subtitle: "Checked out in this thread", disabled: false },
95 + { name: "main", subtitle: "Checked out in another worktree", disabled: true },
96 + ]);
97 + } finally {
98 + act(() => root.unmount());
99 + }
100 +});
apps/mobile/src/features/threads/git/GitBranchesSheet.tsx
+2 -2
@@ -28,7 +28,7 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
28 const insets = useSafeAreaInsets();
29 const { height: windowHeight } = useWindowDimensions();
30 const { selectedThread } = useThreadSelection();
31 - const { selectedThreadCwd, selectedThreadWorktreePath } = useSelectedThreadWorktree();
31 + const { selectedThreadCwd } = useSelectedThreadWorktree();
32 const gitState = useSelectedThreadGitState();
33 const gitActions = useSelectedThreadGitActions();
34 const { canChangeThreadBranch } = gitActions;
@@ -43,7 +43,7 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
43 );
44
45 const currentBranchLabel = gitStatus.data?.refName ?? selectedThread?.branch ?? "Detached HEAD";
46 - const currentWorktreePath = selectedThreadWorktreePath;
46 + const currentWorktreePath = selectedThreadCwd;
47 const availableBranches = gitState.selectedThreadBranches;
48 const branchesLoading = gitState.selectedThreadBranchesLoading;
49 const busy = gitState.gitOperationLabel !== null;
apps/mobile/vite.config.ts
+1
@@ -4,6 +4,7 @@ import { defineConfig, normalizePath } from "vite-plus";
4 import "vite-plus/test/config";
5
6 const reactTests = [
7 + "src/features/threads/git/GitBranchesSheet.occupancy.test.tsx",
8 "src/features/files/useFileTreeEntries.test.tsx",
9 "src/features/projects/AddProjectScreen.test.ts",
10 "src/lib/useMediaVideoPlayback.test.tsx",