evilmartians / lefthook

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

Custom hook folder #839

Open cgaube opened 6 days ago

cgaube commented 6 days ago

:zap: 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

mrexox commented 3 days ago

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 commented 3 days ago

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