Skip to content

Commit 4af35f8

Browse files
authored
fix(git): prevent app freeze on repos with large untracked directories (#1361)
1 parent 3651ff3 commit 4af35f8

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

packages/git/src/queries.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export async function getStatus(
143143
return manager.executeRead(
144144
baseDir,
145145
async (git) => {
146-
const status = await git.status();
146+
const status = await git.status(["--untracked-files=normal"]);
147147
return {
148148
isClean: status.isClean(),
149149
staged: status.staged,
@@ -164,7 +164,7 @@ export async function hasChanges(
164164
return manager.executeRead(
165165
baseDir,
166166
async (git) => {
167-
const status = await git.status();
167+
const status = await git.status(["--untracked-files=normal"]);
168168
return !status.isClean();
169169
},
170170
{ signal: options?.abortSignal },
@@ -189,7 +189,7 @@ export async function getAheadBehind(
189189
return null;
190190
}
191191

192-
const status = await git.status();
192+
const status = await git.status(["--untracked-files=no"]);
193193
return {
194194
aheadOfRemote: status.ahead,
195195
behind: status.behind,
@@ -339,7 +339,7 @@ export async function getChangedFiles(
339339
} catch {}
340340
}
341341

342-
const status = await git.status();
342+
const status = await git.status(["--untracked-files=normal"]);
343343
for (const file of [
344344
...status.modified,
345345
...status.created,
@@ -430,7 +430,7 @@ export async function getChangedFilesDetailed(
430430
try {
431431
const [diffSummary, status] = await Promise.all([
432432
git.diffSummary(["-M", "HEAD"]),
433-
git.status(),
433+
git.status(["--untracked-files=normal"]),
434434
]);
435435

436436
const seenPaths = new Set<string>();
@@ -468,7 +468,10 @@ export async function getChangedFilesDetailed(
468468
if (hasFrom) seenPaths.add(file.from as string);
469469
}
470470

471+
const MAX_UNTRACKED_FILES = 10_000;
472+
let untrackedProcessed = 0;
471473
for (const file of status.not_added) {
474+
if (untrackedProcessed >= MAX_UNTRACKED_FILES) break;
472475
if (!seenPaths.has(file)) {
473476
if (
474477
excludePatterns &&
@@ -483,6 +486,7 @@ export async function getChangedFilesDetailed(
483486
linesAdded: lineCount,
484487
linesRemoved: 0,
485488
});
489+
untrackedProcessed++;
486490
}
487491
}
488492

@@ -664,7 +668,7 @@ export async function getSyncStatus(
664668
baseDir,
665669
async (git) => {
666670
try {
667-
const status = await git.status();
671+
const status = await git.status(["--untracked-files=no"]);
668672
const isDetached = status.detached || status.current === "HEAD";
669673
const currentBranch = isDetached ? null : status.current || null;
670674

0 commit comments

Comments
 (0)