Skip to content

Commit ed9ffca

Browse files
authored
Merge pull request #916 from moritzschepp/ec-encoding
fix encoding error when running a merge tool
2 parents b2d98fe + 2e2b684 commit ed9ffca

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/thor/shell/basic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def answer_match(possibilities, answer, case_insensitive)
367367

368368
def merge(destination, content) #:nodoc:
369369
require "tempfile"
370-
Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination)) do |temp|
370+
Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination), binmode: true) do |temp|
371371
temp.write content
372372
temp.rewind
373373
system(*merge_tool, temp.path, destination)

spec/actions/file_manipulation_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ def file
104104
end
105105
end
106106

107+
it "launches the merge tool when there is a collision and source has utf-8 characters" do
108+
previous_internal = Encoding.default_internal
109+
110+
silence_warnings do
111+
Encoding.default_internal = Encoding::UTF_8
112+
end
113+
114+
destination = File.join(destination_root, "encoding_with_utf8.thor")
115+
FileUtils.mkdir_p(destination_root)
116+
117+
File.write(destination, "blabla")
118+
119+
allow(runner.shell).to receive(:merge_tool).and_return("meld")
120+
expect(Thor::LineEditor).to receive(:readline).and_return("m")
121+
expect(runner.shell).to receive(:system).with("meld", /encoding_with_utf8.thor/, /encoding_with_utf8.thor/)
122+
action :copy_file, "encoding_with_utf8.thor"
123+
ensure
124+
silence_warnings do
125+
Encoding.default_internal = previous_internal
126+
end
127+
end
128+
107129
it "logs status" do
108130
expect(action(:copy_file, "command.thor")).to eq(" create command.thor\n")
109131
end

0 commit comments

Comments
 (0)