MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / detectWorktreeIndexMismatch

Function detectWorktreeIndexMismatch

src/sync/worktree.ts:88–118  ·  view source on GitHub ↗
(
  startPath: string,
  indexRoot: string,
)

Source from the content-addressed store, hash-verified

86 * and monorepo-subdir layouts from producing false warnings.
87 */
88export function detectWorktreeIndexMismatch(
89 startPath: string,
90 indexRoot: string,
91): WorktreeIndexMismatch | null {
92 const worktreeRoot = gitWorktreeRoot(startPath);
93 if (!worktreeRoot) return null;
94
95 const resolvedIndexRoot = realpath(indexRoot);
96 if (worktreeRoot === resolvedIndexRoot) return null;
97
98 // Only flag it when the index root is itself a real working-tree root. This
99 // distinguishes "borrowed another worktree's index" from "index sits in a
100 // plain ancestor directory", and avoids warning outside git entirely.
101 if (gitWorktreeRoot(resolvedIndexRoot) !== resolvedIndexRoot) return null;
102
103 // Don't flag a nested repo (submodule / embedded clone) that `indexRoot`'s
104 // index ALREADY covers: indexing a super-repo descends into its submodules
105 // and gitlinked clones, so a query run from inside one resolves up to the
106 // parent index — whose graph *does* contain that nested repo's files. The
107 // warning's premise ("results are a different branch; symbols changed only
108 // here are missing") is false there, and its "run codegraph init -i" advice
109 // would needlessly fragment the unified workspace index. A genuine borrowed
110 // worktree and the index root are the SAME repository (they share a git
111 // common dir); a submodule/embedded clone is a DIFFERENT repository and does
112 // not — so suppress only when the two clearly differ. (#1031, #1033)
113 const worktreeCommon = gitCommonDir(worktreeRoot);
114 const indexCommon = gitCommonDir(resolvedIndexRoot);
115 if (worktreeCommon && indexCommon && worktreeCommon !== indexCommon) return null;
116
117 return { worktreeRoot, indexRoot: resolvedIndexRoot };
118}
119
120/** One-line-per-fact warning describing a detected mismatch. */
121export function worktreeMismatchWarning(m: WorktreeIndexMismatch): string {

Callers 3

worktreeMismatchForMethod · 0.90
mainFunction · 0.90

Calls 3

gitWorktreeRootFunction · 0.85
realpathFunction · 0.85
gitCommonDirFunction · 0.85

Tested by

no test coverage detected