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, 07:00 UTC
fix(mobile): use loaded branch for untouched worktree base (#23241)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Nov 1, 2026 at 15:58 UTC
cd04747a34f0a803e5117fc13856045f953b6682
3 files changed
+148
-4
apps/mobile/src/features/threads/git/GitBranchesSheet.test.tsx
new
+142
@@ -0,0 +1,142 @@
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
+type InputProps = {
6
+ accessibilityLabel: string;
7
+ value: string;
8
+ onChangeText: (value: string) => void;
9
+};
10
+type ActionProps = { label: string; disabled: boolean; onPress: () => void };
11
+const state = vi.hoisted(() => ({
12
+ refName: null as string | null,
13
+ branch: null as string | null,
14
+ inputs: new Map<string, InputProps>(),
15
+ actions: new Map<string, ActionProps>(),
16
+ worktrees: [] as Array<{ baseBranch: string; newBranch: string }>,
17
+}));
18
+
19
+vi.mock("@react-navigation/native", () => ({ useNavigation: () => ({ goBack() {} }) }));
20
+vi.mock("react-native", () => ({
21
+ Platform: { OS: "android" },
22
+ useWindowDimensions: () => ({ height: 800 }),
23
+ View: ({ children }: { children: ReactNode }) => children,
24
+ ScrollView: ({ children }: { children: ReactNode }) => children,
25
+ Pressable: () => null,
26
+}));
27
+vi.mock("react-native-safe-area-context", () => ({
28
+ useSafeAreaInsets: () => ({ bottom: 0 }),
29
+}));
30
+vi.mock("../../../components/ui/AndroidScreenHeader", () => ({ AndroidSheetHeader: () => null }));
31
+vi.mock("../../../components/ui/SheetHeader", () => ({ SheetHeader: () => null }));
32
+vi.mock("../../../components/ui/ScreenContent", () => ({
33
+ ScreenContent: ({ children }: { children: ReactNode }) => children,
34
+}));
35
+vi.mock("../../../native/StackHeader", () => ({ NativeStackScreenOptions: () => null }));
36
+vi.mock("../../../components/ui/AppText", () => ({
37
+ AppText: ({ children }: { children: ReactNode }) => children,
38
+ AppTextInput: (props: InputProps) => {
39
+ state.inputs.set(props.accessibilityLabel, props);
40
+ return null;
41
+ },
42
+}));
43
+vi.mock("../../../state/query", () => ({
44
+ useEnvironmentQuery: () => ({
45
+ data: state.refName === null ? undefined : { refName: state.refName },
46
+ }),
47
+}));
48
+vi.mock("../../../state/use-thread-selection", () => ({
49
+ useThreadSelection: () => ({
50
+ selectedThread: { environmentId: "environment", branch: state.branch },
51
+ }),
52
+}));
53
+vi.mock("../../../state/use-selected-thread-worktree", () => ({
54
+ useSelectedThreadWorktree: () => ({
55
+ selectedThreadCwd: "/repo",
56
+ selectedThreadWorktreePath: null,
57
+ }),
58
+}));
59
+vi.mock("../../../state/use-selected-thread-git-state", () => ({
60
+ useSelectedThreadGitState: () => ({
61
+ selectedThreadBranches: [],
62
+ selectedThreadBranchesLoading: false,
63
+ gitOperationLabel: null,
64
+ }),
65
+}));
66
+vi.mock("../../../state/use-selected-thread-git-actions", () => ({
67
+ useSelectedThreadGitActions: () => ({
68
+ canChangeThreadBranch: true,
69
+ onCreateSelectedThreadWorktree: async (input: { baseBranch: string; newBranch: string }) => {
70
+ state.worktrees.push(input);
71
+ return null;
72
+ },
73
+ }),
74
+}));
75
+vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { status: () => null } }));
76
+vi.mock("./gitSheetComponents", () => ({
77
+ SheetActionButton: (props: ActionProps) => {
78
+ state.actions.set(props.label, props);
79
+ return null;
80
+ },
81
+}));
82
+
83
+import { GitBranchesSheet } from "./GitBranchesSheet";
84
+
85
+function setup(branch: string | null = null) {
86
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
87
+ state.refName = null;
88
+ state.branch = branch;
89
+ state.inputs.clear();
90
+ state.actions.clear();
91
+ state.worktrees = [];
92
+ const root = createRoot(document.createElement("div"));
93
+ const render = () =>
94
+ act(() => {
95
+ root.render(
96
+ <GitBranchesSheet
97
+ route={{ params: { environmentId: "environment", threadId: "thread" } }}
98
+ />,
99
+ );
100
+ });
101
+ render();
102
+ return {
103
+ render,
104
+ edit(label: string, value: string) {
105
+ act(() => state.inputs.get(label)!.onChangeText(value));
106
+ },
107
+ create() {
108
+ act(() => state.actions.get("Create worktree")!.onPress());
109
+ },
110
+ [Symbol.dispose]() {
111
+ act(() => root.unmount());
112
+ },
113
+ };
114
+}
115
+
116
+it.each([null, "stale-branch"])(
117
+ "uses the loaded checkout branch when thread metadata is %s",
118
+ (branch) => {
119
+ using screen = setup(branch);
120
+ screen.edit("Worktree branch name", "feature/new-worktree");
121
+ state.refName = "release/stable";
122
+ screen.render();
123
+ screen.create();
124
+ expect(state.worktrees).toEqual([
125
+ { baseBranch: "release/stable", newBranch: "feature/new-worktree" },
126
+ ]);
127
+ },
128
+);
129
+
130
+it.each(["custom-base", ""])("preserves an edited base %j when status arrives", (base) => {
131
+ using screen = setup();
132
+ screen.edit("Worktree base branch", base);
133
+ screen.edit("Worktree branch name", "feature/new-worktree");
134
+ state.refName = "release/stable";
135
+ screen.render();
136
+ expect(state.inputs.get("Worktree base branch")!.value).toBe(base);
137
+ expect(state.actions.get("Create worktree")!.disabled).toBe(base === "");
138
+ screen.create();
139
+ expect(state.worktrees).toEqual(
140
+ base === "" ? [] : [{ baseBranch: base, newBranch: "feature/new-worktree" }],
141
+ );
142
+});
apps/mobile/src/features/threads/git/GitBranchesSheet.tsx
+5
-4
@@ -49,9 +49,10 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
49
const busy = gitState.gitOperationLabel !== null;
50
51
const [newBranchName, setNewBranchName] = useState("");
52
- const [worktreeBaseBranch, setWorktreeBaseBranch] = useState(
53
- currentBranchLabel === "Detached HEAD" ? "main" : currentBranchLabel,
54
- );
52
+ const [worktreeBaseBranchOverride, setWorktreeBaseBranchOverride] = useState<string | null>(null);
53
+ const worktreeBaseBranch =
54
+ worktreeBaseBranchOverride ??
55
+ (currentBranchLabel === "Detached HEAD" ? "main" : currentBranchLabel);
56
const [worktreeBranchName, setWorktreeBranchName] = useState("");
57
58
const disabledExistingBranchNames: Array<string> = [];
@@ -141,7 +142,7 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
142
) : null}
143
<TextInput
144
value={worktreeBaseBranch}
144
- onChangeText={setWorktreeBaseBranch}
145
+ onChangeText={setWorktreeBaseBranchOverride}
146
placeholder="main"
147
accessibilityLabel="Worktree base branch"
148
className="android:rounded-xl android:bg-sheet-solid ios:rounded-[18px]"
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.test.tsx",
8
"src/features/threads/new-task-flow-provider.test.tsx",
9
"src/features/workspace/workspace-tabs-state.test.ts",
10
"src/state/use-thread-pr.demand.test.tsx",