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

Apply specific hook to all repositories #832

Open
0xjac opened this issue Oct 3, 2024 · 2 comments
Open

Apply specific hook to all repositories #832

0xjac opened this issue Oct 3, 2024 · 2 comments
Labels
feature request A new lefthook feature description

Comments

@0xjac
Copy link

0xjac commented Oct 3, 2024

⚡ Summary

I am not sure lefthook or even git hooks are the right tools but I have the following problem:

I have a set of private generic hooks (think commitlint, spell check, etc.) which I would like to run on every git repo and:

  1. I want to avoid manually configuring a configuration file in every repo.
  2. I want to keep those hooks private.
  3. I want to use them in repos where hooks are not "officially" used or other hooks are used (manual ones, using other frameworks like pre-commit.com).

    Note: One issue here is that I cannot use a lefthook-local.yaml without a leftook.yaml present which is a problem in some repos.

Value

It allows to automate part of my workflow and ensures I don't forget to run some checks.

Behavior and configuration changes

This might be related to #29 (symlinks won't work in my case). But a couple options are:

  1. Lefthook should run with just a lefthook-local.yaml without a lefthook.yaml being present.
    This would allow running lefthook privately without a shared config (kind of how git hooks originally work)
  2. To build on top of the proposal abvve, Lefthook could read a configuration file located in the GIT_DIR (default: .git). This would allow syncing a base configuration to all repos with git init and a git template.
    • This configuration file should not take precedence over the lefthook{,-local}.yaml files as it only holds a base config.
    • Lefthook should as well run with just that file if present.
  3. More closely related, but lefthook could on top of (or instead of) the above proposals read a global configuration (think $XDG_CONFIG_HOME/lefthook.yaml) which would act as a base configuration and could be overwritten by any configuration file within the repository.
@0xjac 0xjac added the feature request A new lefthook feature description label Oct 3, 2024
@mrexox
Copy link
Member

mrexox commented Oct 3, 2024

@0xjac , let me suggest you an option for that.

  1. Create a useful-hooks.yml file e.g. in your home directory (/home/user/useful-hooks.yml) and describe all the hooks you want there.
  2. Add the .lefthook.yml file to every repo you want useful hooks to work with the following content:
extends:
  - /home/user/useful-hooks.yml
  1. Add .lefthook.yml to ~/.gitignore, so you don't have to commit it.

Lefthook supports different config names, so you can use some of them as "local" and add to global gitignore. You can also use extends to configure this only once. So, the only thing you'll have to do is to copy the .lefthook.yml to your repo and run lefthook install.

Does this approach work for you?

@0xjac
Copy link
Author

0xjac commented Oct 8, 2024

@mrexox Thanks that is a start, but it has a couple issues. Namely:

  1. I have to manually add a .lefthook.yml in a lot of repository and remember to do so each time I create a new repo.
  2. I have to deal with potential conflicts in repos which have a .lefthook.yml and at the very least force add it if it is being used. And if the repo uses a lefthook.yaml then my hooks or the repo hooks will be ignored.

I'm happy to use such a setup but it should:

  1. Provide a way to read a lefthook-local.yaml file, ideally in the $GIT_DIR so I can sync my git repos and keep their tree clean .
  2. Be able to read that lefthook-local.yaml file implicitly and without an explicit lefthook.yaml

But I'm not sure if such an implementation is easier than a simple implicit lookup to extend a lefthook file (whether it is present or not) with a global config?

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