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

Method worktreeMismatchFor

src/mcp/tools.ts:2851–2878  ·  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

2849 * broken by this check.
2850 */
2851 private worktreeMismatchFor(projectPath?: string): WorktreeIndexMismatch | null {
2852 const startPath = projectPath ?? this.defaultProjectHint ?? process.cwd();
2853
2854 // The verdict depends on BOTH the start path AND the index root it resolves
2855 // to, so the cache must be keyed on the pair. Resolve the index root first
2856 // (cheap — getCodeGraph re-walks to the nearest .codegraph/, no git), then
2857 // key on `(startPath, indexRoot)`. The moment that root changes — most
2858 // importantly when a git worktree gains its own index and the walk-up stops
2859 // there instead of at the parent checkout — the key changes and the verdict
2860 // is recomputed, instead of serving the stale "borrowed the parent's index"
2861 // warning for the server's whole lifetime. Keying on startPath alone pinned
2862 // that first verdict until restart (#926).
2863 let indexRoot: string;
2864 try {
2865 indexRoot = this.getCodeGraph(projectPath).getProjectRoot();
2866 } catch {
2867 // No resolvable project (or any other resolution error) → nothing to warn.
2868 return null;
2869 }
2870
2871 const cacheKey = `${startPath}\u0000${indexRoot}`;
2872 const cached = this.worktreeMismatchCache.get(cacheKey);
2873 if (cached !== undefined) return cached;
2874
2875 const mismatch = detectWorktreeIndexMismatch(startPath, indexRoot);
2876 this.worktreeMismatchCache.set(cacheKey, mismatch);
2877 return mismatch;
2878 }
2879
2880 /**
2881 * 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