MCPcopy Create free account
hub / github.com/anus-dev/ANUS / findGitRoot

Function findGitRoot

packages/core/src/utils/gitUtils.ts:50–74  ·  view source on GitHub ↗
(directory: string)

Source from the content-addressed store, hash-verified

48 * @returns The git repository root path, or null if not in a git repository
49 */
50export function findGitRoot(directory: string): string | null {
51 try {
52 let currentDir = path.resolve(directory);
53
54 while (true) {
55 const gitDir = path.join(currentDir, '.git');
56
57 if (fs.existsSync(gitDir)) {
58 return currentDir;
59 }
60
61 const parentDir = path.dirname(currentDir);
62
63 if (parentDir === currentDir) {
64 break;
65 }
66
67 currentDir = parentDir;
68 }
69
70 return null;
71 } catch (_error) {
72 return null;
73 }
74}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected