MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / worktreeMismatchFor

Method worktreeMismatchFor

src/mcp/tools.ts:2783–2810  ·  view source on GitHub ↗

* Cached git worktree/index mismatch for a tool call's effective project. * * The "effective project" is what the request targets: an explicit * `projectPath` arg, else the directory the server resolved its default * project from (`defaultProjectHint`), else cwd. Memoized per start path

(projectPath?: string)

Source from the content-addressed store, hash-verified

2781 * broken by this check.
2782 */
2783 private worktreeMismatchFor(projectPath?: string): WorktreeIndexMismatch | null {
2784 const startPath = projectPath ?? this.defaultProjectHint ?? process.cwd();
2785
2786 // The verdict depends on BOTH the start path AND the index root it resolves
2787 // to, so the cache must be keyed on the pair. Resolve the index root first
2788 // (cheap — getCodeGraph re-walks to the nearest .codegraph/, no git), then
2789 // key on `(startPath, indexRoot)`. The moment that root changes — most
2790 // importantly when a git worktree gains its own index and the walk-up stops
2791 // there instead of at the parent checkout — the key changes and the verdict
2792 // is recomputed, instead of serving the stale "borrowed the parent's index"
2793 // warning for the server's whole lifetime. Keying on startPath alone pinned
2794 // that first verdict until restart (#926).
2795 let indexRoot: string;
2796 try {
2797 indexRoot = this.getCodeGraph(projectPath).getProjectRoot();
2798 } catch {
2799 // No resolvable project (or any other resolution error) → nothing to warn.
2800 return null;
2801 }
2802
2803 const cacheKey = `${startPath}\u0000${indexRoot}`;
2804 const cached = this.worktreeMismatchCache.get(cacheKey);
2805 if (cached !== undefined) return cached;
2806
2807 const mismatch = detectWorktreeIndexMismatch(startPath, indexRoot);
2808 this.worktreeMismatchCache.set(cacheKey, mismatch);
2809 return mismatch;
2810 }
2811
2812 /**
2813 * Prefix a successful read-tool result with a compact worktree-mismatch

Callers 2

withWorktreeNoticeMethod · 0.95
handleStatusMethod · 0.95

Calls 5

getCodeGraphMethod · 0.95
getProjectRootMethod · 0.65
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected