Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/overcommit/subprocess.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<IO>]
def assign_output_streams(process)
Expand Down