12
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

huskyのpre-commitフックがSourceTreeでコミットするときに動かない

Last updated at Posted at 2021-01-11

問題

huskyのpre-commitフックを設定したが、コマンドラインで git commit した時は動くのに、SourceTreeでコミットする時はフックされてない、という事象に遭遇した。

エラーログ

スクリーンショット 2021-01-11 14.54.05.png
SourceTreeの設定を「すべてのコンソール出力を常に表示する」に変えて、コミットした時のログを確認してみると...

Can't find npx in PATH: /Applications/Sourcetree.app/Contents/Resources/git_local/libexec/git-core:/Applications/Sourcetree.app/Contents/Resources/bin:/Applications/Sourcetree.app/Contents/Resources/git_local/bin:/Applications/Sourcetree.app/Contents/Resources/git_local/gitflow:/Applications/Sourcetree.app/Contents/Resources/git_local/git-lfs:/usr/bin:/bin:/usr/sbin:/sbin Skipping pre-commit hook

:thinking:

対処

https://github.com/typicode/husky/issues/639#issuecomment-573281096
npxの場所にPATHを通せば良いっぽい。

the file must be created in your home folder (~/.huskyrc) not at your project root.

.huskyrc はprojectのrootではなく、 ~/ に置く点に注意。

というわけで
私のエラーログの場合

Can't find npx in PATH

とのことなので

$ which npx
/Users/miyuki/.nodebrew/current/bin/npx

ここにあるようなので

~/.huskyrc には

PATH="/Users/miyuki/.nodebrew/current/bin:$PATH"

と記述して、解決した :tada:

参考

12
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?