Skip to content

fix(git): prevent app freeze on repos with large untracked directories#1361

Merged
jonathanlab merged 2 commits intoPostHog:mainfrom
CaioDGallo:fix/freezing-editor
Mar 31, 2026
Merged

fix(git): prevent app freeze on repos with large untracked directories#1361
jonathanlab merged 2 commits intoPostHog:mainfrom
CaioDGallo:fix/freezing-editor

Conversation

@CaioDGallo
Copy link
Copy Markdown
Contributor

@CaioDGallo CaioDGallo commented Mar 30, 2026

Problem

The app freezes (macOS beach ball) when selecting a repository that contains a large untracked directory (e.g. .pnpm-store/ not in .gitignore). The main process becomes unresponsive because multiple git queries run git status which enumerates every file inside untracked directories.

Changes

simple-git's .status() hardcodes a -u flag, which is shorthand for --untracked-files=all. This makes git recursively list every file inside untracked directories, a .pnpm-store/ can contain tens of thousands of files, all piped through stdout and parsed synchronously by simple-git.

From simple-git's source (src/lib/tasks/status.ts)[https://github.com/steveukx/git-js/blob/main/simple-git/src/lib/tasks/status.ts]:

function statusTask(customArgs) {
  const commands = ["status", "--porcelain", "-b", "-u", "--null", ...customArgs];
  // ...
}

Custom args are appended after -u, so passing --untracked-files=normal or --untracked-files=no overrides it (last flag wins in git).

What changed in packages/git/src/queries.ts:

  1. All git.status() calls now pass an explicit --untracked-files mode:

    • --untracked-files=normal for functions that read not_added — collapses untracked directories into a single entry instead of listing every file inside them (matches default git status CLI behavior)
    • --untracked-files=no for getAheadBehind and getSyncStatus which only read branch/ahead/behind info and don't need untracked data at all
  2. getChangedFilesDetailed: capped countFileLines to the first 10,000 untracked files. This function sequentially reads every untracked file to count lines, which can cause a secondary bottleneck after the status enumeration.

No behavior change: --untracked-files=normal still reports untracked content, just grouped by directory instead of expanded per-file. isClean(), not_added, modified, staged, deleted, ahead, behind all remain correct. Functions using --untracked-files=no never accessed untracked fields to begin with.

How did you test this?

Manually selected a repository containing a large untracked .pnpm-store/ directory via the folder picker. Before the fix, the app froze with a beach ball. After the fix, the repo loads without freezing.

@CaioDGallo CaioDGallo force-pushed the fix/freezing-editor branch from 882677e to 3d5aff5 Compare March 30, 2026 14:17
@CaioDGallo CaioDGallo force-pushed the fix/freezing-editor branch from 3d5aff5 to ec50cb8 Compare March 31, 2026 11:14
@jonathanlab jonathanlab merged commit 4af35f8 into PostHog:main Mar 31, 2026
15 checks passed
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.

2 participants