GeezerVison is showing github.com — fix(web): don't seed the worktree base from an unborn HEAD · pingdotgg/t3code@ca8280c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/BranchToolbar.logic.test.ts +51Lines changed: 51 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | resolveEffectiveEnvMode, | 9 | 9 | resolveBranchToolbarPrBranch, | 10 | 10 | resolveLocalCheckoutBranchMismatch, | | 11 | + resolveWorktreeBaseBranchCandidate, | 11 | 12 | sanitizeNewRefName, | 12 | 13 | shouldIncludeBranchPickerItem, | 13 | 14 | } from "./BranchToolbar.logic"; | @@ -254,3 +255,53 @@ describe("sanitizeNewRefName", () => { | 254 | 255 | expect(sanitizeNewRefName("foo--bar")).toBe("foo--bar"); | 255 | 256 | }); | 256 | 257 | }); | | 258 | + | | 259 | +describe("resolveWorktreeBaseBranchCandidate", () => { | | 260 | + const ref = (name: string, overrides: Partial<VcsRef> = {}): VcsRef => ({ | | 261 | + name, | | 262 | + current: false, | | 263 | + isDefault: false, | | 264 | + worktreePath: null, | | 265 | + ...overrides, | | 266 | + }); | | 267 | + | | 268 | + it("waits for the initial ref list", () => { | | 269 | + expect( | | 270 | + resolveWorktreeBaseBranchCandidate({ | | 271 | + isInitialBranchesLoadPending: true, | | 272 | + refs: [], | | 273 | + currentGitBranch: "staging", | | 274 | + }), | | 275 | + ).toBeNull(); | | 276 | + }); | | 277 | + | | 278 | + it("prefers the default branch", () => { | | 279 | + expect( | | 280 | + resolveWorktreeBaseBranchCandidate({ | | 281 | + isInitialBranchesLoadPending: false, | | 282 | + refs: [ref("feature", { current: true }), ref("staging", { isDefault: true })], | | 283 | + currentGitBranch: "feature", | | 284 | + }), | | 285 | + ).toBe("staging"); | | 286 | + }); | | 287 | + | | 288 | + it("falls back to the current branch when it is a listed ref", () => { | | 289 | + expect( | | 290 | + resolveWorktreeBaseBranchCandidate({ | | 291 | + isInitialBranchesLoadPending: false, | | 292 | + refs: [ref("develop", { current: true })], | | 293 | + currentGitBranch: "develop", | | 294 | + }), | | 295 | + ).toBe("develop"); | | 296 | + }); | | 297 | + | | 298 | + it("ignores an unborn HEAD while a clone is still running", () => { | | 299 | + expect( | | 300 | + resolveWorktreeBaseBranchCandidate({ | | 301 | + isInitialBranchesLoadPending: false, | | 302 | + refs: [], | | 303 | + currentGitBranch: "main", | | 304 | + }), | | 305 | + ).toBeNull(); | | 306 | + }); | | 307 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/BranchToolbar.logic.ts +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -200,6 +200,23 @@ export function resolveBranchToolbarValue(input: { | 200 | 200 | return currentGitBranch ?? activeThreadBranch; | 201 | 201 | } | 202 | 202 |
| | 203 | +// A repository whose HEAD is unborn (e.g. while a clone is still running) reports its | | 204 | +// init.defaultBranch as the current branch even though no such ref exists yet. | | 205 | +export function resolveWorktreeBaseBranchCandidate(input: { | | 206 | + isInitialBranchesLoadPending: boolean; | | 207 | + refs: ReadonlyArray<VcsRef>; | | 208 | + currentGitBranch: string | null; | | 209 | +}): string | null { | | 210 | + const { isInitialBranchesLoadPending, refs, currentGitBranch } = input; | | 211 | + if (isInitialBranchesLoadPending) return null; | | 212 | + const defaultBranchName = refs.find((refName) => refName.isDefault)?.name ?? null; | | 213 | + if (defaultBranchName) return defaultBranchName; | | 214 | + if (currentGitBranch && refs.some((refName) => refName.name === currentGitBranch)) { | | 215 | + return currentGitBranch; | | 216 | + } | | 217 | + return null; | | 218 | +} | | 219 | + | 203 | 220 | export function resolveBranchTriggerLabel(input: { | 204 | 221 | activeWorktreePath: string | null; | 205 | 222 | effectiveEnvMode: EnvMode; | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/BranchToolbarBranchSelector.tsx +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,6 +53,7 @@ import { | 53 | 53 | resolveBranchToolbarValue, | 54 | 54 | resolveDraftEnvModeAfterBranchChange, | 55 | 55 | resolveEffectiveEnvMode, | | 56 | + resolveWorktreeBaseBranchCandidate, | 56 | 57 | sanitizeNewRefName, | 57 | 58 | shouldIncludeBranchPickerItem, | 58 | 59 | } from "./BranchToolbar.logic"; | @@ -252,7 +253,6 @@ export function BranchToolbarBranchSelector({ | 252 | 253 | const createBranchItemValue = canCreateBranch | 253 | 254 | ? `__create_new_branch__:${trimmedBranchQuery}` | 254 | 255 | : null; | 255 | | - const defaultBranchName = refs.find((refName) => refName.isDefault)?.name ?? null; | 256 | 256 | const pickerCreateBranchItemValue = hasExactBranchMatch ? null : createBranchItemValue; | 257 | 257 | const branchPickerItems = [ | 258 | 258 | ...(checkoutPullRequestItemValue ? [checkoutPullRequestItemValue] : []), | @@ -478,9 +478,11 @@ export function BranchToolbarBranchSelector({ | 478 | 478 | }); | 479 | 479 | }; | 480 | 480 |
| 481 | | - const worktreeBaseBranchCandidate = isInitialBranchesLoadPending | 482 | | - ? null | 483 | | - : (defaultBranchName ?? currentGitBranch); | | 481 | + const worktreeBaseBranchCandidate = resolveWorktreeBaseBranchCandidate({ | | 482 | + isInitialBranchesLoadPending, | | 483 | + refs, | | 484 | + currentGitBranch, | | 485 | + }); | 484 | 486 |
| 485 | 487 | // The server sets started threads' branches; defaulting here would detach the agent from its worktree. | 486 | 488 | const threadStarted = serverSession !== null; | |
|