19

I have configured husky in my project. It is running the pre-commit hook with "lint-staged" to use "prettier" to format the code before each commit. The configuration works fine when I use the terminal to invoke the git commit.

However, if I commit the files using vs code source control panel to commit, it just commits without running the pre-commit hook. I am using windows 10. pre-commit file:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx "lint-staged"

package.json for "lint-staged"

"lint-staged":{
    "*.{js,json,css,md}": [
        "prettier --write"
    ]
}

vscode source control panel

vscode source control panel

How do I solve this to invoke a pre-commit hook each time when git commit is called though it is from vscode?

umitu
  • 2,423
  • 1
  • 10
  • 28
dnaveen
  • 221
  • 3
  • 8
  • 3
    Just started using Husky and this was the first thing I noticed. When run from the command line, it runs no problem, using the git section of the sidebar in VS Code does not... would love to know an answer to this too.... – Hazy Jun 28 '22 at 03:13
  • 3
    @Hazy did you ever get a solution to this? I am having the same issue yesterday it even worked in vscode, woke up today and now it's not happy, still works in command line as well. – Liam Sep 29 '22 at 09:48
  • 1
    This is not related to git per se. Its VSCode [mis]behaving. – Vijay Raghavan Aravamudhan Mar 14 '23 at 13:47

3 Answers3

0

Can you show the logs from vscode? To know how to do that you can look up what others did on this similar issue.

I think that if you modify the husky command and make it look like this:

"husky": {
  "hooks": {
    "pre-commit": "npx lint-staged"
  }
}

It will work.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34617542) – ryanwebjackson Jul 05 '23 at 21:01
0

It works fine on the latest version of vsCode(version 1.81.0).

dnaveen
  • 221
  • 3
  • 8
0

Solution that helped me on ubuntu 23.04: uninstall vscode and install it via downloading .deb package from their site. Originally I installed it via ubuntu software