Skip to content

fix(search): always check parent index regardless of cwd#153

Merged
raphaelsty merged 1 commit into
lightonai:mainfrom
vlasky:fix/parent-index-cwd-gate
Jul 7, 2026
Merged

fix(search): always check parent index regardless of cwd#153
raphaelsty merged 1 commit into
lightonai:mainfrom
vlasky:fix/parent-index-cwd-gate

Conversation

@vlasky

@vlasky vlasky commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Removes the is_external_project_path gate that skipped find_parent_index when the search path was not a subdirectory of cwd
  • Fixes: searching an absolute path from an unrelated working directory failed to find the parent index, causing either a redundant index build or no results
  • The local_index_exists check already short-circuits the common case; find_parent_index is cheap (one read_dir + one JSON parse per indexed project)

Repro

# Index a project
colgrep init ~/projects/myrepo

# Search a subdirectory from an unrelated cwd
cd /tmp
colgrep "some query" ~/projects/myrepo/src/

Expected: uses existing index for ~/projects/myrepo
Actual (before fix): fails to find the parent index because /tmp is not an ancestor of the search path

Test plan

  • cargo build -p colgrep clean
  • cargo clippy -p colgrep -- -D warnings clean
  • cargo test -p colgrep --lib passes (662 tests)
  • Manual: search a subdirectory of an indexed project from an unrelated cwd, confirm parent index is used

The is_external_project_path gate skipped find_parent_index when the
search path was not a subdirectory of cwd. This meant that searching
an absolute path from an unrelated working directory (e.g. running
`colgrep "query" /path/to/sub/` from ~/.local/share/colgrep/indices)
would fail to find the parent index and either build a redundant
index or return no results.

The local_index_exists check already short-circuits the common case
(searching a directly-indexed project root). For subdirectory searches,
find_parent_index is both necessary and cheap (one read_dir + one JSON
parse per indexed project).

Removes is_external_project_path and its Windows-only test as they are
now dead code.
@raphaelsty

Copy link
Copy Markdown
Collaborator

Amazing MR @vlasky you rock 🤘☺️

@raphaelsty raphaelsty merged commit 14334f1 into lightonai:main Jul 7, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants