sds / overcommit

A fully configurable and extendable Git hook manager
MIT License
3.92k stars 281 forks source link

Fix encoding of process output under windows #766

Closed rymut closed 3 years ago

rymut commented 3 years ago

Output of commands under windows is not UTF-8 by default, this can lead to "invalid byte sequence in UTF-8" error on symlink check

sds commented 3 years ago

Thanks for the pull request, @rymut.

This currently breaks a large number of tests when running on Linux (which is what the vast majority of Overcommit users use).

      Failure/Error: ec = Encoding::Converter.new(Encoding.locale_charmap, 'UTF-8')
      Encoding::ConverterNotFoundError:                                                                                                                                                 code converter not found (UTF-8 to UTF-8)

If the issue is only reproducible when checking for bad symlinks, can we isolate this change to just change the encoding on the problematic line? Specifically:

https://github.com/sds/overcommit/blob/8622f9e83fcd2b1e1bc1d19494d4c25843dbea5c/lib/overcommit/utils/file_utils.rb#L27

rymut commented 3 years ago

Thanks @sds: in my case only calling win32_symlink is reproducible - but the underlying problem will still be present. My current commit should fix the issue with braking tests under linux - if the problems with the tests will be still persisting then I will isolate a change to win32_simlink.