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

Custom hook folder #839

Open
cgaube opened this issue Oct 11, 2024 · 2 comments
Open

Custom hook folder #839

cgaube opened this issue Oct 11, 2024 · 2 comments
Labels
feature request A new lefthook feature description

Comments

@cgaube
Copy link

cgaube commented Oct 11, 2024

⚡ Summary

Right now lefthook automatically installs github hooks files in the git rev-parse --git-path hooks folder
This folder should be configurable.

Value

Every systems is configured differently,
A common scenario is to setup a global hook folder that contains all the github hooks that will delegate to other scripts stored in different directories.
A use case would be to have script executed on all your repositories installed on your computer but also add custom hooks at each repos level

e.g
~/.gitconfig

[core]
	hooksPath = ~/hooks

~/.hooks/pre-commit hooks that execute global scripts + delegate to individual repo pre-commit hooks if needed

~/repo1/.hooks/pre-commit
~/repo2/.hooks/pre-commit

Behavior and configuration changes

Add a new configuration at the root level

hooks_folder: '.hooks/'

use that directory when installing and synchronizing hooks scripts

e.g if you are in
~/repo1. lefthook install will add git hooks scripts to ~/repo1/.hooks

If hooks_folder is not provided fallback to git rev-parse --git-path hooks

@cgaube cgaube added the feature request A new lefthook feature description label Oct 11, 2024
@mrexox
Copy link
Member

mrexox commented Oct 14, 2024

Hey! Could you please provide more details about the suggested setting?

Git uses only one dir for hooks, so if you have ~/hooks configured and run git commit - a ~/hooks/pre-commit will be triggered. If this is your manual hook, then what's the purpose of having different hooks dir for lefthook? It looks like lefthook hooks won't be executed in this scenario.

And if you have lefthook hook installed in ~/hooks/pre-commit, then you'll have repo-specific commands anyway, because settings are parsed from your repo's lefthook.yml, they are not global.

@cgaube
Copy link
Author

cgaube commented Oct 14, 2024

Hello, thank you for your reply

Git uses only one dir for hooks, so if you have ~/hooks configured and run git commit - a ~/hooks/pre-commit will be triggered. If this is your manual hook, then what's the purpose of having different hooks dir for lefthook? It looks like lefthook hooks won't be executed in this scenario.

Here is the scenario

The global pre-commit actually looks into the current repo local .hooks/pre-commit and execute that script if it exits

So if i do a git commit from the repoA folder for example
~/hooks pre-commit is executed, looks for repoA/.hooks/pre-commit and execute that script

What i m trying to do is install lefthook just for repoA but I dont want other repos to use it
So i want to configure repoA/lefthook.yml to install the lefthook precommit script automatically in repoA/.hooks/pre-commit

That way I can still use global hooks that will be executed on ALL repos precommit and also execute lefthook on repoA

This is why i would like that have this option that way lefthook never override my global/pre-commit script.

Hope this make sense

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

2 participants