-
-
Notifications
You must be signed in to change notification settings - Fork 999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fatal when trying to call git from hook #98
Comments
hi @WiseBird, its hard for me to get the problem. can you create a github repo with minimal reproducible test case? |
@iamstarkov here it is And here you can see a workaround. |
I'm seeing this too. If I call a bash script in a subdirectory below the package, and that script calls git status, it doesn't work despite the working directory being correct and sibling to |
Ah, in my case it was because I was setting |
im having this problem as well |
I'm seeing this too. I'm in a monorepo where my Update: Looks like my issue was actually in the task I was running. Upgrading |
I am running into this issue as well. This happens because the node app is a child directory of the git repository. My guess is that it is caused by |
I had the similar problem (lint-staged to be run on a sub-directory within the main project). Following issue and its solution , resolved it. |
Like others I am seeing the variable setting |
I used |
This did:
|
Just for documentation purposes, I want to share my experience of this same issue while building a docker image for my project. Here's the setup of my directory Root Dir/
with server/ and client/ with their own package.json. I have husky installed in server and client folder respectively and got the fatal error while I was building the image. I took inspiration from @egucciar and changed my precommit script to do This is how my precommit command looks: |
Looks like the issue(?) is in git itself. Pretty easy to reproduce: mkdir test-precommit
cd test-precommit
git init
mkdir dir
echo "echo GIT_DIR=\$GIT_DIR" >> .git/hooks/pre-commit
echo "cd dir" >> .git/hooks/pre-commit
echo "git status" >> .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
git commit -m test Output:
|
Adding |
Shouldn't the workaround for this issue just be documented and then closed? I don't see how this can be fixed in a non-breaking way. If Husky would manipulate GIT_DIR to an absolute path, it would probably break quite a few scripts that relied on its relative nature. And if Husky won't change it, while it also needs to set the current working directory to the sub-dir for Node to work, I can't see this being fixed from Husky alone. That means either
|
Example of dealing with this issue: fatso83/check-commit-msg@9385d85
|
I'm using
Project structure
if I run
if I run
if I run just command in |
Turns out just adjusting fatso83/check-commit-msg@79c82b9 The tool is a commit hook that is run by Husky's as the |
For me, an upgrade of git to version 2.23.0 (from 2.17.1) solved this wrong GIT_DIR problem - did not tried versions between. The issue seems to be really a problem in older git versions as @testerez suggested. |
@xanonid Could you try running the little script by @testerez and dump its output? It would be interesting to see what the differences are between 2.17 and 2.23. If anything, I would assume that they have changed In any case, relying on your users to have the latest Git version is a bit haphazard, so I'd suggest having the script find the right .git root itself, as suggested above. |
After update git from 2.17.1 to 2.26.2(last version) this problem "GIT_DIR" was fixed for me. |
in my case I have a monorepo with python for the api and javascript/react for the frontend (very similar structure to the other comments here). I am/was using pre-commit for git hooks on the python side, and I was trying to use husky for the javascript side (I realize that pre-commit could do the javascript side too, but I like husky auto-installing with the rest). Anyways I found that my husky hooks are getting removed when I install the python pre-commit library. It outputs the following
which I believe would mess up any scripts husky has going that would refer to the original .git/hooks/pre-commit Does anyone run husky and pre-commit together in harmony? |
sigh... I think I found the "solution" on stack overflow. This seems to push you more to using pre-commit, which isn't bad but definitely not what I was hoping. |
@marcstreeter We have a monorepo with a mix of Go, Python, Java and Javascript. We have actually made a |
@fatso83 that sounds awesome, could you point me in any direction for how to do that? I didn't know husky could drive commit hooks for other programming languages |
Remember that any NPM script is just a command line that gets executed. There is nothing that says it has to be JavaScript. For instance, it is quite common to invoke |
Closing as v5 doesn't have this issue. Thanks for the workarounds/solutions regarding v4 :) |
I am getting
fatal: Not a git repository: '.git'
when trying to call git from hook:"precommit": "git status"
. I think the reason is that my package.json isn't located in root folder and hook is run from there.The only way I found is to prepend each git call with
cd ../../../
.The text was updated successfully, but these errors were encountered: