Open quintrino opened 1 month 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?
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?
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.
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.
I guess it can be solved by using a repo starter template. E.g. a repo that contains lot of things preconfigured. It's also useful for setting up many other things (which are often language- or framework-specific).
Many package managers have default install commnads, so to create a new TypeScript repo, I just clone the starter repo, unset the origin, then run bun install
to install the NPM deps, which automatically installs lefthook
into Git.
: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.