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

Add missing cwd option when calling execGit function #1075

Conversation

lucasenicora
Copy link
Contributor

I've found this issue when executing lintStaged from node v16. My current setup is as follows:

I have 2 different folders:

  • /path/to/project/git => root folder of the git repository
  • /path/to/project => root folder for the project, which is NOT a git repository

When executing lintStaged, the setup is as follows:

  • Node JS process is executed with process.cwd() == /path/to/project
  • Inside the JS file executed by Node, I call lintStaged({ cwd: '/path/to/project/git'})
  • I get the Current directory is not a git directory! error

After debugging the code, the issue seems to be that resolveGitRepo() is calling execGit() without passing the cwd parameter. Without this parameter, execGit() is forced to fall back to process.cwd(), which in my case is NOT a proper git directory.

@iiroj
Copy link
Member

iiroj commented Dec 23, 2021

Thanks for the PR @lucasenicora! I assume after making this change locally, everything is working as expected for you?

@codecov
Copy link

codecov bot commented Dec 23, 2021

Codecov Report

Merging #1075 (0ca02c9) into master (96a1a29) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1075   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines          593       593           
  Branches       157       157           
=========================================
  Hits           593       593           
Impacted Files Coverage Δ
lib/resolveGitRepo.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 96a1a29...0ca02c9. Read the comment docs.

@iiroj iiroj merged commit a230b03 into lint-staged:master Dec 24, 2021
@github-actions
Copy link
Contributor

🎉 This PR is included in version 12.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants