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

Function nestedRepositoryBelow

src/sync/worktree.ts:148–170  ·  view source on GitHub ↗
(startPath: string, indexRoot: string)

Source from the content-addressed store, hash-verified

146 * common dir): the #155 borrowed-worktree case, warned about, not refused.
147 */
148export function nestedRepositoryBelow(startPath: string, indexRoot: string): NestedRepository | null {
149 // git needs an existing directory to run in: a file, or a sub-path that does
150 // not exist yet, belongs to the repository of its nearest existing directory.
151 let dir = path.resolve(startPath);
152 while (!isDirectory(dir)) {
153 const up = path.dirname(dir);
154 if (up === dir) return null;
155 dir = up;
156 }
157 const repoRoot = gitWorktreeRoot(dir);
158 if (!repoRoot) return null;
159
160 // The on-disk spelling of both ends (`realpathSync.native` normalizes case on
161 // macOS and Windows), so `relPath` matches the paths the index stored.
162 const rel = path.relative(nativeRealpath(indexRoot), nativeRealpath(repoRoot));
163 if (!rel || rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) return null;
164
165 const repoCommon = gitCommonDir(repoRoot);
166 if (!repoCommon) return null;
167 const indexCommon = gitCommonDir(realpath(indexRoot));
168 if (indexCommon && sameDirectory(repoCommon, indexCommon)) return null;
169 return { root: repoRoot, relPath: rel.split(path.sep).join('/') };
170}
171
172function isDirectory(p: string): boolean {
173 try {

Callers 2

uncoveredNestedRepoMethod · 0.90

Calls 8

gitWorktreeRootFunction · 0.85
nativeRealpathFunction · 0.85
gitCommonDirFunction · 0.85
sameDirectoryFunction · 0.85
isDirectoryFunction · 0.70
realpathFunction · 0.70
resolveMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected