Use commitlint in a prepush hook
See original GitHub issueHello, and thanks for this module 👍
I was just wondering if it’s possible to use it in a prepush hook ?
Actually, while working I sometimes write commit message that are not well formed, but then reorganize all this to clean things up. So I would rather run commitlint
on all commit messages that are going to be pushed, instead of on each commit.
Is it possible to do that ? I saw that $GIT_PARAMS
don’t contain commit messages, just remote and branch names, so I don’t see a way to achieve this, but I wonder if you have one.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Setup pre-commit hooks with husky v6 + commitlint + lint-staged
pre-push ; pre-rebase; post-update. Pre-commit hooks are actions that run after staging your changes and running git commit and before ...
Read more >Git Hooks - Git SCM
The pre-push hook runs during git push , after the remote refs have been updated but before any objects have been transferred. It...
Read more >What is the correct way to add commitlint to the commit-msg ...
I have an angular project where I want to enforce conventional commits. I have not been able to successfully had the right hook...
Read more >How to run ESLint using a pre-commit hook - Level Up Coding
Update: There is a better way to add pre-commit hooks to your project. Checkout husky. You can follow the below-given tutorial to learn...
Read more >Using Git hooks for easier development (2020)
Pre-push. Git hooks are set up in the .git folder in a Git project. ... It is used to evaluate the commit message...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For those who will come later, my solution was the following:
I basically get a count of commits ahead between
HEAD
anddevelop
, and then apply commitlint for this number of commits. It can be put in one line:npx -- commitlint --from=HEAD~$(git rev-list HEAD...develop --count)--to=HEAD
That’s exactly what I needed. I just had to invert
to
andfrom
, resulting in this :commitlint --from=origin/my-branch --to=HEAD
And I added a git command to get the remote branch dynamically :
commitlint --from=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}) --to=HEAD
Now I just need to write a more robust script that doesn’t fail if there is no remote branch.
Thank you @marionebl !