MCPcopy
hub / github.com/claude-code-best/claude-code / resolveStopBoundary

Function resolveStopBoundary

src/utils/markdownConfigLoader.ts:191–220  ·  view source on GitHub ↗

* Compute the stop boundary for getProjectDirsUpToHome's upward walk. * * Normally the walk stops at the nearest `.git` above `cwd`. But if the Bash * tool has cd'd into a nested git repo inside the session's project (submodule, * vendored dep with its own `.git`), that nested root isn't the rig

(cwd: string)

Source from the content-addressed store, hash-verified

189 * copy only when the worktree lacks one.
190 */
191function resolveStopBoundary(cwd: string): string | null {
192 const cwdGitRoot = findGitRoot(cwd)
193 const sessionGitRoot = findGitRoot(getProjectRoot())
194 if (!cwdGitRoot || !sessionGitRoot) {
195 return cwdGitRoot
196 }
197 // findCanonicalGitRoot resolves worktree `.git` files to the main repo.
198 // Submodules (no commondir) and standalone clones fall through unchanged.
199 const cwdCanonical = findCanonicalGitRoot(cwd)
200 if (
201 cwdCanonical &&
202 normalizePathForComparison(cwdCanonical) ===
203 normalizePathForComparison(sessionGitRoot)
204 ) {
205 // Same canonical repo (main, or a worktree of main). Stop at nearest .git.
206 return cwdGitRoot
207 }
208 // Different canonical repo. Is it nested *inside* the session's project?
209 const nCwdGitRoot = normalizePathForComparison(cwdGitRoot)
210 const nSessionRoot = normalizePathForComparison(sessionGitRoot)
211 if (
212 nCwdGitRoot !== nSessionRoot &&
213 nCwdGitRoot.startsWith(nSessionRoot + sep)
214 ) {
215 // Nested repo inside the project — skip past it, stop at the project's root.
216 return sessionGitRoot
217 }
218 // Sibling repo or elsewhere. Stop at nearest .git (old behavior).
219 return cwdGitRoot
220}
221
222/**
223 * Traverses from the current directory up to the git root (or home directory if not in a git repo),

Callers 1

getProjectDirsUpToHomeFunction · 0.85

Calls 2

getProjectRootFunction · 0.85

Tested by

no test coverage detected