Skip to content

feat: respect .gitignore in tree sidebar - #5136

Open
rkristelijn wants to merge 4 commits into
marktext:developfrom
rkristelijn:feat/gitignore-tree-filter
Open

feat: respect .gitignore in tree sidebar#5136
rkristelijn wants to merge 4 commits into
marktext:developfrom
rkristelijn:feat/gitignore-tree-filter

Conversation

@rkristelijn

Copy link
Copy Markdown

Closes #5135

Summary

When opening a folder that contains a .gitignore, the tree sidebar now respects those patterns and hides ignored files/directories (e.g. .git/, build artifacts, .amazonq/, etc.).

Changes

  • New file packages/desktop/src/main/filesystem/gitignore.ts: Helper that loads and parses .gitignore using the ignore package (spec-compliant gitignore matching including negation, nested patterns, etc.)
  • packages/desktop/src/main/filesystem/watcher.ts: Integrates the gitignore filter into chokidar's ignored callback, applied after existing treePathExcludePatterns
  • packages/desktop/package.json: Added ignore@7.0.4 dependency

Behavior

  • If .gitignore exists at the opened folder root → patterns are applied
  • If no .gitignore exists → no change in behavior
  • .git/ is always excluded when a .gitignore is present
  • Additive to existing treePathExcludePatterns preference (both filters apply)

Testing

  • Verified typecheck passes (pnpm typecheck)
  • Tested on Linux Mint 22.3 with Node v24.15.0

- Add pre-flight check in postinstall.ts for libx11-dev, libxkbfile-dev,
  libsecret-1-dev, pkg-config on Linux (dpkg-based distros)
- Clear error message with exact apt-get command on failure
- Add Makefile for dev workflow shortcuts (deps, install, dev, build)
- Add gitignore.ts helper that parses .gitignore at the opened folder root
- Integrate with chokidar watcher's ignored callback
- Uses the 'ignore' npm package for correct gitignore pattern matching
- .git directory is always excluded when .gitignore is present
- Additive to existing treePathExcludePatterns preference
Resolve rootPath and validate that the constructed .gitignore path
stays within the root directory. Addresses SonarQube blocker:
'Change this code to not construct the path from user-controlled data.'
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.

feat: respect .gitignore in tree sidebar

1 participant