Skip to content

fix(review): resolve repo root for untracked file discovery - #450

Merged
backnotprop merged 1 commit into
backnotprop:mainfrom
blimmer:fix/untracked-files-subdirectory-cwd
Mar 31, 2026
Merged

backnotprop merged 1 commit into
backnotprop:mainfrom
blimmer:fix/untracked-files-subdirectory-cwd

Conversation

@blimmer

@blimmer blimmer commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Resolve repo root in getUntrackedFileDiffs so git ls-files lists all untracked files, not just those under the process CWD
  • Use the resolved root as CWD for git diff --no-index so paths are root-relative, matching tracked-diff output
  • Add regression test that runs runGitDiff from a subdirectory

Problem

git ls-files --others --exclude-standard scopes to the CWD subtree and returns CWD-relative paths. git diff HEAD always covers the full repo with root-relative paths. When the hook process inherits a subdirectory CWD (e.g., an agent that cd'd into packages/foo/), untracked files outside that subtree are silently dropped and the one that is found gets a wrong relative path in the diff header.

AI

Note that I used Opus 4.6 to assist with identifying, filing the GitHub issue, and the TDD-resolution of this bug.

Fixes #449

git ls-files scopes to the CWD subtree and returns CWD-relative paths,
unlike git diff HEAD which covers the full repo with root-relative paths.
When the hook process inherits a subdirectory CWD, untracked files outside
that subtree are silently dropped and paths for files inside it are wrong.

Resolve the repo root via rev-parse --show-toplevel and use it as the CWD
for both git ls-files and git diff --no-index in getUntrackedFileDiffs.

Fixes backnotprop#449
@backnotprop

Copy link
Copy Markdown
Owner

looks good thanks!

@backnotprop
backnotprop merged commit cce877d into backnotprop:main Mar 31, 2026
5 checks passed
backnotprop pushed a commit that referenced this pull request Apr 1, 2026
git ls-files scopes to the CWD subtree and returns CWD-relative paths,
unlike git diff HEAD which covers the full repo with root-relative paths.
When the hook process inherits a subdirectory CWD, untracked files outside
that subtree are silently dropped and paths for files inside it are wrong.

Resolve the repo root via rev-parse --show-toplevel and use it as the CWD
for both git ls-files and git diff --no-index in getUntrackedFileDiffs.

Fixes #449
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.

Bug: untracked files missing from code review when agent CWD is a subdirectory

2 participants