Skip to content

fix(mcp): translate Git-root paths for subdirectory projects in detect_changes (#1951) - #2334

Merged
DeusData merged 2 commits into
mainfrom
fix/issue-1951
Sep 30, 2026
Merged

DeusData merged 2 commits into
mainfrom
fix/issue-1951

Conversation

@DeusData

Copy link
Copy Markdown
Owner

When the indexed project root is a subdirectory of a normal Git
repository, detect_changes found the changed file but seeded zero
symbols. Git reports diff and porcelain status paths relative to the
Git ROOT ("game/src/math.ts"), while graph file_paths are relative to
the project root ("src/math.ts"), so the seed lookup never matched.
The same mismatch left the hunk-scoping paths and the snapshot
fingerprint (root_path + git path) pointing at the wrong files.

Resolve the project's position in the worktree with
rev-parse --show-prefix in the existing revision-resolution call,
translate every diff/status record into project-relative coordinates
(records outside the project are left out, as they have no graph
nodes), and run the hunk diff with --relative so hunk paths use the
same coordinates. At the repository root the prefix is empty and the
behavior is unchanged.


Touches src/mcp/mcp.c / tests/test_mcp.c like the #1827 PR; trivial rebase after whichever lands first.

Fixes #1951

…t_changes (#1951)

When the indexed project root is a subdirectory of a normal Git
repository, detect_changes found the changed file but seeded zero
symbols. Git reports diff and porcelain status paths relative to the
Git ROOT ("game/src/math.ts"), while graph file_paths are relative to
the project root ("src/math.ts"), so the seed lookup never matched.
The same mismatch left the hunk-scoping paths and the snapshot
fingerprint (root_path + git path) pointing at the wrong files.

Resolve the project's position in the worktree with
`rev-parse --show-prefix` in the existing revision-resolution call,
translate every diff/status record into project-relative coordinates
(records outside the project are left out, as they have no graph
nodes), and run the hunk diff with --relative so hunk paths use the
same coordinates. At the repository root the prefix is empty and the
behavior is unchanged.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
The --show-prefix reader added a raw free(), growing src/mcp/mcp.c past
its memory-core ratchet (784 -> 785). HEAD, base and prefix now share
detect_read_rev_parse_line (read, drop a trailing CR, validate, copy,
free), which removes the two per-record frees in handle_detect_changes;
mcp.c is at 783. Validation and read order are unchanged.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData
DeusData merged commit e2f9fcc into main Sep 30, 2026
40 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.

detect_changes loses impacted symbols when the indexed project is a subdirectory of a normal Git repository

1 participant