fix(cli): index <path> never rebuilds an ancestor instead (#1524) (#1797)

An explicit path names the project to rebuild; it is not a hint to go
looking for one. resolveProjectPath's upward walk is right for a query run
from a subdirectory, but for a full re-index it silently rebuilt the
nearest initialized parent's graph when <path> had no index of its own.
Refuse with the parent's path and the way to index <path> itself; a bare
`codegraph index` still resolves from cwd as before.

Fixes #1524

Co-authored-by: danusha2345 <ewidusoc498@gmail.com>
This commit is contained in:
Colby Mchenry
2026-09-08 16:00:58 -05:00
committed by GitHub
co-authored by danusha2345
parent 374b3b4209
commit 4fd816b610
3 changed files with 79 additions and 2 deletions
+13 -2
View File
@@ -791,7 +791,13 @@ program
.option('-q, --quiet', 'Suppress progress output')
.option('-v, --verbose', 'Show detailed worker lifecycle and memory info')
.action(async (pathArg: string | undefined, options: { force?: boolean; quiet?: boolean; verbose?: boolean }) => {
const projectPath = resolveProjectPath(pathArg);
// An EXPLICIT path names the project to rebuild — it is never a hint to go
// looking for one. resolveProjectPath walks up to the nearest initialized
// ancestor, which is right for `codegraph query` run from a subdirectory,
// but for a full re-index it silently rebuilt the parent's graph under a
// normal "Done" when <path> had no index of its own (#1524). Only a bare
// `codegraph index` (cwd) may resolve upward.
const projectPath = pathArg ? path.resolve(pathArg) : resolveProjectPath();
try {
// Don't (re)index your home directory / a filesystem root (#845). --force
@@ -804,7 +810,12 @@ program
if (!isInitialized(projectPath)) {
error(`CodeGraph not initialized in ${projectPath}`);
info('Run "codegraph init" first');
const ancestor = pathArg ? resolveProjectPath(pathArg) : projectPath;
if (ancestor !== projectPath) {
info(`The nearest initialized project is ${ancestor} — pass that path to rebuild it, or run "codegraph init" in ${projectPath} to index it on its own.`);
} else {
info('Run "codegraph init" first');
}
process.exit(1);
}