From f0f384aab796ca0c309c989079659bf4f7db08c2 Mon Sep 17 00:00:00 2001 From: Shunsuke Hayashi Date: Sun, 22 Mar 2026 16:24:21 +0900 Subject: [PATCH] =?UTF-8?q?fix(analyze):=20address=20Copilot=20review=20?= =?UTF-8?q?=E2=80=94=20ESM=20import,=20CLI=20option,=20.gitignore=20guard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace require(" fs\) with ESM-compatible top-level import (statSync) - Register --no-git option in Commander CLI definition - Use hasGitDir() instead of isGitRepo() for .gitignore update guard to match the PR intent (filesystem check vs git CLI invocation) --- gitnexus/src/cli/analyze.ts | 6 ++++-- gitnexus/src/cli/index.ts | 1 + gitnexus/src/storage/git.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) 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 {