evilmartians / lefthook

Fast and powerful Git hooks manager for any type of projects.
MIT License
4.78k stars 211 forks source link

GIT_TEMPLATE_DIR Compatibility #815

Open quintrino opened 1 week ago

quintrino commented 1 week ago

:zap: Summary

Git provides the ability to set a standard template for your git setup using the GIT_TEMPLATE_DIR, Lefthook should be able to point, or generate or store a template for git to use via the GIT_TEMPLATE_DIR ENV.

Value

Rather than having to remember to manually run lefthook add every time you clone a repo you're looking to add functionality on, this would allow it to happen automatically.

Behavior and configuration changes

a command such as lefthook template would point to a directory that could be saved via export GIT_TEMPLATE_DIR=$(lefthook template) or maybe it could create one at $XDG_CONFIG_HOME/lefthook/template or something.

mrexox commented 4 days ago

Hey @quintrino! Thank you for submitting a feature request. Could you describe in more details how this would differ from having a lefthook.yml in a git template dir? I just think it's way more simpler to configure lefthook in a git's template directory and use this when git init a new project, than having to maintain a special template with lefthook. WDYT?

quintrino commented 4 days ago

So I guess my desire is to have lefthook be added automatically on all projects I git init or git clone.

my limited understanding of lefthook is that currently you have to add lefthook manually to every git repo using lefthook install

Other githook managers do this by setting a git template (and therefore git hook template) using the GIT_TEMPLATE_DIR env, is there another way to have lefthook automatically applied to all repos?

mrexox commented 3 days ago

I see, the problem is that git init copies only the content of a .git/ folder in a git template dir, so lefthook config doesn't get copied.

Could you share the info about other hook managers? I am curious, maybe I could get inspired and implement something similar in lefthook.

Also there's a postinstall script in lefthook NPM package which runs lefthook install when you install the NPM dependencies. So this problem with installing hooks on git clone is solved for JS projects.

quintrino commented 3 days ago

So overcommit handles it here. https://github.com/sds/overcommit?tab=readme-ov-file#automatically-install-overcommit-hooks I can, if I need to, just create a blank .git and install lefthook, store that in my dotfiles somewhere and set it as the default git template, but that's assuming that the git hooks will complain if you attempt to run a git command without a lefthook.yml installed in the repo.