husky icon indicating copy to clipboard operation
husky copied to clipboard

Not a git repository

Open davidfurlong opened this issue 9 years ago • 5 comments

Im trying to use husky where I have this kind of directory setup:

--> Project
    --> .git
    --> SubProject
        --> package.json (husky installed)
    --> SubProject2
        --> package.json (husky installed)

and I get the error

husky > npm run -s precommit (node v8.1.4)

gitError: fatal: Not a git repository: '.git'

Is there a way to tell husky where to look for git ?

davidfurlong avatar Aug 08 '17 12:08 davidfurlong

You have to add a property gitDir to lint-staged.

"lint-staged": {
    "gitDir": "../",
    "linters": {
      "*.{js,json,jsx}": [
        "prettier --single-quote --no-semi --write",
        "git add"
      ]
    }
  }

https://github.com/okonet/lint-staged#working-from-a-subdirectory https://github.com/okonet/lint-staged/issues/170

carlosflorencio avatar Aug 09 '17 19:08 carlosflorencio

This does not work, if you want to use husky without lint-staged

MartinMuzatko avatar Nov 27 '17 15:11 MartinMuzatko

Hey, i'm trying to use Husky without lint staged as well, is there a way to add "gitDir : "../" option to package.json?

parthdesai93 avatar Apr 23 '18 19:04 parthdesai93

https://stackoverflow.com/a/11915540/436540

git --git-dir ../../.git --work-tree ../.. add path/to/my-file.json

brettstack avatar Apr 08 '19 16:04 brettstack

It seems the 'gitDir' option has been removed since v3.1 . So, the way to config 'gitDir' doesn't work any more. I solved this problem with just one command in the project root directory: npm install husky -D. You can try it.

majorcool avatar Aug 21 '19 08:08 majorcool