feat: add option to exclude files globally
Summary
Add a third option to the ignore/exclude menu that writes to the user's global git excludes file. This complements the existing options:
| Option | File | Scope |
|---|---|---|
| Add to .gitignore | .gitignore |
Shared, this repo |
| Add to .git/info/exclude | .git/info/exclude |
Private, this repo |
| Add to ~/.config/git/ignore | core.excludesFile or XDG default |
Private, all repos ← NEW |
The new option:
- Respects
core.excludesFileif configured - Falls back to XDG-compliant default (
$XDG_CONFIG_HOME/git/ignoreor~/.config/git/ignore) - Displays the actual file path in the menu for transparency
Screenshot
The menu now shows three options, with the global option displaying the resolved path:
Ignore or exclude file
> Add to .gitignore
> Add to .git/info/exclude
> Add to ~/.config/git/ignore
Test plan
- [x] Tested manually with default XDG path
- [x] Verified tilde expansion works when writing
- [x] Confirmed
core.excludesFileis respected when configured
Closes #5108
I used Claude Code extensively to help me implement this--hope you don't mind. I did have it iterate a few times where it wasn't doing things in a sensible way and to make it follow the conventions of the code base.
Thanks, good work. It still took some more work to get it to a state that I'm happy with:
- I added a few cleanup commits before yours
- added a bunch of fixup commits for your commit to correct a few things; please have a look at those, they have commit messages explaining what they are about
- and I added an additional commit to add the explanatory comments that I saw in the commit message (e.g. "- Add to .gitignore (shared, this repo)"), I had assumed you would make them part of the menu, and I like that. I'm not really sure if this makes the entries too verbose, but I guess using a different color for them makes it acceptable. Alternatively, we could consider adding tooltips.
I'm happy with this in the current state, but please double-check my changes.
Thanks for taking a look and making these fixes. All seems good to me. The help text is nice, though if core.excludesFile is configured specially for the repo you're in, it won't actually be shared for all repos. But I don't expect this is a common configuration. This, along with not wanting to clutter the interface, was why I didn't try to add clarifying text myself.
though if core.excludesFile is configured specially for the repo you're in, it won't actually be shared for all repos.
Right, I forgot that core.excludesFile could also be a local config. I agree that's probably uncommon, but if we wanted to get fancy we could actually work out whether it's local or global (using git config --show-scope) and show the correct help text for either case.