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

If cwd is not same as gitDir #856

Closed
wants to merge 3 commits into from
Closed

If cwd is not same as gitDir #856

wants to merge 3 commits into from

Conversation

ram3shyadav
Copy link

No description provided.

@iiroj
Copy link
Member

iiroj commented Apr 29, 2020

When using the relative option, files are relative to the cwd, which might be different from the git dir. Is this what you mean?

I think git commands can now also always run in the cwd, which would fix the issue.

@ram3shyadav
Copy link
Author

ram3shyadav commented Apr 29, 2020

When using the relative option, files are relative to the cwd, which might be different from the git dir. Is this what you mean?

I think git commands can now also always run in the cwd, which would fix the issue.

yes,

and its not fixed.

If my package.json file is not in root/cwd thn git add is failing after linters

@iiroj
Copy link
Member

iiroj commented Apr 29, 2020

But can you confirm this only happens when using the relative option? This would then be a new bug after passing only matched files to the git add command.

A straightforward solution would be to resolve the paths before adding them.

I can create a fix tomorrow.

@codecov
Copy link

codecov bot commented Apr 29, 2020

Codecov Report

Merging #856 into master will decrease coverage by 0.49%.
The diff coverage is 57.14%.

Impacted file tree graph

@@             Coverage Diff             @@
##            master     #856      +/-   ##
===========================================
- Coverage   100.00%   99.50%   -0.50%     
===========================================
  Files           17       17              
  Lines          596      602       +6     
  Branches       142      143       +1     
===========================================
+ Hits           596      599       +3     
- Misses           0        3       +3     
Impacted Files Coverage Δ
lib/gitWorkflow.js 98.00% <57.14%> (-2.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 885a644...1e1536a. Read the comment docs.

@iiroj
Copy link
Member

iiroj commented Apr 29, 2020

The correct fix is to resolve to cwd instead of gitDir here: https://github.com/okonet/lint-staged/blob/master/lib/gitWorkflow.js#L253

The working dir can be set to this.cwd in the constructor options.

@ram3shyadav
Copy link
Author

The correct fix is to resolve to cwd instead of gitDir here: https://github.com/okonet/lint-staged/blob/master/lib/gitWorkflow.js#L253

The working dir can be set to this.cwd in the constructor options.

To reproduce issue

  • create a git repo
  • add package.json in a sub folder
  • npm install husky
  • npm install lint-staged
  • use lint-staged entry from package.json with --relative flag in pre-commit config

cwd will be directory of package.json
gitDir will be root folder

git add try to add file from path relative to package.json folder. it should be from git root

App
    .git
    ClientApp
        package.json

@iiroj
Copy link
Member

iiroj commented Apr 29, 2020

I'll close this PR and opened #857. I'll also add a test case according to your instructions.

@iiroj iiroj closed this Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants