{"record":{"id":"b6521d21249e277e","repo":"abhigyanpatwari/GitNexus","slug":"source-branch-name-contains-characters-not-all","errorCode":null,"errorMessage":"${source}: branch name contains characters not allowed in a git ref (~ ^ : ? * [ \\\\).","messagePattern":"(.+?): branch name contains characters not allowed in a git ref \\(~ \\^ : \\? \\* \\[ \\\\\\\\\\)\\.","errorType":"validation","errorClass":"GitNexusRcError","httpStatus":null,"severity":"error","filePath":"gitnexus/src/cli/analyze-config.ts","lineNumber":172,"sourceCode":" * 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\n  // sanitizeDetectedBranch) are covered (#1996 tri-review P1).\n  if (trimmed.includes('`')) {\n    throw new GitNexusRcError(\n      `${source}: branch name must not contain a backtick (it would break the generated Markdown).`,","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/cli/analyze-config.ts#L154-L190","documentation":"Thrown by validateBranchName() when the branch name contains any character git forbids in a refname: ~ ^ : ? * [ \\. These characters have special meaning to git (revision syntax, globbing, path separators) and would break the generated checkout command or be rejected by git itself.","triggerScenarios":"Passing a branch name containing '~' (as in 'HEAD~1'), ':' (revision range syntax), '*' (glob), '?' (single-match), '[' (charclass), '^' (parent), or '\\' (Windows path separator leaked in).","commonSituations":"A Windows user pasting a branch name that included a backslash; a name like 'fix:wip' using a colon; an attempt to pass a git rev-parse expression instead of a branch.","solutions":["Use only git-refname-safe characters: letters, digits, '-', '_', '.', '/'.","Replace any ':' or '\\' with '-' or '/'.","If you meant to pass a revision expression, that is not supported here — pass a branch name."],"exampleFix":"// before\n{ \"defaultBranch\": \"bugfix:auth\" }\n\n// after\n{ \"defaultBranch\": \"bugfix/auth\" }","handlingStrategy":"validation","validationCode":"function assertGitRefSafe(name: string): void {\n  if (/[~^:?*[\\\\]/.test(name)) {\n    throw new Error(`branch name contains a forbidden git-ref character`);\n  }\n}","typeGuard":"function isGitRefSafe(name: string): boolean {\n  return typeof name === 'string' && !/[~^:?*[\\\\]/.test(name);\n}","tryCatchPattern":null,"preventionTips":["Restrict branch names to [A-Za-z0-9._-/] plus the allowed prefix shapes.","Never pass a git rev-parse expression (HEAD~1, A:B) where a branch name is expected.","On Windows, watch for backslashes leaked from path copy-paste."],"tags":["validation","git","branch","config","security"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}