{"record":{"id":"3408d725bd0c0fff","repo":"abhigyanpatwari/GitNexus","slug":"source-branch-name-must-not-contain-whitespace","errorCode":null,"errorMessage":"${source}: branch name must not contain whitespace.","messagePattern":"(.+?): branch name must not contain whitespace\\.","errorType":"validation","errorClass":"GitNexusRcError","httpStatus":null,"severity":"error","filePath":"gitnexus/src/cli/analyze-config.ts","lineNumber":168,"sourceCode":"  }\n};\n\n/**\n * Validate a user-supplied branch name (from CLI or `.gitnexusrc`). Returns the\n * trimmed name or throws {@link GitNexusRcError}. Conservative but accepts the\n * shapes real branches use (`feature/foo-bar`, `release/1.2`, `develop`).\n */\nexport function validateBranchName(value: string, source: string): string {\n  const trimmed = value.trim();\n  if (!trimmed) {\n    throw new GitNexusRcError(`${source}: branch name must not be empty.`);\n  }\n  if (trimmed.length > BRANCH_MAX_LENGTH) {\n    throw new GitNexusRcError(`${source}: branch name is too long (max ${BRANCH_MAX_LENGTH}).`);\n  }\n  assertNoHiddenChars(trimmed, source);\n  if (/\\s/.test(trimmed)) {\n    throw new GitNexusRcError(`${source}: branch name must not contain whitespace.`);\n  }\n  // git ref-name rules (subset): reject characters git itself forbids in refs.\n  if (/[~^:?*[\\\\]/.test(trimmed)) {\n    throw new GitNexusRcError(\n      `${source}: branch name contains characters not allowed in a git ref (~ ^ : ? * [ \\\\).`,\n    );\n  }\n  if (trimmed.startsWith('-')) {\n    throw new GitNexusRcError(`${source}: branch name must not start with \"-\".`);\n  }\n  if (trimmed.includes('..')) {\n    throw new GitNexusRcError(`${source}: branch name must not contain \"..\".`);\n  }\n  // Git permits a backtick in a ref, but the branch is embedded inside a\n  // Markdown inline-code span in the generated AGENTS.md/CLAUDE.md regression\n  // example, where a backtick would close the span early and let the rest of\n  // the template render as instruction text. Reject it at this single\n  // chokepoint so all three tiers (CLI flag, .gitnexusrc, auto-detect via","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/cli/analyze-config.ts#L150-L186","documentation":"Thrown by validateBranchName() when the (already trimmed) branch name contains any whitespace character (spaces, tabs, newlines). Git refnames cannot contain whitespace, and the branch is interpolated into a shell-like context in generated docs, so whitespace would break the example command.","triggerScenarios":"Passing --default-branch 'feature foo' (internal space), a name with a trailing tab that survived trim of outer spaces, or a multi-line value.","commonSituations":"A branch name with a typo'd space ('feature/ auth' instead of 'feature/auth'); pasting a name that included a newline; a config editor that auto-wrapped a long line.","solutions":["Replace internal whitespace with hyphens or underscores.","Re-type the branch name without spaces.","Verify the branch exists locally with `git branch --list` and copy the exact token."],"exampleFix":"# before\ngitnexus analyze --default-branch \"feature/auth refactor\"\n\n# after\ngitnexus analyze --default-branch \"feature/auth-refactor\"","handlingStrategy":"validation","validationCode":"function assertNoWhitespaceInBranch(name: string): void {\n  if (/\\s/.test(name.trim())) {\n    throw new Error('branch name must not contain whitespace');\n  }\n}","typeGuard":"function isBranchWithoutWhitespace(name: string): boolean {\n  return typeof name === 'string' && !/\\s/.test(name.trim());\n}","tryCatchPattern":null,"preventionTips":["Use hyphens or slashes as separators inside branch names, never spaces.","Confirm the exact branch token with `git branch --list` before passing it.","Watch for tabs/newlines introduced by terminal copy-paste."],"tags":["validation","git","branch","config"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}