Skip to content
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: not a git repository: '.git' | Inside a subdirectory (Not Monorepo) #584

Closed
Nikodermus opened this issue Sep 30, 2019 · 8 comments
Closed

Comments

@Nikodermus
Copy link

Hey guys, I'm using husky in a subfolder which is the only one with a package.json, and when I try to install husky, it gives me the following error

husky > Setting up git hooks
Command failed: git rev-parse --show-toplevel --absolute-git-dir
fatal: not a git repository (or any of the parent directories): .git
husky > Failed to install

My folder structure is

cool-project/
--.git/
--frontend/
----.huskyrc
----node_modules

I'm using 3.0.7 (just installed it).

When I run manually git rev-parse --show-toplevel --absolute-git-dir it gives me the path and the git folder

Actually the hooks do run

{
    "hooks": {
        "pre-commit": "yarn test && yarn lint-staged && yarn build && git add dist",
    }
}

but then the error

fatal: not a git repository: '.git'
husky > pre-commit hook failed (add --no-verify to bypass)
@Nikodermus Nikodermus changed the title husky > Failed to uninstall | Inside a subdirectory (Not Monorepo) fatal: not a git repository: '.git' | Inside a subdirectory (Not Monorepo) Sep 30, 2019
@typicode
Copy link
Owner

typicode commented Oct 1, 2019

Hi @Nikodermus,

That's weird, could you try re-installing and doing a git commit with HUSKY_DEBUG=1 .

It should give the current directory where git rev-parse was run and more info during the commit as well.

@Nikodermus
Copy link
Author

npm install -D husky

> husky@3.0.7 install <secret>/canon/layout_previewer/node_modules/husky
> node husky install

husky > Setting up git hooks
husky > Done

> husky@3.0.7 postinstall <secret>/canon/layout_previewer/node_modules/husky
> opencollective-postinstall || exit 0

HUSKY_DEBUG=1 git commit

husky:debug husky v3.0.7 (created at 10/1/2019, 10:55:22 AM)
husky:debug pre-commit hook started
husky:debug Current working directory is '<secret>/canon'
husky:debug Changed current working directory to '<secret>/canon/layout_previewer'
husky > pre-commit (node v10.13.0)
yarn run v1.17.3
$ echo 'no tests here.'
no tests here.
Done in 0.07s.
yarn run v1.17.3
$ lint-staged
No staged files match any of provided globs.
Done in 0.49s.
yarn run v1.17.3
$ vue-cli-service build

⠼  Building for production...

<webpack build omitted>

 DONE  Build complete. The dist directory is ready to be deployed.
 INFO  Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
                                  
Done in 11.02s.
fatal: not a git repository: '.git'
husky > pre-commit hook failed (add --no-verify to bypass)

folder structure

canon/
--.git/
--layout_previewer/
----.huskyrc
----node_modules

@typicode
Copy link
Owner

typicode commented Oct 1, 2019

Thanks, install seems to work this time.

husky:debug Changed current working directory to '/canon/layout_previewer'

Pre-commit script is running in <secret>/canon/layout_previewer, which is good. I'm not sure why git add dist fails then.

Can you try changing:

"pre-commit": "yarn test && yarn lint-staged && yarn build && git add dist",
// to
"pre-commit": "yarn test && yarn lint-staged && yarn build && pwd && echo $GIT_DIR && git add dist",

@Nikodermus
Copy link
Author

Yeah installing seems good now tho...

DONE  Build complete. The dist directory is ready to be deployed.
INFO  Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
                                  
Done in 32.97s.
<secret>/canon/layout_previewer
.git
fatal: not a git repository: '.git'
husky > pre-commit hook failed (add --no-verify to bypass)

@typicode
Copy link
Owner

typicode commented Oct 1, 2019

Can you try to unset GIT_DIR?

"pre-commit": "yarn test && yarn lint-staged && yarn build && pwd && unset GIT_DIR && echo $GIT_DIR && git add dist"

@Nikodermus
Copy link
Author

Nikodermus commented Oct 7, 2019

Thanks!, Hooks are now triggering ok, with the changes you proposed + jumping to husky@next but the commitizen hook is not working, should I now open a issue with them?`

It stops the commit due to empty message when in a regular repo starts the comitizen CLI

.huskyrc

{
    "hooks": {
        "pre-commit": "yarn test && yarn lint-staged && yarn build && unset GIT_DIR && echo $GIT_DIR",
        "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true"
    }
}

package.json

"husky": "^4.0.0-beta.2",

git commit

husky > pre-commit (node v10.13.0)
yarn run v1.17.3
$ echo 'no tests here.'
no tests here.
Done in 0.07s.
yarn run v1.17.3
$ lint-staged
  ↓ Stashing changes... [skipped]
    → No partially staged files found...
  ✔ Running tasks...
Done in 2.51s.
yarn run v1.17.3
$ vue-cli-service build

⠏  Building for production...
<webpack build ommited>                       
Done in 51.01s.

husky > prepare-commit-msg (node v10.13.0)
Command failed: git diff --no-ext-diff --name-only && git diff --no-ext-diff --cached --name-only
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>

Aborting commit due to empty commit message.

@typicode
Copy link
Owner

typicode commented Oct 8, 2019

husky > prepare-commit-msg (node v10.13.0)
Command failed: git diff --no-ext-diff --name-only && git diff --no-ext-diff --cached --name-only
Not a git repository

It seems to be the same kind of error Not a git repository. Can you check if you have a GIT_DIR env variable set in your terminal?

$ echo $GIT_DIR

@arelstone
Copy link

arelstone commented Nov 6, 2019

Adding the .huskyrc-file made the triggers run for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants