app/workspaces: Show the real base on a detached HEAD

With no current branch, the new-workspace base picker selected nothing
and its button fell back to a hardcoded "main", while the daemon
created the workspace from the repository's actual default branch
(`master` in some repositories). Default to the base the daemon
reports instead, and label an empty selection "Default branch" rather
than inventing a branch name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-26 10:49:57 +00:00
1 parent 55bafb24c5
commit 643ca85844
12 files changed
+35 -4

No files matched your search

+1
View File
@@ -1410,6 +1410,7 @@ export const ar: TranslationResources = {
},
},
newWorkspace: {
defaultBase: "الفرع الافتراضي",
title: "مساحة عمل جديدة",
create: "يخلق",
isolation: {
+1
View File
@@ -1421,6 +1421,7 @@ export const en = {
},
},
newWorkspace: {
defaultBase: "Default branch",
title: "New workspace",
create: "Create",
isolation: {
+1
View File
@@ -1447,6 +1447,7 @@ export const es: TranslationResources = {
},
},
newWorkspace: {
defaultBase: "Rama predeterminada",
title: "Nuevo espacio de trabajo",
create: "Crear",
isolation: {
+1
View File
@@ -1440,6 +1440,7 @@ export const fr: TranslationResources = {
},
},
newWorkspace: {
defaultBase: "Branche par défaut",
title: "Nouvel espace de travail",
create: "Créer",
isolation: {
+1
View File
@@ -1425,6 +1425,7 @@ export const ja: TranslationResources = {
},
},
newWorkspace: {
defaultBase: "デフォルトブランチ",
title: "新しいワークスペース",
create: "作成",
isolation: {
+1
View File
@@ -1417,6 +1417,7 @@ export const ko: TranslationResources = {
},
},
newWorkspace: {
defaultBase: "기본 브랜치",
title: "새 워크스페이스",
create: "생성",
isolation: {
+1
View File
@@ -1437,6 +1437,7 @@ export const ptBR: TranslationResources = {
},
},
newWorkspace: {
defaultBase: "Branch padrão",
title: "Novo workspace",
create: "Criar",
isolation: {
+1
View File
@@ -1430,6 +1430,7 @@ export const ru: TranslationResources = {
},
},
newWorkspace: {
defaultBase: "Ветка по умолчанию",
title: "Новое рабочее пространство",
create: "Создать",
isolation: {
+1
View File
@@ -1399,6 +1399,7 @@ export const zhCN: TranslationResources = {
},
},
newWorkspace: {
defaultBase: "默认分支",
title: "新建 workspace",
create: "创建",
isolation: {
@@ -405,9 +405,19 @@ describe("defaultBasePickerItem", () => {
});
});
it("has no default for detached HEAD", () => {
it("has no default for detached HEAD without a repository base", () => {
expect(defaultBasePickerItem({ currentBranch: null })).toBeNull();
});
it("names the repository's base on a detached HEAD instead of guessing", () => {
expect(
defaultBasePickerItem({
currentBranch: null,
baseRef: "master",
baseRefExact: "refs/remotes/origin/master",
}),
).toMatchObject({ kind: "branch", name: "master", refName: "refs/remotes/origin/master" });
});
});
describe("starting-ref search", () => {
@@ -137,6 +137,9 @@ export function buildBranchPickerItems(details: readonly BranchPickerDetail[]):
export interface BaseRefCheckoutStatus {
currentBranch: string | null;
upstreamRef?: string | null;
baseRef?: string | null;
baseRefExact?: string | null;
comparisonBaseRef?: string | null;
}
// Display only. The exact ref is what every request carries; this is just how a ref reads in
@@ -162,6 +165,13 @@ function refQualifier(refName: string): string | null {
return null;
}
function repositoryBasePickerItem(status: BaseRefCheckoutStatus): PickerItem | null {
const refName = status.baseRefExact ?? status.comparisonBaseRef ?? status.baseRef;
if (!refName) return null;
const name = branchNameFromRef(refName);
return { kind: "branch", name, refName, accessibilityLabel: name };
}
// The one owner of "what do we branch off when the user picked nothing". The checkmarked
// row, the trigger label, and the created ref all read this; computing it twice is how the
// picker once showed local main while branching off something else.
@@ -171,7 +181,9 @@ function refQualifier(refName: string): string | null {
// than a remote name, so a fork tracking upstream/main branches from upstream/main.
export function defaultBasePickerItem(status: BaseRefCheckoutStatus): PickerItem | null {
const currentBranch = status.currentBranch;
if (!currentBranch) return null;
// On a detached HEAD there is no branch to follow; name the base the daemon would use
// anyway, so the picker shows what will actually be created from.
if (!currentBranch) return repositoryBasePickerItem(status);
// COMPAT(checkoutUpstreamRef): added in v0.2.6, remove after 2027-02-01 once the daemon
// floor sends upstreamRef. Daemons that predate it omit the field, which lands on the
// local ref — the base those daemons always used.
@@ -1213,8 +1213,8 @@ export function NewWorkspaceScreen({
);
const triggerLabel = useMemo(() => {
const displayItem = itemById.get(selectedOptionId);
return displayItem ? pickerItemLabel(displayItem) : "main";
}, [itemById, selectedOptionId]);
return displayItem ? pickerItemLabel(displayItem) : t("newWorkspace.defaultBase");
}, [itemById, selectedOptionId, t]);
const selectPickerItem = useCallback(
(item: PickerItem) => {
setup.chooseRef(item);