Skip to content

fix: respect .git/info/exclude in a linked git worktree and a submodule - #1462

Merged
dsherret merged 2 commits into
mainfrom
fix-info-exclude-linked-worktree
Nov 16, 2026
Merged

dsherret merged 2 commits into
mainfrom
fix-info-exclude-linked-worktree

Conversation

@dsherret

Copy link
Copy Markdown
Member

Closes #1459

In a worktree created with git worktree add, .git is a file with the path of the worktree's git directory (<main>/.git/worktrees/<name>), and that directory's commondir file has the path of the git directory it shares with the main worktree. git reads info/exclude from that shared directory, but dprint only looked in <root>/.git/info/exclude, so it formatted files that git ignores.

Changes

  • When .git is a file, its gitdir: <path> and the git directory's commondir are now followed the same way git does it (relative and absolute paths, only trailing \r/\n trimmed, nothing read from a file over 1 MB) and info/exclude is read from there.
  • A submodule also has a .git file, but its git directory has no commondir, so it now gets the info/exclude of its own git directory (<super>/.git/modules/<name>), which matches git.
  • A .git file that doesn't lead anywhere still makes the directory a repository root with no exclude file, as before.
  • The language server's change detection now watches the resolved exclude file and notices when the .git file changes. The .git and commondir files aren't read again on each lookup unless the .git file changed or the repository has no info/exclude.

The cost for a normal run is one extra stat of .git per repository root found during a traversal.

Testing

  • New unit tests for linked worktrees (absolute and relative gitdir, absolute commondir, Windows line endings), submodules, .git files that don't lead to an exclude file, and change detection in a linked worktree.
  • New traversal test mirroring the issue.
  • Ran the steps from the issue: excluded-dir/probe.md is listed by 0.64.3 and isn't listed with this change, in both the linked and main worktrees.

…dule

In a worktree created with `git worktree add`, `.git` is a file with the
path of the worktree's git directory, whose `commondir` file has the path
of the git directory it shares with the main worktree. git reads
`info/exclude` from there, but dprint only looked in `<root>/.git`, so it
formatted files that git ignores.

A `.git` file is now followed the way git does it. This also picks up the
`info/exclude` of a submodule, which has a `.git` file without a
`commondir`.

Closes #1459
# Conflicts:
#	crates/dprint/src/utils/gitignore.rs
@dsherret
dsherret merged commit 211cd3a into main Nov 16, 2026
4 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.

.git/info/exclude is not respected in a linked git worktree

1 participant