Repository navigation
fix(mobile): use loaded branch for untouched worktree base #23241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
only21mil
wants to merge
6
commits into
pingdotgg:main
Choose a base branch
from
only21mil:r13/a083-seed-the-worktree-base-after-branch-stat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−4
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
72d0305
test(mobile): reproduce late worktree base status
only21mil a42bfe6
fix(mobile): follow loaded status for untouched worktree base
only21mil e7aae15
test(mobile): format worktree status regression coverage
only21mil 02dbeb0
test(mobile): isolate native sheet header chrome
only21mil 471b528
chore: merge main into mobile worktree base fix
maria-rcks 6e7d9f7
Merge remote-tracking branch 'github/main' into takeover-23241
maria-rcks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
apps/mobile/src/features/threads/git/GitBranchesSheet.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { act, type ReactNode } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| type InputProps = { | ||
| accessibilityLabel: string; | ||
| value: string; | ||
| onChangeText: (value: string) => void; | ||
| }; | ||
| type ActionProps = { label: string; disabled: boolean; onPress: () => void }; | ||
| const state = vi.hoisted(() => ({ | ||
| refName: null as string | null, | ||
| branch: null as string | null, | ||
| inputs: new Map<string, InputProps>(), | ||
| actions: new Map<string, ActionProps>(), | ||
| worktrees: [] as Array<{ baseBranch: string; newBranch: string }>, | ||
| })); | ||
|
|
||
| vi.mock("@react-navigation/native", () => ({ useNavigation: () => ({ goBack() {} }) })); | ||
| vi.mock("react-native", () => ({ | ||
| Platform: { OS: "android" }, | ||
| useWindowDimensions: () => ({ height: 800 }), | ||
| View: ({ children }: { children: ReactNode }) => children, | ||
| ScrollView: ({ children }: { children: ReactNode }) => children, | ||
| Pressable: () => null, | ||
| })); | ||
| vi.mock("react-native-safe-area-context", () => ({ | ||
| useSafeAreaInsets: () => ({ bottom: 0 }), | ||
| })); | ||
| vi.mock("../../../components/ui/AndroidScreenHeader", () => ({ AndroidSheetHeader: () => null })); | ||
| vi.mock("../../../components/ui/SheetHeader", () => ({ SheetHeader: () => null })); | ||
| vi.mock("../../../components/ui/ScreenContent", () => ({ | ||
| ScreenContent: ({ children }: { children: ReactNode }) => children, | ||
| })); | ||
| vi.mock("../../../native/StackHeader", () => ({ NativeStackScreenOptions: () => null })); | ||
| vi.mock("../../../components/ui/AppText", () => ({ | ||
| AppText: ({ children }: { children: ReactNode }) => children, | ||
| AppTextInput: (props: InputProps) => { | ||
| state.inputs.set(props.accessibilityLabel, props); | ||
| return null; | ||
| }, | ||
| })); | ||
| vi.mock("../../../state/query", () => ({ | ||
| useEnvironmentQuery: () => ({ | ||
| data: state.refName === null ? undefined : { refName: state.refName }, | ||
| }), | ||
| })); | ||
| vi.mock("../../../state/use-thread-selection", () => ({ | ||
| useThreadSelection: () => ({ | ||
| selectedThread: { environmentId: "environment", branch: state.branch }, | ||
| }), | ||
| })); | ||
| vi.mock("../../../state/use-selected-thread-worktree", () => ({ | ||
| useSelectedThreadWorktree: () => ({ | ||
| selectedThreadCwd: "/repo", | ||
| selectedThreadWorktreePath: null, | ||
| }), | ||
| })); | ||
| vi.mock("../../../state/use-selected-thread-git-state", () => ({ | ||
| useSelectedThreadGitState: () => ({ | ||
| selectedThreadBranches: [], | ||
| selectedThreadBranchesLoading: false, | ||
| gitOperationLabel: null, | ||
| }), | ||
| })); | ||
| vi.mock("../../../state/use-selected-thread-git-actions", () => ({ | ||
| useSelectedThreadGitActions: () => ({ | ||
| canChangeThreadBranch: true, | ||
| onCreateSelectedThreadWorktree: async (input: { baseBranch: string; newBranch: string }) => { | ||
| state.worktrees.push(input); | ||
| return null; | ||
| }, | ||
| }), | ||
| })); | ||
| vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { status: () => null } })); | ||
| vi.mock("./gitSheetComponents", () => ({ | ||
| SheetActionButton: (props: ActionProps) => { | ||
| state.actions.set(props.label, props); | ||
| return null; | ||
| }, | ||
| })); | ||
|
|
||
| import { GitBranchesSheet } from "./GitBranchesSheet"; | ||
|
|
||
| function setup(branch: string | null = null) { | ||
| (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; | ||
| state.refName = null; | ||
| state.branch = branch; | ||
| state.inputs.clear(); | ||
| state.actions.clear(); | ||
| state.worktrees = []; | ||
| const root = createRoot(document.createElement("div")); | ||
| const render = () => | ||
| act(() => { | ||
| root.render( | ||
| <GitBranchesSheet | ||
| route={{ params: { environmentId: "environment", threadId: "thread" } }} | ||
| />, | ||
| ); | ||
| }); | ||
| render(); | ||
| return { | ||
| render, | ||
| edit(label: string, value: string) { | ||
| act(() => state.inputs.get(label)!.onChangeText(value)); | ||
| }, | ||
| create() { | ||
| act(() => state.actions.get("Create worktree")!.onPress()); | ||
| }, | ||
| [Symbol.dispose]() { | ||
| act(() => root.unmount()); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| it.each([null, "stale-branch"])( | ||
| "uses the loaded checkout branch when thread metadata is %s", | ||
| (branch) => { | ||
| using screen = setup(branch); | ||
| screen.edit("Worktree branch name", "feature/new-worktree"); | ||
| state.refName = "release/stable"; | ||
| screen.render(); | ||
| screen.create(); | ||
| expect(state.worktrees).toEqual([ | ||
| { baseBranch: "release/stable", newBranch: "feature/new-worktree" }, | ||
| ]); | ||
| }, | ||
| ); | ||
|
|
||
| it.each(["custom-base", ""])("preserves an edited base %j when status arrives", (base) => { | ||
| using screen = setup(); | ||
| screen.edit("Worktree base branch", base); | ||
| screen.edit("Worktree branch name", "feature/new-worktree"); | ||
| state.refName = "release/stable"; | ||
| screen.render(); | ||
| expect(state.inputs.get("Worktree base branch")!.value).toBe(base); | ||
| expect(state.actions.get("Create worktree")!.disabled).toBe(base === ""); | ||
| screen.create(); | ||
| expect(state.worktrees).toEqual( | ||
| base === "" ? [] : [{ baseBranch: base, newBranch: "feature/new-worktree" }], | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔎 Supported by static analysis
Script executed:
Repository: pingdotgg/t3code
Length of output: 41770
Don't let stale thread metadata set the base for a detached checkout.
A detached checkout loads with
refName: null. The sheet's??chain then falls through toselectedThread?.branch. When that thread branch is set, the untouched base field shows the stale branch. The"Detached HEAD" ? "main"default applies only when the thread branch is also empty. Distinguish a loaded status with a nullrefNamefrom a status that has not loaded yet. Only the second case should fall back to thread metadata.