question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: fatal: Not a git repository

See original GitHub issue

When trying to use lint-staged and husky in a project where the actual node.js project is a child directory of the git repo (as shown below):

project
  └─ node-app
       └─ package.json

I get the following error:

:; git commit                                                                                                                  

> husky - npm run -s precommit

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

    at ChildProcess.<anonymous> (/home/tri/project/node-app/node_modules/staged-git-files/index.js:85:19)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:886:16)
    at Socket.<anonymous> (internal/child_process.js:342:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:501:12)
/home/tri/project/node-app/node_modules/lint-staged/src/index.js:44
            files.forEach((file) => {
                 ^

TypeError: Cannot read property 'forEach' of undefined
    at sgf (/home/tri/project/node-app/node_modules/lint-staged/src/index.js:44:18)
    at /home/tri/project/node-app/node_modules/staged-git-files/index.js:13:13
    at /home/tri/project/node-app/node_modules/staged-git-files/index.js:38:13
    at ChildProcess.<anonymous> (/home/tri/project/node-app/node_modules/staged-git-files/index.js:88:9)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:886:16)
    at Socket.<anonymous> (internal/child_process.js:342:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)

When running npm run precommit, I see a lot of these errors

:; npm run precommit

> node-app@1.0.0 precommit /home/tri/project/node-app
> lint-staged

 ❯ Running tasks for *.js
   ✖ prettier --single-quote --no-bracket-spacing --jsx-bracket-same-line --write
     → /home/tri/prooject/node-app/node-app/Link.react.js
     git add
🚫 prettier --single-quote --no-bracket-spacing --jsx-bracket-same-line --write  found some errors. Please fix them and try committing again.
Unable to read file:
Error: ENOENT: no such file or directory, open ''
Unable to read file: /home/tri/project/node-app/node-app/test/nightwatch/user.js
Error: ENOENT: no such file or directory, open '/home/tri/project/node-app/node-app/test/nightwatch/user.js'
Unable to read file: /home/tri/project/node-app/node-app/test/nightwatch/universalSearch.js

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
okonetcommented, Jun 9, 2017

That’s why I encourage people to read the README when something isn’t working 😃

3reactions
MJ111commented, Jun 9, 2017

@maxime1992 You have to insert gitDir as property of lint-staged. like this.

{
  "lint-staged": {
    "gitDir": "../",
    "*.ts": [
      "yarn run prettier:precommit",
      "git add"
    ]
  },
  ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Git error - Fatal: Not a git repository and how to fix it | Datree.io
This error means you attempted to run a Git command, but weren't inside a Git repository. Make sure you've: ... Usually, this is...
Read more >
Solving “Fatal: Not A Git Repository” (Or Any Of The Parent ...
This error means that you have some files that have been edited but not committed, and by checking out another branch, you'll overwrite...
Read more >
Not a git repository" when attempting to remote add a Git repo
You'll get this error if you try to use a Git command when your current working directory is not within ...
Read more >
How to Fix the “fatal: not a git repository” Error - ContainIQ
In short, the fatal: not a git repository error indicates that your current working directory isn't tracked by Git. If you find yourself...
Read more >
How To Fix "fatal: not a git repository" in Git? - Tim Mousk
Here are a few reasons why this error happens: · 1. Ensure you are inside the correct directory that contains the Git repository....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found