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

Relative path in a repo subdirectory not found when using hash symmetric difference #522

Closed
3 tasks done
dshemetov opened this issue Oct 27, 2023 · 7 comments · Fixed by #584
Closed
3 tasks done
Assignees
Labels
bug Something isn't working
Milestone

Comments

@dshemetov
Copy link
Collaborator

dshemetov commented Oct 27, 2023

Describe the bug
Relative path in a repo subdirectory not found when using --revision=<hash>...<hash> but not when using --revision=origin/main....

To Reproduce
Steps to reproduce the behavior:

  1. Clone this repository: https://github.com/dshemetov/darker-test
  2. See the README.md in the repo for instructions

Expected behavior
The behavior between these should be consistent, I believe.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Python version 3.8, 3.10 (doesn't really matter)
  • Darker version 1.7.2
  • Black version 23.10.1

Steps before ready to implement:

  • Reproduce
  • Understand the reason
  • Design a fix and update the description
@akaihola
Copy link
Owner

Hi @dshemetov,

Could you check whether your description is correct ("not found" in both cases)?

Relative path in a repo subdirectory not found when using --revision=... but not when using --revision=origin/main....

@akaihola akaihola self-assigned this Feb 23, 2024
@akaihola akaihola added this to the Darker 1.8.1 milestone Feb 23, 2024
@dshemetov
Copy link
Collaborator Author

Hi @akaihola, thanks for looking into this. It'll take me a little time to remember the context here, but I'll try and verify soon.

@akaihola
Copy link
Owner

akaihola commented Apr 13, 2024

I just managed to reproduce this issue using your repository:

[/tmp/darker-test]$ darker --check -r a994113...origin/dev subdir
[/tmp/darker-test]$ darker --check -r a994113...origin/dev subdir/subsubdir
[/tmp/darker-test]$ cd subdir
[/tmp/darker-test/subdir]$ darker --check -r a994113...origin/dev subsubdir
argument PATH: Error: Path(s) 'subsubdir' do not exist in origin/dev

@akaihola
Copy link
Owner

To reproduce and understand this on the Git level:

[/tmp/darker-test]$ git cat-file -p origin/dev:subdir
100644 blob 6f1c2a548639ac49507a525b63597938878b2e6d	Makefile
100644 blob 921b47f1f8168d376ad41a120c1d79a4ab8fe5fa	requirements.txt
040000 tree adc767417cd500fe67e0add3ca9a71c670ca4b29	subsubdir

[/tmp/darker-test]$ git cat-file -p origin/dev:subdir/subsubdir
100644 blob 14c0d0b5e618b2921fceaee13f4965974d3f137a	file.py

[/tmp/darker-test]$ cd subdir

[/tmp/darker-test/subdir]$ git cat-file -p origin/dev:subsubdir
fatal: path 'subsubdir' does not exist in 'origin/dev'

[/tmp/darker/test/subdir]$ git cat-file -p origin/dev:subdir/subsubdir
100644 blob 14c0d0b5e618b2921fceaee13f4965974d3f137a	file.py

[/tmp/darker/test/subdir]$ git cat-file -p origin/dev:./subsubdir
100644 blob 14c0d0b5e618b2921fceaee13f4965974d3f137a	file.py

[/tmp/darker-test/subdir]$ cd subsubdir

[/tmp/darker-test/subdir/subsubdir]$ git cat-file -p origin/dev:./file.py
a = ["really", "really", "really","really",     "really", "really", "really", "really","really",  "really", "long", "line"] # add comment

So git cat-file seems to treat paths relative to repository root and not the current working directory – unless the path begins with ./

The fix then is to either prepend ./ to paths in the git cat-file call, or to always include all path elements starting from the repository root.

@akaihola
Copy link
Owner

@dshemetov would you like to accept the invite to become a collaborator on the Darker repository, and review the fix in PR #584?

@dshemetov
Copy link
Collaborator Author

Hey @akaihola, thanks for addressing this! I see you've already received a review and merged the fix, I will double check and confirm that the issue I had is resolved 👍

@akaihola
Copy link
Owner

thanks for addressing this! I see you've already received a review and merged the fix, I will double check and confirm that the issue I had is resolved

Glad @dshemetov if it helps! I hope my fix works. Path handling is a bit messy in Darker, could be simplified in the future...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

2 participants