-
Notifications
You must be signed in to change notification settings - Fork 32
fix(git): include untracked files in diffs #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,14 +55,43 @@ | |
| }; | ||
| } | ||
|
|
||
| function getUntrackedDiff(): string { | ||
| const files = spawnSync('git', ['ls-files', '--others', '--exclude-standard', '-z'], { | ||
| encoding: 'utf-8', | ||
| maxBuffer: GIT_DIFF_MAX_BUFFER, | ||
| }); | ||
| if (files.error) throw files.error; | ||
| if (files.status !== 0) { | ||
| throw new Error(files.stderr.trim() || `git ls-files exited with code ${files.status}`); | ||
| } | ||
|
|
||
| return files.stdout | ||
| .split('\0') | ||
| .filter(Boolean) | ||
| .map((file) => { | ||
| const result = spawnSync('git', ['diff', '--no-index', '--', '/dev/null', file], { | ||
|
Check warning on line 72 in src/git/diff.ts
|
||
|
|
||
| encoding: 'utf-8', | ||
| maxBuffer: GIT_DIFF_MAX_BUFFER, | ||
| }); | ||
| 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; | ||
|
Comment on lines
+76
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the untracked entry is an embedded Git repository, Useful? React with 👍 / 👎. |
||
| }) | ||
| .filter(Boolean) | ||
| .join('\n'); | ||
| } | ||
|
|
||
| export function getUnstagedDiff(): DiffResult { | ||
| const diff = execSync('git diff', { | ||
| const trackedDiff = execSync('git diff', { | ||
|
Check warning on line 87 in src/git/diff.ts
|
||
|
|
||
| encoding: 'utf-8', | ||
| maxBuffer: GIT_DIFF_MAX_BUFFER, | ||
| }); | ||
| const diff = [trackedDiff, getUntrackedDiff()].filter(Boolean).join('\n').trim(); | ||
| return { | ||
| diff: diff.trim(), | ||
| hasChanges: diff.trim().length > 0, | ||
| diff, | ||
| hasChanges: diff.length > 0, | ||
| staged: false, | ||
| }; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a working tree contains hundreds or thousands of non-ignored untracked files, this synchronous map launches a separate
git diffprocess 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 makesuggestappear hung for minutes; generate the untracked patch in a bounded/batched operation or stop once the usable diff limit is reached.Useful? React with 👍 / 👎.