{"record":{"id":"463824457b95c5f1","repo":"abhigyanpatwari/GitNexus","slug":"branch-options-branch-does-not-match-the-ch","errorCode":null,"errorMessage":"--branch \"${options.branch}\" does not match the checked-out branch \"${checkedOutBranch}\". Check out \"${options.branch}\" before indexing it, or omit --branch to index the current branch.","messagePattern":"--branch \"(.+?)\" does not match the checked-out branch \"(.+?)\"\\. Check out \"(.+?)\" before indexing it, or omit --branch to index the current branch\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/run-analyze.ts","lineNumber":1084,"sourceCode":"  const storagePath = await requireStoragePath(\n    repoPath,\n    options.force ? ANALYZE_FORCE_STORAGE_REQUIREMENTS : ANALYZE_STORAGE_REQUIREMENTS,\n  );\n  const repoHasGit = hasGitDir(repoPath);\n  const currentCommit = repoHasGit ? getCurrentCommit(repoPath) : '';\n  // Normalize the auto-detected branch the same way an explicit `--branch` is\n  // validated (#2106 R1): a git ref the branch-name rules forbid becomes `null`\n  // → the flat slot, matching that a later `--branch <that-ref>` query would\n  // also be rejected. A normal ref round-trips index-time/query-time labels.\n  const checkedOutBranch = repoHasGit\n    ? (sanitizeDetectedBranch(getCurrentBranch(repoPath)) ?? null)\n    : null;\n  // Analyze indexes the working tree, not an arbitrary ref. An explicit\n  // `--branch X` while a DIFFERENT branch Y is checked out would write Y's\n  // content into X's slot, corrupting X (#2106). Refuse the mismatch. Detached\n  // HEAD / non-git (checkedOutBranch === null) still allow an explicit label.\n  if (options.branch && checkedOutBranch && options.branch !== checkedOutBranch) {\n    throw new Error(\n      `--branch \"${options.branch}\" does not match the checked-out branch \"${checkedOutBranch}\". ` +\n        `Check out \"${options.branch}\" before indexing it, or omit --branch to index the current branch.`,\n    );\n  }\n  const branchLabel = options.branch ?? checkedOutBranch;\n  const placement = options.branch\n    ? await resolveBranchPlacement(repoPath, branchLabel, storagePath)\n    : {};\n  const { lbugPath, metaPath } = getStoragePaths(repoPath, placement.branch, storagePath);\n  return {\n    storagePath,\n    repoHasGit,\n    currentCommit,\n    checkedOutBranch,\n    branchLabel,\n    placement,\n    lbugPath,\n    metaPath,","sourceCodeStart":1066,"sourceCodeEnd":1102,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/core/run-analyze.ts#L1066-L1102","documentation":"Error \"--branch \"${options.branch}\" does not match the checked-out branch \"${checkedOutBranch}\". Check out \"${options.branch}\" before indexing it, or omit --branch to index the current branch.\" thrown in abhigyanpatwari/GitNexus.","triggerScenarios":"Thrown at gitnexus/src/core/run-analyze.ts:967 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}