Skip to content

fix(git): handle nested worktrees properly - #2015

Merged
pynappo merged 7 commits into
nvim-neo-tree:mainfrom
pynappo:fix/git-nested-worktree
Apr 17, 2026
Merged

pynappo merged 7 commits into
nvim-neo-tree:mainfrom
pynappo:fix/git-nested-worktree

Conversation

@pynappo

@pynappo pynappo commented Apr 16, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2010

Also various refactors of the codebase

@pynappo
pynappo force-pushed the fix/git-nested-worktree branch from 487f530 to 88f394f Compare April 16, 2026 07:50
@pynappo
pynappo merged commit 4d0828d into nvim-neo-tree:main Apr 17, 2026
16 checks passed
@nianiam nianiam mentioned this pull request Apr 24, 2026
3 tasks done
pynappo added a commit to stupidbullet/neo-tree.nvim that referenced this pull request May 20, 2026
@vsajko vsajko mentioned this pull request Aug 3, 2026
3 tasks done
pynappo pushed a commit to ardaaltinors/neo-tree.nvim that referenced this pull request Aug 18, 2026
Nested repository discovery in `on_directory_loaded` lived inside the
`if state.use_libuv_file_watcher then` branch, so a folder holding a `.git`
entry was only registered as its own worktree when the file watcher was
enabled. `use_libuv_file_watcher` defaults to `false`, so under the default
config a nested repository was never discovered: every path below it resolved
against the outer worktree, and its files were reported as ignored whenever the
outer `.gitignore` excludes the directory. This completes nvim-neo-tree#2015 for the default
config.

Registration now sits outside the watcher branch and is gated on
`enable_git_status`. Two details keep it from adding work for anyone else:

- The tree root is skipped, because the source already runs a status for it in
  `filesystem.navigate`. Without this it would be statused twice on every fresh
  scan, which is measurable on large repositories. The guard compares
  `folder.path` rather than `target_path` so that a symlinked tree root is
  still recognised as the root.
- The child has to be named exactly `.git` rather than merely end in `.git`, so
  directories such as `mirror.git` no longer trigger a `git rev-parse` on every
  scan. Those never become registered worktrees, so the existing lookup guard
  cannot suppress the repeat.

Because the block now precedes the watcher's early return for git-internal
paths, discovery also runs for folders inside a `.git` directory. That is
inert: such folders do not contain a `.git` child.
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.

BUG: Nested git worktrees are incorrectly marked as gitignored because mark_gitignored short-circuits on the first ancestor in M.worktrees

1 participant