diff --git a/lib/overcommit/subprocess.rb b/lib/overcommit/subprocess.rb index 07e4fe04..3be06388 100644 --- a/lib/overcommit/subprocess.rb +++ b/lib/overcommit/subprocess.rb @@ -51,7 +51,7 @@ def spawn(args, options = {}) err.rewind out.rewind - Result.new(process.exit_code, out.read, err.read) + Result.new(process.exit_code, to_utf8(out.read), to_utf8(err.read)) end # Spawns a new process in the background using the given array of @@ -83,6 +83,23 @@ def win32_prepare_args(args) %w[cmd.exe /c] + [args.join(' ')] end + # Convert string from current locale to utf-8 + # + # When running commands under windows the command output is using + # current system locale (depends on system lanuage) not UTF-8 + # + # @param process [String] + # @return [String] + def to_utf8(string) + if Encoding.locale_charmap == 'UTF-8' + return string + end + + ec = Encoding::Converter.new(Encoding.locale_charmap, 'UTF-8') + # Convert encoding, alternatively simple: string.scrub will suffice + ec.convert(string) + end + # @param process [ChildProcess] # @return [Array] def assign_output_streams(process)