MCPcopy
hub / github.com/coder/mux / discoverGitRoots

Function discoverGitRoots

src/node/multiProject/gitRootDiscovery.ts:14–48  ·  view source on GitHub ↗
(workspacePath: string)

Source from the content-addressed store, hash-verified

12 * Returns empty array if no git roots are found.
13 */
14export async function discoverGitRoots(workspacePath: string): Promise<string[]> {
15 assert(workspacePath.trim().length > 0, "discoverGitRoots requires a non-empty workspacePath");
16
17 const entries = await fs.readdir(workspacePath, { withFileTypes: true });
18 const roots: string[] = [];
19
20 for (const entry of entries) {
21 if (!entry.isDirectory() && !entry.isSymbolicLink()) {
22 continue;
23 }
24
25 const childPath = path.join(workspacePath, entry.name);
26 const gitPath = path.join(childPath, ".git");
27
28 try {
29 await fs.access(gitPath);
30 roots.push(childPath);
31 } catch {
32 // Not a git root — skip.
33 }
34 }
35
36 // Single-project workspaces keep .git at the workspace root. Only check this
37 // fallback when no child repositories were discovered.
38 if (roots.length === 0) {
39 try {
40 await fs.access(path.join(workspacePath, ".git"));
41 roots.push(workspacePath);
42 } catch {
43 // Workspace is not a git repository.
44 }
45 }
46
47 return roots;
48}

Callers 1

Calls 2

pushMethod · 0.65
assertFunction · 0.50

Tested by

no test coverage detected