MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / findEnvrcDirectory

Function findEnvrcDirectory

cli/src/init/init-direnv.ts:16–48  ·  view source on GitHub ↗
(startDir: string)

Source from the content-addressed store, hash-verified

14 * @internal
15 */
16export function findEnvrcDirectory(startDir: string): string | null {
17 let currentDir = path.resolve(startDir)
18 const root = path.parse(currentDir).root
19
20 while (currentDir !== root) {
21 // Read directory entries once and check for both .envrc and .git
22 let entries: string[]
23 try {
24 entries = fs.readdirSync(currentDir)
25 } catch {
26 // Directory not readable - stop searching
27 break
28 }
29
30 const hasEnvrc = entries.includes('.envrc')
31 const hasGit = entries.includes('.git')
32
33 if (hasEnvrc) {
34 return currentDir
35 }
36
37 // If this is a git root and no .envrc found, stop searching
38 if (hasGit) {
39 break
40 }
41
42 const parentDir = path.dirname(currentDir)
43 if (parentDir === currentDir) break
44 currentDir = parentDir
45 }
46
47 return null
48}
49
50/** @internal */
51export function isDirenvAvailable(): boolean {

Callers 2

initializeDirenvFunction · 0.85

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected