Include untracked files in working-tree diff reviews#123
Include untracked files in working-tree diff reviews#123benvinegar merged 2 commits intomodem-dev:mainfrom
Conversation
Greptile SummaryThis PR makes untracked working-tree files visible in Confidence Score: 4/5PR is safe to merge for the primary macOS/Linux audience; one untested edge case (0-byte untracked files) should be verified before broad rollout. The implementation is architecturally clean and well-tested across the main scenarios (default inclusion, opt-out, pathspecs, parser-sensitive filenames, subdirectory launches, agent sidecars, watch signatures). Prior thread concerns about misleading variable names, redundant
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[loadGitChangeset] --> B[resolveGitRepoRoot]
A --> C[runGitText — git diff tracked]
C --> D[normalizePatchChangeset]
D --> E[trackedChangeset / trackedFiles]
A --> F{shouldIncludeUntrackedFiles?}
F -- "staged / range / excludeUntracked=true" --> G[return trackedChangeset]
F -- "working tree, default" --> H[listGitUntrackedFiles\ngit status --porcelain=v1 -z]
H --> I{untrackedFiles.length > 0?}
I -- "no" --> G
I -- "yes" --> J[buildUntrackedDiffFile x N]
J --> K[runGitUntrackedFileDiffText\ngit diff --no-index /dev/null file]
K --> L[normalizeUntrackedPatchHeaders\nescape parser-sensitive paths]
L --> M[parseUntrackedPatchFile\noverride name = filePath]
M --> N[buildDiffFile]
N --> O[merge trackedFiles + untrackedFiles]
O --> P[orderDiffFiles — agent context ordering]
P --> Q[Changeset returned]
subgraph Watch Mode
W1[computeWatchSignature] --> W2[gitWorkingTreeWatchSignature]
W2 --> W3[runGitText — git diff tracked patch]
W2 --> W4[resolveGitRepoRoot]
W2 --> W5[listGitUntrackedFiles]
W5 --> W6[statSignature per untracked file\nsize + mtime + inode only]
W3 & W6 --> W7[joined signature string]
end
Reviews (2): Last reviewed commit: "fix untracked diff watch and parser edge..." | Re-trigger Greptile |
src/core/git.ts
Outdated
| return trackedPatch; | ||
| } | ||
|
|
||
| const normalizedRepoRoot = repoRoot ?? resolveGitRepoRoot(input, { cwd, gitExecutable }); |
There was a problem hiding this comment.
Misleading variable name
normalizedRepoRoot
The variable is named normalizedRepoRoot, but at this point the path has NOT been run through realpathSync — it is either the raw value passed in by the caller (e.g. the git rev-parse --show-toplevel output from loaders.ts) or whatever resolveGitRepoRoot returns. The actual symlink resolution only happens inside excludedUntrackedPaths. Using this as the cwd for runGitCommand (line 395) works in practice because the OS resolves symlinks transparently, but the naming implies a normalization step that hasn't occurred here and could be confusing to future readers.
Consider renaming to resolvedRepoRoot to better reflect what it is at this stage:
| const normalizedRepoRoot = repoRoot ?? resolveGitRepoRoot(input, { cwd, gitExecutable }); | |
| const resolvedRepoRoot = repoRoot ?? resolveGitRepoRoot(input, { cwd, gitExecutable }); |
(and updating the two subsequent uses on lines 383 and 395)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
099829e to
2d46246
Compare
|
A quick note on scope/design: I looked at broader cleanup options for working-tree diff loading, but kept this PR focused on the user-visible behavior change plus the correctness/perf fixes needed to make it safe by default. Specifically, this PR does three things together:
I intentionally did not fold in a broader refactor (for example, a dedicated working-tree adapter module) because that felt like extra blast radius for a feature fix. Also, re: If this lands and we want follow-up cleanup later, the most obvious candidates seem to be:
|
|
Sounds good, thanks for the added explanation. I think I'll merge and just start experimenting/testing during regular usage, see where we wind up. |
https://pi.dev/session/#4cb769589e158d30950cb75ef33ae439
Summary
hunk diffreviewsexclude_untracked/--exclude-untrackedas the opt-out--agent-contextsidecars visible when they are also untracked files in the repoCloses #109.
Testing
bun test test/cli.test.ts test/config.test.ts test/loaders.test.ts test/watch.test.ts test/git.test.tsbun run typecheckbun run src/main.tsx -- diff --help