podtatranec · 2022-11-17 15:57
I would like to define some defaults for a subdirectory. Specifically override git author in all repositories under specific directory.
Ideally I'd do it using \`.dir-locals.el\` or \`dir-locals-set-class-variables\` one level above all the git repos. However it seems as soon as Emacs finds one configuration it stops looking up the directory structure. So if I have project-specific .dir-locals.el I'd need to copy my overrides from level above.
Is there a standard way to do this? Am I missing something? I didn't even notice any mention that Emacs stops looking as soon as it finds one in the docs ([https://www.gnu.org/software/emacs/manual/html\_node/emacs/Directory-Variables.html](https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html)) or anywhere else.
The closest thing I found was this [https://github.com/jinnovation/nested-dir-locals.el](https://github.com/jinnovation/nested-dir-locals.el)
ilemming · 2022-11-17 18:59
So what's wrong with nested-dir-locals.el? I haven't tried it myself, I'm just asking. Does it work?
I had a similar problem with git worktrees, and ended up creating a git hook that copies the file into the nested dir. Since it worked for me, I did not end up installing the package.
podtatranec · 2022-11-17 19:02
Unless I am doing something terribly wrong - it does not work. Only the first found .dir-locals.el file gets applied. Anything in the directory tree above it gets ignored
Edit: Oh wait, you were referring to the repo I linked. I was a bit concerned about the note at the top of the repo:
NOTE: This project is in experimental phase currently. Expect rough edges, unstable APIs, etc.
And that made me wonder if there is perhaps a cleaner way to do things
joranvar · 2022-11-17 20:43
If the only thing you want to override is some git configuration, you might want to use the `includeIf` constructions in git itself, in combination with the gitdir keyword (https://git-scm.com/docs/git-config#_conditional_includes). I used that with nix home-manager to use a different config for subdirs that are work related as opposed to personal projects.
arthurno1 · 2022-11-17 20:54
Have you seen [sidecar-locals](https://codeberg.org/ideasman42/emacs-sidecar-locals)? I am not sure if that is exactly what you ask for, but I think it solves the same problem, just differently.
podtatranec · 2022-11-17 21:32
\*that\* actually looks like something that will solve my immediate issue. Thank you very much!
I'll still look around other options to merge multiple dir-locals though for other uses in the future possibly
podtatranec · 2022-11-17 21:34
That looks like something I'm going to make use of as well. Thank you!
lafrenierejm · 2022-11-18 17:44
I’ve had very good experiences with https://github.com/fritzgrabo/cascading-dir-locals. I’ve been using it daily for over a year; haven’t noticed any issues yet.