question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use commitlint in a prepush hook

See original GitHub issue

Hello, 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
tqn-treezorcommented, Dec 29, 2021

For those who will come later, my solution was the following:

commitCount=$(git rev-list HEAD...develop --count)
npx -- commitlint --from=HEAD~($commitCount) --to=HEAD

I basically get a count of commits ahead between HEAD and develop, 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

2reactions
drazikcommented, Jun 4, 2018

That’s exactly what I needed. I just had to invert to and from, 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 !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found