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

Add "no_skip" whitelist/additive option for hooks and commands #477

Closed
istrasci opened this issue May 4, 2023 · 4 comments · Fixed by #478
Closed

Add "no_skip" whitelist/additive option for hooks and commands #477

istrasci opened this issue May 4, 2023 · 4 comments · Fixed by #478
Labels
feature request A new lefthook feature description

Comments

@istrasci
Copy link

istrasci commented May 4, 2023

⚡ Summary

Create a no_skip ("enforce"?) whitelist/additive option for hooks and commands.

Value

Currently there is only a skip option for hooks and commands which is blacklist/subtractive behaviour. I often have commands that I want to execute only on particular branches. Since there is only a subtractive option, I have to implement additive behaviour myself by writing a custom script that checks the current git branch, and executes the command if I'm on one of the allowed branches. I'd rather not have to do that.

Common use case would be that I want to execute my test suite in a pre-commit hook only if I'm on master or hotfix/* branches. I cannot blacklist every other possible branch name, so I must create the workaround myself.

Behavior and configuration changes

Add a no_skip (or another word, but I can't find a good antonym for "skip") option that implements additive behaviour for hooks and commands.

@istrasci istrasci added the feature request A new lefthook feature description label May 4, 2023
@mrexox
Copy link
Member

mrexox commented May 5, 2023

Hey! Thank you for the feature request. I like the word only, does it make sense to you?

So, you suggest to add something like this, right?

# lefthook.yml

pre-commit:
  only:
    - ref: master
    - ref: hotfix/*
  commands:
    test:
      only: 
        - ref: hotfix/*
      run: make test
    lint:
      run: make lint

I think this option should accept all possible skip values, but apply them the opposite way.

If you confirm, I will start working on this feature.

@istrasci
Copy link
Author

istrasci commented May 5, 2023

@mrexox Yes, your understanding is correct. Accept all possible skip values, but apply them the opposite way. I think the word only is a good choice 👍.

Thank you for your consideration!

@mrexox mrexox mentioned this issue May 10, 2023
4 tasks
@mrexox
Copy link
Member

mrexox commented May 11, 2023

Hey! The feature has just been released with v1.3.13, check it out! Docs: https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md#only

@istrasci
Copy link
Author

Awesome, thank you!

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

Successfully merging a pull request may close this issue.

2 participants