* 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)
| 233 | * copy only when the worktree lacks one. |
| 234 | */ |
| 235 | function resolveStopBoundary(cwd: string): string | null { |
| 236 | const cwdGitRoot = findGitRoot(cwd) |
| 237 | const sessionGitRoot = findGitRoot(getProjectRoot()) |
| 238 | if (!cwdGitRoot || !sessionGitRoot) { |
| 239 | return cwdGitRoot |
| 240 | } |
| 241 | // findCanonicalGitRoot resolves worktree `.git` files to the main repo. |
| 242 | // Submodules (no commondir) and standalone clones fall through unchanged. |
| 243 | const cwdCanonical = findCanonicalGitRoot(cwd) |
| 244 | if ( |
| 245 | cwdCanonical && |
| 246 | normalizePathForComparison(cwdCanonical) === |
| 247 | normalizePathForComparison(sessionGitRoot) |
| 248 | ) { |
| 249 | // Same canonical repo (main, or a worktree of main). Stop at nearest .git. |
| 250 | return cwdGitRoot |
| 251 | } |
| 252 | // Different canonical repo. Is it nested *inside* the session's project? |
| 253 | const nCwdGitRoot = normalizePathForComparison(cwdGitRoot) |
| 254 | const nSessionRoot = normalizePathForComparison(sessionGitRoot) |
| 255 | if ( |
| 256 | nCwdGitRoot !== nSessionRoot && |
| 257 | nCwdGitRoot.startsWith(nSessionRoot + sep) |
| 258 | ) { |
| 259 | // Nested repo inside the project — skip past it, stop at the project's root. |
| 260 | return sessionGitRoot |
| 261 | } |
| 262 | // Sibling repo or elsewhere. Stop at nearest .git (old behavior). |
| 263 | return cwdGitRoot |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Traverses from the current directory up to the git root (or home directory if not in a git repo), |
no test coverage detected