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

Method worktreeMismatchFor

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

2966 * broken by this check.
2967 */
2968 private worktreeMismatchFor(projectPath?: string): WorktreeIndexMismatch | null {
2969 const startPath = projectPath ?? this.defaultProjectHint ?? process.cwd();
2970
2971 // The verdict depends on BOTH the start path AND the index root it resolves
2972 // to, so the cache must be keyed on the pair. Resolve the index root first
2973 // (cheap — getCodeGraph re-walks to the nearest .codegraph/, no git), then
2974 // key on `(startPath, indexRoot)`. The moment that root changes — most
2975 // importantly when a git worktree gains its own index and the walk-up stops
2976 // there instead of at the parent checkout — the key changes and the verdict
2977 // is recomputed, instead of serving the stale "borrowed the parent's index"
2978 // warning for the server's whole lifetime. Keying on startPath alone pinned
2979 // that first verdict until restart (#926).
2980 let indexRoot: string;
2981 try {
2982 indexRoot = this.getCodeGraph(projectPath).getProjectRoot();
2983 } catch {
2984 // No resolvable project (or any other resolution error) → nothing to warn.
2985 return null;
2986 }
2987
2988 const cacheKey = `${startPath}\u0000${indexRoot}`;
2989 const cached = this.worktreeMismatchCache.get(cacheKey);
2990 if (cached !== undefined) return cached;
2991
2992 const mismatch = detectWorktreeIndexMismatch(startPath, indexRoot);
2993 this.worktreeMismatchCache.set(cacheKey, mismatch);
2994 return mismatch;
2995 }
2996
2997 /**
2998 * 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