Skip to content

Commit c7d6e8f

Browse files
committed
fix(projects): wait for settings before choosing worktree base
1 parent 61bf378 commit c7d6e8f

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,9 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
882882
// The default may only exist as origin/<default> (isRemote), which
883883
// availableBranches filters out — search the unfiltered refs for it.
884884
const preferredBranch = resolveDefaultWorktreeBaseRef({
885-
configuredRef: projectSettings.settings.defaultWorktreeBaseRef,
885+
configuredRef: selectedEnvironmentServerConfig
886+
? projectSettings.settings.defaultWorktreeBaseRef
887+
: undefined,
886888
refs: allBranchRefs,
887889
currentBranch: availableBranches.find((branch) => branch.current)?.name ?? null,
888890
});
@@ -903,6 +905,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
903905
draftStartFromOrigin,
904906
projectSettings.settings.defaultWorktreeBaseRef,
905907
selectedBranchName,
908+
selectedEnvironmentServerConfig,
906909
selectedProjectDraftKey,
907910
workspaceMode,
908911
]);

‎apps/web/src/components/BranchToolbarBranchSelector.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { resolveDefaultWorktreeBaseRef } from "@t3tools/shared/git";
22
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
3-
import { useEnvironmentSettings } from "../hooks/useSettings";
3+
import { useAtomValue } from "@effect/atom-react";
44
import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";
55
import { resolveThreadCurrentPullRequestLink } from "@t3tools/shared/threadPullRequests";
66
import { useRightPanelStore } from "../rightPanelStore";
@@ -37,6 +37,7 @@ import { shouldLoadNextBranchPageAfterScroll } from "../state/paginatedBranches"
3737
import { usePaginatedBranches } from "../state/queries";
3838
import { useProject, useThreadShell } from "../state/entities";
3939
import { useEnvironmentQuery } from "../state/query";
40+
import { serverEnvironment } from "../state/server";
4041
import { threadEnvironment } from "../state/threads";
4142
import { useAtomCommand } from "../state/use-atom-command";
4243
import { vcsEnvironment } from "../state/vcs";
@@ -153,11 +154,13 @@ export function BranchToolbarBranchSelector({
153154
? scopeProjectRef(draftThread.environmentId, draftThread.projectId)
154155
: null;
155156
const activeProject = useProject(activeProjectRef);
156-
const configuredBaseRef = useEnvironmentSettings(
157-
environmentId,
158-
(settings) =>
159-
resolveProjectSettings(settings, activeProject?.id ?? null).settings.defaultWorktreeBaseRef,
160-
);
157+
const serverSettings = useAtomValue(serverEnvironment.settingsValueAtom(environmentId));
158+
const configuredBaseRef = serverSettings
159+
? resolveProjectSettings(
160+
serverSettings,
161+
serverThread?.projectId ?? draftThread?.projectId ?? null,
162+
).settings.defaultWorktreeBaseRef
163+
: undefined;
161164

162165
const activeThreadId = serverThread?.id ?? (draftThread ? threadId : undefined);
163166
const activeThreadBranch =

‎packages/shared/src/git.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ describe("applyGitStatusStreamEvent", () => {
279279
describe("resolveDefaultWorktreeBaseRef", () => {
280280
const refs = [{ name: "origin/main", isDefault: true }];
281281

282+
it("waits for saved settings when refs load first", () => {
283+
expect(
284+
resolveDefaultWorktreeBaseRef({
285+
configuredRef: undefined,
286+
refs,
287+
currentBranch: "main",
288+
}),
289+
).toBeNull();
290+
expect(
291+
resolveDefaultWorktreeBaseRef({ configuredRef: "dev", refs, currentBranch: "main" }),
292+
).toBe("dev");
293+
});
294+
282295
it.each(["dev", "upstream/dev", "refs/tags/v1", "a1b2c3d", "missing-branch"])(
283296
"honors %s even when it is absent from the loaded page of refs",
284297
(configuredRef) => {

‎packages/shared/src/git.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ import * as Arr from "effect/Array";
1010
import * as Result from "effect/Result";
1111
import { detectSourceControlProviderFromRemoteUrl } from "./sourceControl.ts";
1212

13-
/** Keep configured refs verbatim: tags, commits and paginated-out branches need not be listed. */
13+
/**
14+
* Wait for settings (undefined); null opts into the repository default.
15+
* Keep configured refs verbatim: tags, commits and paginated-out branches need not be listed.
16+
*/
1417
export function resolveDefaultWorktreeBaseRef(input: {
15-
readonly configuredRef: string | null;
18+
readonly configuredRef: string | null | undefined;
1619
readonly refs: readonly Pick<VcsRef, "name" | "isDefault">[];
1720
readonly currentBranch: string | null;
1821
}): string | null {
22+
if (input.configuredRef === undefined) return null;
1923
return (
2024
input.configuredRef ?? input.refs.find((ref) => ref.isDefault)?.name ?? input.currentBranch
2125
);

0 commit comments

Comments
 (0)