sds / overcommit

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

Invalid byte sequence in UTF-8 on Win10 when checking symlink's #765

Closed rymut closed 3 years ago

rymut commented 3 years ago

System: Windows 10 Enterprise - with Polish as a default language result of chcp command is "Active code page: 852"

Error:

Check for broken symlinks............................[BrokenSymlinks] FAILED
Hook raised unexpected error
invalid byte sequence in UTF-8
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/utils/file_utils.rb:71:in `win32_symlink?'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/utils/file_utils.rb:27:in `symlink?'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/utils.rb:271:in `broken_symlink?'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook/pre_commit/broken_symlinks.rb:8:in `block in run'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook/pre_commit/broken_symlinks.rb:8:in `select'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook/pre_commit/broken_symlinks.rb:8:in `run'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook/base.rb:47:in `block in run_and_transform'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/utils.rb:260:in `with_environment'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook/base.rb:47:in `run_and_transform'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook_runner.rb:161:in `run_hook'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook_runner.rb:97:in `block in consume'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook_runner.rb:94:in `loop'
C:/tools/Ruby30-x64/lib/ruby/gems/3.0.0/gems/overcommit-0.58.0/lib/overcommit/hook_runner.rb:94:in `consume'

How to reproduce the error:

mkdir demo 
cd demo 
git init 
overcommit --install
echo void main() {} > main.c
git add main.c
overcommit --run post-commit

As per https://github.com/sds/overcommit/issues/717#issuecomment-639261852 dump of raw bytes from dir_output:

[32, 86, 111, 108, 117, 109, 101, 32, 105, 110, 32, 100, 114, 105, 118, 101, 32, 67, 32, 105, 115, 32, 87, 105, 110, 100, 111, 119, 115, 10, 32, 86, 111, 108, 117, 109, 101, 32, 83, 101, 114, 105, 97, 108, 32, 78, 117, 109, 98, 101, 114, 32, 105, 115, 32, 50, 67, 56, 49, 45, 55, 52, 68, 53, 10, 10, 32, 68, 105, 114, 101, 99, 116, 111, 114, 121, 32, 111, 102, 32, 67, 58, 92, 85, 115, 101, 114, 115, 92, 114, 121, 109, 117, 116, 98, 92, 80, 114, 111, 106, 101, 99, 116, 115, 92, 100, 101, 109, 111, 10, 10, 50, 57, 46, 49, 48, 46, 50, 48, 50, 49, 32, 32, 48, 57, 58, 51, 57, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 49, 32, 109, 97, 105, 110, 46, 99, 112, 112, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 32, 70, 105, 108, 101, 40, 115, 41, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 49, 32, 98, 121, 116, 101, 115, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 48, 32, 68, 105, 114, 40, 115, 41, 32, 32, 55, 53, 48, 255, 51, 49, 56, 255, 49, 52, 49, 255, 52, 52, 48, 32, 98, 121, 116, 101, 115, 32, 102, 114, 101, 101, 10]
rymut commented 3 years ago

Pull request to fix the issue https://github.com/sds/overcommit/pull/766

sds commented 3 years ago

Fixed by #766.