diff --git a/gitnexus/src/cli/analyze.ts b/gitnexus/src/cli/analyze.ts index cec7074c3..dc6270f2b 100644 --- a/gitnexus/src/cli/analyze.ts +++ b/gitnexus/src/cli/analyze.ts @@ -328,8 +328,10 @@ export const analyzeCommand = async ( }; await saveMeta(storagePath, meta); await registerRepo(repoPath, meta); - // Only attempt to update .gitignore when a git repository is present - if (repoHasGit) { + // Only attempt to update .gitignore when a .git directory is present. + // Use hasGitDir (filesystem check) rather than isGitRepo (shells out to git) + // so we skip correctly for --no-git folders even if git CLI is available. + if (hasGitDir(repoPath)) { await addToGitignore(repoPath); } diff --git a/gitnexus/src/cli/index.ts b/gitnexus/src/cli/index.ts index 6f5164f5c..f0e88acc3 100644 --- a/gitnexus/src/cli/index.ts +++ b/gitnexus/src/cli/index.ts @@ -28,6 +28,7 @@ program .option('-f, --force', 'Force full re-index even if up to date') .option('--embeddings', 'Enable embedding generation for semantic search (off by default)') .option('--skills', 'Generate repo-specific skill files from detected communities') + .option('--no-git', 'Index a folder without requiring a .git directory') .option('-v, --verbose', 'Enable verbose ingestion warnings (default: false)') .addHelpText('after', '\nEnvironment variables:\n GITNEXUS_NO_GITIGNORE=1 Skip .gitignore parsing (still reads .gitnexusignore)') .action(createLazyAction(() => import('./analyze.js'), 'analyzeCommand')); diff --git a/gitnexus/src/storage/git.ts b/gitnexus/src/storage/git.ts index 3b4381b93..b9330ff91 100644 --- a/gitnexus/src/storage/git.ts +++ b/gitnexus/src/storage/git.ts @@ -1,4 +1,5 @@ import { execSync } from 'child_process'; +import { statSync } from 'fs'; import path from 'path'; // Git utilities for repository detection, commit tracking, and diff analysis @@ -47,7 +48,6 @@ export const getGitRoot = (fromPath: string): string | null => { */ export const hasGitDir = (dirPath: string): boolean => { try { - const { statSync } = require('fs') as typeof import('fs'); statSync(path.join(dirPath, '.git')); return true; } catch {