{"record":{"id":"77df7467483eb584","repo":"gitbutlerapp/gitbutler","slug":"no-branch-selected-77df74","errorCode":null,"errorMessage":"No branch selected!","messagePattern":"No branch selected!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/desktop/src/components/commit/NewCommitView.svelte","lineNumber":85,"sourceCode":"\t\t\tconst parentId = commitAction?.parentCommitId;\n\t\t\tconst insertBelow = commitAction?.insertBelow;\n\n\t\t\tif (!finalStackId) {\n\t\t\t\tconst stack = await createNewStack({\n\t\t\t\t\tprojectId,\n\t\t\t\t\tbranch: { name: finalBranchName, order: 0 },\n\t\t\t\t});\n\t\t\t\tfinalStackId = stack.id ?? undefined;\n\t\t\t\tfinalBranchName = stack.heads[0]?.name; // Updated to access the name property\n\t\t\t\tuiState.global.draftBranchName.set(undefined);\n\t\t\t}\n\n\t\t\tif (!finalStackId) {\n\t\t\t\tthrow new Error(\"No stack selected!\");\n\t\t\t}\n\n\t\t\tif (!finalBranchName) {\n\t\t\t\tthrow new Error(\"No branch selected!\");\n\t\t\t}\n\n\t\t\t// Run commit-msg hook if hooks are enabled\n\t\t\tlet finalMessage = message;\n\t\t\tif ($runCommitHooks) {\n\t\t\t\tconst messageHookResult = await runMessageHook({ projectId, message });\n\t\t\t\tif (messageHookResult?.status === \"failure\") {\n\t\t\t\t\tshowWarning(\"Commit message hook failed\", messageHookResult.error);\n\t\t\t\t\treturn;\n\t\t\t\t} else if (messageHookResult?.status === \"message\") {\n\t\t\t\t\tfinalMessage = messageHookResult.message;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst worktreeChanges = await uncommittedService.worktreeChanges(projectId, stackId);\n\n\t\t\t// Get current editor mode from the component instance\n\t\t\tconst isRichTextMode = input?.isRichTextMode?.() || false;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/apps/desktop/src/components/commit/NewCommitView.svelte#L67-L103","documentation":"Thrown in the new-commit flow when finalBranchName is falsy after stack resolution. The name normally comes from the draft branch name state (uiState.global.draftBranchName) or from the freshly created stack's heads[0].name; when both are absent there is no head branch to commit onto.","triggerScenarios":"Committing with no draft branch name set and the existing/created stack exposing an empty heads array (heads[0]?.name is undefined); stack exists with an id but zero head branches.","commonSituations":"A stack left in a headless state after all its branches were deleted or merged; the draft-branch state was cleared (uiState.global.draftBranchName.set(undefined)) while the commit form stayed open; backend returned a stack DTO without heads.","solutions":["Provide/confirm a branch name in the commit form before saving (pick a target branch in the UI).","Check that the target stack actually has head branches; if it is empty, delete it and let GitButler create a fresh one.","In code, validate stack.heads[0]?.name right after createNewStack and retry or surface the error there.","Reload the project view so branch state is re-synced from the backend."],"exampleFix":"// before\nif (!finalBranchName) {\n  throw new Error(\"No branch selected!\");\n}\n\n// after\nif (!finalBranchName) {\n  showWarning(\"No branch to commit to\", \"The stack has no head branches; create a branch first\");\n  return;\n}","handlingStrategy":"validation","validationCode":"const draftName = $uiState.global.draftBranchName ?? stack.heads[0]?.name;\nif (!draftName) {\n  showWarning(\"No branch to commit to\", \"Create a branch in this stack first\");\n  return;\n}","typeGuard":"function hasBranchName(b: string | null | undefined): b is string {\n  return typeof b === \"string\" && b.trim().length > 0;\n}","tryCatchPattern":"try {\n  await createCommit(/* ... */);\n} catch (e) {\n  if (e instanceof Error && e.message === \"No branch selected!\") {\n    showToast({ message: \"Pick a target branch, then commit again\", style: \"danger\" });\n  } else throw e;\n}","preventionTips":["Require a non-empty branch name in the commit form before enabling save.","After createNewStack, verify stack.heads[0]?.name exists before proceeding.","Clear draft-branch UI state only after confirming the replacement name."],"tags":["svelte","gitbutler","branch","commit","desktop"],"backgroundTag":"missing-branch-selection","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}