overcommit icon indicating copy to clipboard operation
overcommit copied to clipboard

Invoke Bundler Context: `File.read()` doesn't use the right encoding

Open samyouel opened this issue 10 months ago • 1 comments

Hey there.

For some reason, when using Overcommit together with the Git Graph Extension for VSCode, any time a hook runs and it checks on the bundler context (most templates do that), the action fails with this error message: git/hooks/post-checkout:30:in '<main>': invalid byte sequence in US-ASCII (ArgumentError)

It seems that the code there at that line tries to read the file from filesystem but doesn't take into account the encoding of the file.

# Check if Overcommit should invoke a Bundler context for loading gems
File.read('.overcommit.yml') =~ /gemfile: (?:false|['"]?(.*)['"]?)/

simply adding the encoding explicitly to the File.read() method seems to solve the issue.

I obviously can't do that on my end by overwriting the files, as they are being regenerated all the time.

Would you mind if I create a PR to add the encoding to all templates or does this collide with other things I can't overlook?

# Check if Overcommit should invoke a Bundler context for loading gems
File.read('.overcommit.yml', encoding: 'UTF-8') =~ /gemfile: (?:false|['"]?(.*)['"]?)/

Thanks so much, it's driving me crazy lately since I can't use my lovely GUI assistant for git anymore..

samyouel avatar Mar 18 '25 11:03 samyouel