fix(analyze): address Copilot review — ESM import, CLI option, .gitignore guard

- 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)
This commit is contained in:
Shunsuke Hayashi 2026-03-22 16:24:21 +09:00
parent 4dffd81b12
commit f0f384aab7
3 changed files with 6 additions and 3 deletions

View file

@ -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);
}

View file

@ -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'));

View file

@ -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 {