Skip to content

Conversation

@JoeyKL
Copy link

@JoeyKL JoeyKL commented Dec 10, 2025

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.excludesFile if configured
  • Falls back to XDG-compliant default ($XDG_CONFIG_HOME/git/ignore or ~/.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

  • Tested manually with default XDG path
  • Verified tilde expansion works when writing
  • Confirmed core.excludesFile is respected when configured

Closes #5108

@JoeyKL
Copy link
Author

JoeyKL commented Dec 10, 2025

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.

stefanhaller and others added 9 commits December 14, 2025 19:15
The action for ignoring a file says "Ignore or exclude file", but the action for
excluding a file says "Exclude file"; this asymmetry doesn't make sense. We
should either add a more specific "Ignore file" string for ignoring a file, or
use the more generic one for excluding too. I decided to do the latter, since
it's simpler, and I find it good enough.
Now that all callers pass the same one, we can hard-code it in the function.
Add a third option to the ignore/exclude menu that writes to the user's
global git excludes file. This complements the existing options:

- Add to .gitignore (shared, this repo)
- Add to .git/info/exclude (private, this repo)
- Add to ~/.config/git/ignore (private, all repos) <- NEW

The new option respects core.excludesFile if configured, otherwise falls
back to the XDG-compliant default location ($XDG_CONFIG_HOME/git/ignore
or ~/.config/git/ignore).

The menu displays the actual file path that will be modified, making the
behavior predictable and transparent.

Closes jesseduffield#5108
Return error if we can't resolve the user's home directory. Without this it
would create a file with the literal name `~/...` in the current directory,
which is never what we want.
Use fmt.Sprintf instead of template syntax to substitute the path name. For
texts with only a single placeholder this is good enough, and it's a bit
simpler.
Was showing the wrong error when trying to ignore the .gitignore file.
@stefanhaller stefanhaller added the enhancement New feature or request label Dec 14, 2025
@stefanhaller stefanhaller force-pushed the add-global-excludes-option branch from 7006600 to 76d994c Compare December 14, 2025 18:26
@stefanhaller
Copy link
Collaborator

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.

@JoeyKL
Copy link
Author

JoeyKL commented Dec 16, 2025

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.

@stefanhaller
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclude option ignores core.excludesFile configuration

2 participants