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

fix: Git directory is not resolved if GIT_WORK_TREE is set to relative path #887

Merged

Conversation

alexrinass
Copy link
Contributor

@alexrinass alexrinass commented Jun 12, 2020

Resolving the git directory failed 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 (e.g. multi-package repos).

GIT_WORK_TREE can be used to set the worktree directory for a Git repo. GIT_DIR specifies only the .git directory path. 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 the relative path will fail to resolve correctly.

While GIT_DIR is unset in resolveGitRepo.js, GIT_WORK_TREE was not. Unsetting GIT_WORK_TREE in the same place fixes the issue.

Resolves #886

…to relative path

Resolving the git directory failed 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 (e.g. multi-package repos).

`GIT_WORK_TREE` can be used to set the worktree directory for a Git repo. `GIT_DIR` specifies only the `.git` directory path. `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 the relative path will fail to resolve correctly.

While `GIT_DIR` is unset in `resolveGitRepo.js`, `GIT_WORK_TREE` was not. Unsetting `GIT_WORK_TREE` in the same place fixes the issue.
@alexrinass
Copy link
Contributor Author

alexrinass commented Jun 12, 2020

I am not familiar with the project or the JS tooling and I couldn't find any contribution guidelines. So I hope it's ok that way. Feel free to propose corrections.

iiroj
iiroj approved these changes Jun 12, 2020
Copy link
Collaborator

@iiroj iiroj left a comment

Looks good, thanks for the PR and the additional test!

@codecov
Copy link

codecov bot commented Jun 12, 2020

Codecov Report

Merging #887 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #887   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines          597       599    +2     
  Branches       142       142           
=========================================
+ Hits           597       599    +2     
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 0daae61...5e8bb4c. Read the comment docs.

@iiroj iiroj merged commit a1904ec into okonet:master Jun 12, 2020
3 checks passed
@github-actions
Copy link

github-actions bot commented Jun 12, 2020

🎉 This PR is included in version 10.2.10 🎉

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git directory is not correctly resolved if GIT_WORK_TREE is set to relative path
2 participants