7

i tried to run this command but it always show this error, i can't fix it with anyway. Help me, please!

(venv)<...>pre-commit install

[ERROR] Cowardly refusing to install hooks with core.hooksPath set.

hint: git config --unset-all core.hooksPath

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Hữu Tuân
  • 81
  • 1
  • 3
  • welcome to SO! Do you happen to have core.hooksPath configured? Check with `git config -l` – eftshift0 Jun 01 '21 at 17:15
  • https://github.com/pre-commit/pre-commit/issues?q=is%3Aissue+Cowardly+refusing+to+install+hooks+with+core.hooksPath+set – phd Jun 01 '21 at 18:07

3 Answers3

10
  1. Run:

    git config --unset-all core.hooksPath
    
  2. If the global core.hooksPath is not empty, run:

    git config --global --unset-all core.hooksPath
    

    But of course, it's global so be careful.

    Why pre-commit is nonfunctional with global hooks? see issue

Noam Nol
  • 570
  • 4
  • 11
2

You are getting the above error because of setting up a global hook path.

It can be resolved in below two ways: -

  1. Unset the global hook path as below: -

    git config --unset core.hooksPath
    
  2. Set local hooks path as below: -

    git config --local core.hooksPath .git/hooks
    

There is a very interesting conversation on this topic, I will highly recommend going through it once:-

issue Cowardly refusing to install hooks with core.hooksPath set

Please let me know in the comments if this resolves your problem. I am super curious about it.

Pratap Alok Raj
  • 1,098
  • 10
  • 19
0

I also hit this problem, and I'm definitely not convinced by the author's answer in #1198. Requiring to edit a personal file/setting to be able to use a software does not seems acceptable to be me.

Anyway, the workaround I found is to prevent pre-commit to use global config during install phase, where you probably have setup your core.hookspath. As there is no option, we can trick git by telling it to use /dev/null as global config dir, only during install time:

$ XDG_CONFIG_HOME=/dev/null pre-commit install
pre-commit installed at .git/hooks/pre-commit

I'm not sure to fully understand the implication of doing so, but I'm aware that my global git hooks won't run anymore when pre-commit is enabled on a project :)

mrjk
  • 1
  • 1