-
-
Notifications
You must be signed in to change notification settings - Fork 310
fix(git): commit bodies with carriage returns are correctly split by … #1780
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
base: master
Are you sure you want to change the base?
fix(git): commit bodies with carriage returns are correctly split by … #1780
Conversation
…line This should enable us to correctly parse squashed commits made on an SCM server residing on a Windows OS.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1780 +/- ##
=======================================
Coverage 97.88% 97.88%
=======================================
Files 60 60
Lines 2606 2606
=======================================
Hits 2551 2551
Misses 55 55 ☔ View full report in Codecov by Sentry. |
bearomorphism
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall good, but I noticed a small inconsistency between the test and the implementation
tests/test_git.py
Outdated
| rev_and_commit = ( | ||
| "abc123\n" # rev | ||
| "def456 ghi789\n" # parents | ||
| "feat: add new feature\n" # title | ||
| "John Doe\n" # author | ||
| "[email protected]\n" # author_email |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qq: is it possible that rev, parents, etc. end with "\r\n"?
If not, could you add comments here about why there will be possibly both CRLF and LF in the `rev_and_commit string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! While I cannot say definitively, my SCM server only appears to be attaching CRLFs on the body not the metadata. The metadata still appears to be using normal LFs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer body_newline.join( original lines ov rev_and_commit ).
The inconsistency between this test and the implementation may cause confusion to future contributors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can add test cases when LF and CRLF are mixed in message.
Also, it would be better to add context on why we are covering those test cases. For example:
# This should enable us to correctly parse squashed commits made on an SCM server residing on a Windows OS.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my latest commit matches your request? I made the test consistent with the implementation. Let me know if I am wrong and misinterpreted you.
| rev, parents, title, author, author_email, *body_list = ( | ||
| rev_and_commit.splitlines() | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we split rev, parents, title, author, author_email with "\n" only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in my above comment I think that would technically work. My preference is we stick with my provided implementation (everything uses splitlines())
- it still handles
\n - is easier to read
- splitting the output by line seems to be the intended goal of that line
Furthermore, I think there is minimal risk of it causing a bug since the parts that theoretically don't need the extra delimiter logic are all computer generated. That said, I'd be happy to piece out the logic and only apply the splitlines() call to the body if that's what you want.
bearomorphism
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@woile @Lee-W @noirbizarre could you also take a look?
... line
This should enable us to correctly parse squashed commits made on an SCM server residing on a Windows OS.
Description
Checklist
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsDocumentation Changes
uv run poe doclocally to ensure the documentation pages renders correctlyExpected Behavior
Commit bodies that use carriage returns for line breaks will now be successfully split when getting processed. In particular this enables commitizen to process squash commits made on an SCM server that is hosted by a Windows OS.
Steps to Test This Pull Request
\r\n):cz changelog --dry-runand verify that only thefeatandfixentries are included\n)cz changelog --dry-runand verify that only thefeatandfixentries are includedAdditional Context