{"record":{"id":"8f82406da272087b","repo":"abhigyanpatwari/GitNexus","slug":"source-branch-name-is-too-long-max-branch-max-length","errorCode":null,"errorMessage":"${source}: branch name is too long (max ${BRANCH_MAX_LENGTH}).","messagePattern":"(.+?): branch name is too long \\(max (.+?)\\)\\.","errorType":"validation","errorClass":"InvalidBranchError","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/git-ref.ts","lineNumber":62,"sourceCode":"      throw new InvalidBranchError(\n        `${source}: value contains control or hidden/bidirectional characters, which are not allowed.`,\n      );\n    }\n  }\n};\n\n/**\n * Validate a user-supplied branch name. Returns the trimmed name or throws\n * {@link InvalidBranchError}. Conservative but accepts the shapes real\n * 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 InvalidBranchError(`${source}: branch name must not be empty.`);\n  }\n  if (trimmed.length > BRANCH_MAX_LENGTH) {\n    throw new InvalidBranchError(`${source}: branch name is too long (max ${BRANCH_MAX_LENGTH}).`);\n  }\n  assertNoHiddenChars(trimmed, source);\n  if (/\\s/.test(trimmed)) {\n    throw new InvalidBranchError(`${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 InvalidBranchError(\n      `${source}: branch name contains characters not allowed in a git ref (~ ^ : ? * [ \\\\).`,\n    );\n  }\n  if (trimmed.startsWith('-')) {\n    throw new InvalidBranchError(`${source}: branch name must not start with \"-\".`);\n  }\n  // Force-refspec prefix (`git fetch origin +main` / `+refs/heads/main:…`).\n  // Rejected here so neither the CLI nor HTTP can pass a force-update refspec\n  // through as a \"branch\" (#3199 review, defense in depth).\n  if (trimmed.startsWith('+')) {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/core/git-ref.ts#L44-L80","documentation":"validateBranchName enforces a maximum branch-name length (BRANCH_MAX_LENGTH) and throws InvalidBranchError '<source>: branch name is too long (max N).' when the trimmed value exceeds it. Overlong refs cause problems with git plumbing, filesystem path limits (.git/refs files), and downstream tools.","triggerScenarios":"Calling validateBranchName with a trimmed value whose length exceeds BRANCH_MAX_LENGTH — typically auto-generated names like long ticket slugs, timestamps, hashes, or AI-generated descriptive branch names concatenated together.","commonSituations":"Build systems that concatenate prefix + ticket ID + timestamp + user into a branch; CI-generated release branch names; migrating repos with extremely long legacy branch names.","solutions":["Shorten the branch name to at most BRANCH_MAX_LENGTH characters (trim descriptors, use IDs instead of prose).","Programmatically truncate or slugify generated names before validation, keeping a unique suffix.","Check the check the length limit value via BRANCH_MAX_LENGTH and enforce it in your name generator.","Use a shorter naming convention/prefix for automated branches."],"exampleFix":"// before\nconst branch = `${prefix}/${ticket}/${Date.now()}/${user}/${slug}`;\nvalidateBranchName(branch, 'ci');\n// after\nlet branch = `${prefix}/${ticket}/${slug}`;\nif (branch.length > BRANCH_MAX_LENGTH) branch = branch.slice(0, BRANCH_MAX_LENGTH);\nvalidateBranchName(branch, 'ci');","handlingStrategy":"validation","validationCode":"import { BRANCH_MAX_LENGTH } from './git-ref';\nif (name.length > BRANCH_MAX_LENGTH) {\n  name = name.slice(0, BRANCH_MAX_LENGTH);\n}","typeGuard":"const isWithinBranchLength = (v: string): boolean => v.length <= BRANCH_MAX_LENGTH;","tryCatchPattern":"try {\n  branch = validateBranchName(generated, 'ci');\n} catch (e) {\n  if (e instanceof InvalidBranchError && /too long/.test(e.message)) {\n    branch = validateBranchName(truncateWithHash(generated, BRANCH_MAX_LENGTH), 'ci');\n  } else throw e;\n}","preventionTips":["Cap generated branch names at BRANCH_MAX_LENGTH in your name generator.","Prefer short IDs/ticket numbers over prose in automated branch names.","Add a unit test that your naming scheme can never exceed the limit.","When importing legacy repos, rename over-long branches up front."],"tags":["git","branch-name","validation","length-limit"],"backgroundTag":"value-out-of-range","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-09-15T23:29:44.066Z","contentChangedAt":"2026-09-15T23:29:44.066Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}