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

Function isGitRepository

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

Source from the content-addressed store, hash-verified

14 * @returns true if the directory is in a git repository, false otherwise
15 */
16export function isGitRepository(directory: string): boolean {
17 try {
18 let currentDir = path.resolve(directory);
19
20 while (true) {
21 const gitDir = path.join(currentDir, '.git');
22
23 // Check if .git exists (either as directory or file for worktrees)
24 if (fs.existsSync(gitDir)) {
25 return true;
26 }
27
28 const parentDir = path.dirname(currentDir);
29
30 // If we've reached the root directory, stop searching
31 if (parentDir === currentDir) {
32 break;
33 }
34
35 currentDir = parentDir;
36 }
37
38 return false;
39 } catch (_error) {
40 // If any filesystem error occurs, assume not a git repo
41 return false;
42 }
43}
44
45/**
46 * Finds the root directory of a git repository

Callers 5

performGrepSearchMethod · 0.85
loadGitRepoPatternsMethod · 0.85
getCoreSystemPromptFunction · 0.85
constructorMethod · 0.85
getInstallationInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected