Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIT_TEMPLATE_DIR Compatibility #815

Open
quintrino opened this issue Sep 13, 2024 · 5 comments
Open

GIT_TEMPLATE_DIR Compatibility #815

quintrino opened this issue Sep 13, 2024 · 5 comments
Labels
feature request A new lefthook feature description

Comments

@quintrino
Copy link

⚡ 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.

@quintrino quintrino added the feature request A new lefthook feature description label Sep 13, 2024
@mrexox
Copy link
Member

mrexox commented Sep 16, 2024

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
Copy link
Author

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
Copy link
Member

mrexox commented Sep 17, 2024

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
Copy link
Author

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.

@notramo
Copy link

notramo commented Nov 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new lefthook feature description
Projects
None yet
Development

No branches or pull requests

3 participants