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

Apply Format in Place when Revisions Are Provided and End Revision is HEAD #778

Open
haohu321 opened this issue Dec 13, 2024 · 2 comments
Open
Assignees
Labels
question Further information is requested

Comments

@haohu321
Copy link

Is your feature request related to a problem? Please describe.
After the user commit changes, it will be impossible for him to apply the formatting using darker. A work around would be reset the commit and then recommit. Or try generate a diff patch and git apply (tried this but doesn't work).

Describe the solution you'd like
Ideally if the end revision is HEAD, we should still allow darker to apply the file changes. Then the user could easily
darker --revision=HEAD^..HEAD .

Describe alternatives you've considered

  1. Git reset, run darker and then re-commit. This would be very tedious if the user has a long history of local commit unless the user squash, reset, run darker and then recommit.
  2. Let darker generate a diff then try to apply as git patch. The output from darker can't be applied directly by git apply.

Additional context
Add any other context or screenshots about the feature request here.

@akaihola akaihola added the question Further information is requested label Dec 15, 2024
@akaihola
Copy link
Owner

Thanks @haohu321 for the report!

Could you clarify what you mean by "impossible to apply formatting using Darker"?

Let's try to create a practical use case, maybe that will help me understand:

  • git checkout main
  • make some code modifications
  • git add .
  • git commit -m "Code modifications which don't comply with Black"
  • darker -r main..HEAD
  • git diff <- this should now show Darker's reformatting to the modified lines

At this point, you could either

  • add reformatting as a separate commit: git add . ; git commit -m "Darker reformatting", or
  • amend to the last commit: git commit --amend -m "Code modifications and Darker reformatting"

Could you point out which part of this workflow is failing for you?

@haohu321
Copy link
Author

haohu321 commented Dec 16, 2024

Hi @akaihola , thanks for taking a look. This is what's broken for me:


$ darker --revision=HEAD^..HEAD .
argument -r/--revision: Can't write reformatted files for revision 'HEAD'. Either --diff or --check must be used.

$ darker -r HEAD^..HEAD .
argument -r/--revision: Can't write reformatted files for revision 'HEAD'. Either --diff or --check must be used.

darker forces me to supply --diff or --check Is this a potential bug?

Also a minor issue: After pip install darker==2.1.1, darker --version always shows 1.2.1 I guess the version needs to be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Development

No branches or pull requests

2 participants