{"record":{"id":"313c87b65490cd46","repo":"paperclipai/paperclip","slug":"branch-name-is-required","errorCode":null,"errorMessage":"Branch name is required.","messagePattern":"Branch name is required\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":628,"sourceCode":"}\n\nfunction detectGitBranchName(cwd: string): string | null {\n  try {\n    const value = execFileSync(\"git\", [\"branch\", \"--show-current\"], {\n      cwd,\n      encoding: \"utf8\",\n      stdio: [\"ignore\", \"pipe\", \"ignore\"],\n    }).trim();\n    return nonEmpty(value);\n  } catch {\n    return null;\n  }\n}\n\nfunction validateGitBranchName(cwd: string, branchName: string): string {\n  const value = nonEmpty(branchName);\n  if (!value) {\n    throw new Error(\"Branch name is required.\");\n  }\n  try {\n    execFileSync(\"git\", [\"check-ref-format\", \"--branch\", value], {\n      cwd,\n      stdio: [\"ignore\", \"pipe\", \"pipe\"],\n    });\n  } catch (error) {\n    throw new Error(`Invalid branch name \"${branchName}\": ${extractExecSyncErrorMessage(error) ?? String(error)}`);\n  }\n  return value;\n}\n\nfunction isPrimaryGitWorktree(cwd: string): boolean {\n  const workspace = detectGitWorkspaceInfo(cwd);\n  return Boolean(workspace && workspace.gitDir === workspace.commonDir);\n}\n\nfunction resolvePrimaryGitRepoRoot(cwd: string): string {","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/worktree.ts#L610-L646","documentation":"Thrown by validateGitBranchName when nonEmpty(branchName) returns falsy, i.e. the branch name argument is empty, whitespace-only, or null/undefined. The validator needs a non-empty branch before it can run git check-ref-format.","triggerScenarios":"Calling a worktree repair/resolve flow with input.selector that is empty or all whitespace; the selector came from detectGitBranchName returning null in a detached-HEAD state and was passed through unguarded; CLI flag --branch supplied as empty string.","commonSituations":"Detached HEAD where git branch --show-current returns nothing; a selector/flag that defaulted to empty; whitespace-only input from a templated command; programmatic call passing undefined.","solutions":["Provide an explicit non-empty branch name via the selector or --branch flag.","If in detached HEAD, check out or name a branch first before running the worktree command.","Validate input.selector with nonEmpty before calling the resolver and surface a clearer CLI error.","Detect detached HEAD upstream and require the user to specify a branch explicitly."],"exampleFix":"// before\nconst branch = detectGitBranchName(cwd) ?? '';\nvalidateGitBranchName(repoRoot, branch);\n// after\nconst branch = nonEmpty(detectGitBranchName(cwd));\nif (!branch) throw new Error('Detached HEAD: pass --branch explicitly.');\nvalidateGitBranchName(repoRoot, branch);","handlingStrategy":"validation","validationCode":"function requireBranchName(raw: string | null | undefined): string {\n  const v = nonEmpty(raw);\n  if (!v) throw new Error('Branch name required (detached HEAD? pass --branch).');\n  return v;\n}","typeGuard":"function isNonEmptyBranchName(name: unknown): name is string {\n  return typeof name === 'string' && name.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Pass --branch explicitly in detached-HEAD contexts.","Validate selector with nonEmpty before calling the resolver.","Detect detached HEAD upstream and prompt for a branch."],"tags":["git","worktree","validation","branch"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}