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

Function getDirectories

cli/src/utils/directory-browser.ts:15–60  ·  view source on GitHub ↗
(dirPath: string)

Source from the content-addressed store, hash-verified

13 * Skips hidden directories (those starting with '.').
14 */
15export function getDirectories(dirPath: string): DirectoryEntry[] {
16 const entries: DirectoryEntry[] = []
17
18 // Add parent directory option if not at filesystem root
19 const parentDir = path.dirname(dirPath)
20 if (parentDir !== dirPath) {
21 entries.push({
22 name: '..',
23 path: parentDir,
24 isParent: true,
25 isGitRepo: false,
26 })
27 }
28
29 try {
30 const items = readdirSync(dirPath)
31 for (const item of items) {
32 // Skip hidden directories
33 if (item.startsWith('.')) continue
34
35 const fullPath = path.join(dirPath, item)
36 try {
37 const stat = statSync(fullPath)
38 if (stat.isDirectory()) {
39 entries.push({
40 name: item,
41 path: fullPath,
42 isParent: false,
43 isGitRepo: hasGitDirectory(fullPath),
44 })
45 }
46 } catch {
47 // Skip items we can't stat
48 }
49 }
50 } catch {
51 // If we can't read the directory, just return parent option
52 }
53
54 // Sort non-parent entries alphabetically (case-insensitive)
55 const parentEntry = entries.find((e) => e.isParent)
56 const childEntries = entries.filter((e) => !e.isParent)
57 childEntries.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()))
58
59 return parentEntry ? [parentEntry, ...childEntries] : childEntries
60}
61
62/**
63 * Check if a directory contains a .git subdirectory.

Callers 1

useDirectoryBrowserFunction · 0.90

Calls 1

hasGitDirectoryFunction · 0.85

Tested by

no test coverage detected