fix: use Git for untracked file diffs - #41
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:86efd86918
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ['diff', ...DIFF_FLAGS, '--no-index', '--', '/dev/null', file], | ||
| { encoding: 'utf-8', maxBuffer: 50 * 1024 * 1024 }, |
There was a problem hiding this comment.
Generate untracked diffs from the repository root
When diffx is launched from a subdirectory, git ls-files returns paths relative to that directory (for example, sub-new rather than sub/sub-new), and this command preserves that shortened path in the patch headers. The server later resolves the parsed path against getRepoRoot() in getFileContent, so untracked image previews return 404 or display a different root-level file, and saved comments reference the wrong repository path. Normalize these paths and run the diff from the repository root.
Useful? React with 👍 / 👎.
| // for this use case. | ||
| const result = spawnSync( | ||
| 'git', | ||
| ['diff', ...DIFF_FLAGS, '--no-index', '--', '/dev/null', file], |
There was a problem hiding this comment.
Force Git's default prefixes on generated patches
When the user has diff.noprefix=true, this produces headers such as diff --git file file and +++ file; the server's parseFilePaths and parseBinaryFiles require a/ and b/, so binary untracked files disappear from the UI and other per-file metadata is lost. This is a regression from the handcrafted untracked patches, which always emitted those prefixes. Git documents --default-prefix as using the default a/ and b/ prefixes, so include it here to make the output independent of user configuration.
Useful? React with 👍 / 👎.
Unstaged files is shown with "binary files are not tracked" so we cannot see the changes.