Skip to main content

search_code

Function search_code 

Source
pub fn search_code(
    repo_root: &Path,
    query: &str,
    subpath: Option<&str>,
) -> (Vec<CodeMatch>, bool)
Expand description

Searches file contents across the repository’s working tree (tracked plus untracked-but-not-ignored), optionally scoped to subpath.

Runs git grep -n -I --untracked -e <query> [-- <subpath>] in repo_root. -I skips binary files, --untracked extends the search to untracked-not-ignored files. Returns matches as { path, line_number, line }, capped at [SEARCH_MATCH_CAP]; the returned flag reports whether the result was truncated. git grep exits 1 when there are no matches — that and a non-git directory both degrade to an empty list (never an error).