Skip to content

fix(git): include untracked files in diffs - #250

Open
404-Page-Found wants to merge 1 commit into
mainfrom
fix/198-detect-untracked-files
Open

fix(git): include untracked files in diffs#250
404-Page-Found wants to merge 1 commit into
mainfrom
fix/198-detect-untracked-files

Conversation

@404-Page-Found

Copy link
Copy Markdown
Contributor

Summary

Ensures the single-repository suggestion flow recognizes and analyzes untracked files when no staged changes exist.

Changes

  • Discover non-ignored untracked files with Git.
  • Generate no-index diffs for those files.
  • Combine them with ordinary unstaged changes.
  • Add regression coverage for an untracked-only working tree.

Testing

  • npm run build
  • node --test tests/git-diff.test.mjs

Related

Closes #198

Generate no-index diffs for untracked files during unstaged detection.

Closes #198
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@404-Page-Found, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ecfb7f90-c6b1-4043-9e98-5269280ba4f6

📥 Commits

Reviewing files that changed from the base of the PR and between 76c6e18 and 23a1bbf.

📒 Files selected for processing (2)
  • src/git/diff.ts
  • tests/git-diff.test.mjs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@404-Page-Found

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23a1bbfe08

ℹ️ 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".

Comment thread src/git/diff.ts
Comment on lines +71 to +72
.map((file) => {
const result = spawnSync('git', ['diff', '--no-index', '--', '/dev/null', file], {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid spawning one Git process per untracked file

When a working tree contains hundreds or thousands of non-ignored untracked files, this synchronous map launches a separate git diff process for every file before prompting or applying the configured diff truncation. In the inspected Linux environment, 1,000 tiny files took about 14 seconds, so an untracked generated or dependency tree can make suggest appear hung for minutes; generate the untracked patch in a bounded/batched operation or stop once the usable diff limit is reached.

Useful? React with 👍 / 👎.

Comment thread src/git/diff.ts
Comment on lines +76 to +80
if (result.error) throw result.error;
if (result.status !== 0 && result.status !== 1) {
throw new Error(result.stderr.trim() || `git diff --no-index exited with code ${result.status}`);
}
return result.stdout;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not treat every exit status 1 as a valid diff

When the untracked entry is an embedded Git repository, git ls-files --others returns a directory such as nested/, and git diff --no-index /dev/null nested/ emits Could not access 'nested/null' while also exiting with status 1. This condition accepts that access error as an ordinary difference, discards the empty stdout, and ultimately reports no changes, so the original untracked-only failure remains for repositories adding a submodule or embedded repository; distinguish an actual patch from status-1 errors or handle directory entries explicitly.

Useful? React with 👍 / 👎.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Comment thread src/git/diff.ts
.split('\0')
.filter(Boolean)
.map((file) => {
const result = spawnSync('git', ['diff', '--no-index', '--', '/dev/null', file], {
Comment thread src/git/diff.ts

export function getUnstagedDiff(): DiffResult {
const diff = execSync('git diff', {
const trackedDiff = execSync('git diff', {
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.

[Reliability] Untracked files are ignored by single-repo diff detection

2 participants