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
Git directory is not correctly resolved if GIT_WORK_TREE is set to relative path #886
Comments
Thanks for the issue! Would you like to submit a PR as well? Otherwise, I can open one during the weekend or so. |
Maybe we could put it here: |
I guess that would work but wouldn't it be more suitable here? https://github.com/okonet/lint-staged/blob/master/lib/resolveGitRepo.js#L37 |
You are correct! Maybe all those could be collected in one place. |
I created a pull request with the fix: #887. |
🎉 This issue has been resolved in version 10.2.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Resolving the git directory will fail if the environment variable
GIT_WORK_TREE
is set to a relative path and lint-staged is run from a subdirectory of a Git repository.This is because while
GIT_DIR
is unset inresolveGitRepo.js
,GIT_WORK_TREE
is not.GIT_WORK_TREE
can be used to set the worktree directory for a Git repo.GIT_DIR
specifies only the .git directory.git rev-parse --show-toplevel
will return the Git worktree directory. If it is set to a relative path, it won't work when git commands are called from a subdirectory, as.
will then translate to the subdirectory.In
resolveGitRepo.js
, you need to adddelete process.env.GIT_WORK_TREE
and then everything works as expected.Why set GIT_WORK_TREE to a relative path?
lint-staged is usually called from hook-scripts and if you call
git --work-tree=/ABSOLUTE/PATH/TO/REPO --git-dir=/ABSOLUTE/PATH/TO/REPO/.git commit
from the worktree root, Git will setGIT_WORK_TREE
to.
.GIT_DIR
will remain an absolute path.Steps to reproduce
test-repo
my_app
), where your JS app lives and which contains package.json with lint-staged configexport GIT_WORK_TREE=.
Debug Logs
The Git repo resides at
/Users/USER/Development/test-repo/
. lint-staged resolves it to the subdirectory/Users/USER/Development/test-repo/my_app
.expand to view
Environment
lint-staged
: 10.2.9The text was updated successfully, but these errors were encountered: