* fix(git): suppress stderr leak in getCurrentCommit and getGitRoot (#1172)
Node's execSync forwards the child's stderr to the parent process when
the stdio option is not explicitly set. getCurrentCommit and getGitRoot
both caught the resulting error but did not suppress the stderr output,
causing "fatal: not a git repository" messages to leak to the terminal
whenever they were called on a path outside a git worktree.
Add stdio: ['ignore', 'pipe', 'ignore'] to both functions, matching the
pattern already used by getRemoteUrl, getRemoteOriginUrl, and
getCanonicalRepoRoot in the same file.
* address review: add getGitRoot stderr test, normalize em dashes to ASCII
- Add matching process.stderr.write spy test for getGitRoot (#1172)
- Replace U+2014 em dashes with ASCII -- in new comments
Previously gitnexus analyze exited with an error on any directory that
lacked a .git entry, making it impossible to index generated code,
vendored libraries, or monorepo sub-trees that are not git roots.
Changes:
storage/git.ts
- Add hasGitDir(dirPath): boolean — a lightweight synchronous check for
the presence of a .git file or directory. Works for git worktrees
(.git file pointing at the real repo) as well as standard repos.
cli/analyze.ts
- Add noGit?: boolean to AnalyzeOptions.
- When the explicit inputPath resolves to a non-git folder (or the cwd
is not inside any git repo), respect --no-git instead of hard-failing.
- Print an actionable tip pointing at --no-git when git is absent and the
flag was not supplied.
- currentCommit defaults to an empty string for non-git folders so the
up-to-date check still functions (empty string never matches a real
commit hash, so the index is always rebuilt).
- Skip addToGitignore() when no .git is present — there is nothing to
update and the function would create a stale .gitignore at the root.
Git-dependent features that remain disabled for non-git folders:
- Incremental update (always rebuilds from scratch)
- Commit tracking in metadata
- .gitignore update
Closes#384