Closed Nagico closed 1 year ago
Hello @Nagico - thank you for raising this issue and for the PR to solve it. While I can understand the approach of allowing the user to override the encoding used, as you mention:
but the applications use uft-8 most frequently
So I wonder if a simpler change would be to enforce/assume reading in utf-8
vs. a user having to override to utf-8
if their system default is something else? E.g. just hardcode it:
with open(args.input, encoding="utf-8") as f:
message = f.read()
What do you think about this instead?
Pinging back @Nagico - see my comments above. Thoughts?
Pinging back @Nagico - see my comments above. Thoughts?
I'm sorry to be so late reply to you! I think it's a great idea to hardcode it.
Although most applications (like Pycharm) use UTF-8, the windows terminal (cmd or powershell) still uses GBK. But after my testing, hardcoding is able to submit commits within the terminal normally, possibly because Git will handle all the commit content in UTF-8.
I will close this PR and if you need any other tests, please feel free to contact me at any time!
Thanks again for this suggestion @Nagico! We just published 2.2.0
to PyPI with the encoding fix!
Release notes here: https://github.com/compilerla/conventional-pre-commit/releases/tag/v2.2.0
Problem
It's a long story. For those Chinese users developing with Windows system, the system default encoding is gbk, but the applications use uft-8 most frequently.
So when we commit with utf-8 message, the
conventional-pre-commit
will read text in gbk encoding, and raiseUnicodeDecodeError
.Solution
Add an
--encoding
argument to specify the encoding. SeeReadme.md
for more details.