GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): don't seed the worktree base from an unborn HEAD · pingdotgg/t3code@ca8280c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components
    • BranchToolbar.logic.test.ts
    • BranchToolbar.logic.ts
    • BranchToolbarBranchSelector.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/BranchToolbar.logic.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/BranchToolbar.logic.test.ts
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
resolveEffectiveEnvMode,
99
resolveBranchToolbarPrBranch,
1010
resolveLocalCheckoutBranchMismatch,
11+
resolveWorktreeBaseBranchCandidate,
1112
sanitizeNewRefName,
1213
shouldIncludeBranchPickerItem,
1314
} from "./BranchToolbar.logic";
@@ -254,3 +255,53 @@ describe("sanitizeNewRefName", () => {
254255
expect(sanitizeNewRefName("foo--bar")).toBe("foo--bar");
255256
});
256257
});
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

‎apps/web/src/components/BranchToolbar.logic.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/BranchToolbar.logic.ts
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ export function resolveBranchToolbarValue(input: {
200200
return currentGitBranch ?? activeThreadBranch;
201201
}
202202

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+
203220
export function resolveBranchTriggerLabel(input: {
204221
activeWorktreePath: string | null;
205222
effectiveEnvMode: EnvMode;
Collapse file

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

Copy file name to clipboardExpand all lines: apps/web/src/components/BranchToolbarBranchSelector.tsx
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
resolveBranchToolbarValue,
5454
resolveDraftEnvModeAfterBranchChange,
5555
resolveEffectiveEnvMode,
56+
resolveWorktreeBaseBranchCandidate,
5657
sanitizeNewRefName,
5758
shouldIncludeBranchPickerItem,
5859
} from "./BranchToolbar.logic";
@@ -252,7 +253,6 @@ export function BranchToolbarBranchSelector({
252253
const createBranchItemValue = canCreateBranch
253254
? `__create_new_branch__:${trimmedBranchQuery}`
254255
: null;
255-
const defaultBranchName = refs.find((refName) => refName.isDefault)?.name ?? null;
256256
const pickerCreateBranchItemValue = hasExactBranchMatch ? null : createBranchItemValue;
257257
const branchPickerItems = [
258258
...(checkoutPullRequestItemValue ? [checkoutPullRequestItemValue] : []),
@@ -478,9 +478,11 @@ export function BranchToolbarBranchSelector({
478478
});
479479
};
480480

481-
const worktreeBaseBranchCandidate = isInitialBranchesLoadPending
482-
? null
483-
: (defaultBranchName ?? currentGitBranch);
481+
const worktreeBaseBranchCandidate = resolveWorktreeBaseBranchCandidate({
482+
isInitialBranchesLoadPending,
483+
refs,
484+
currentGitBranch,
485+
});
484486

485487
// The server sets started threads' branches; defaulting here would detach the agent from its worktree.
486488
const threadStarted = serverSession !== null;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.