Skip to content

Commit 1b95317

Browse files
committed
support THOR_MERGE values with arguments
- Split THOR_MERGE with Shellwords and pass argv to system - Adds spec covering THOR_MERGE="nvim -d" Fixes #909
1 parent c049fb6 commit 1b95317

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/thor/shell/basic.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,15 @@ def merge(destination, content) #:nodoc:
372372
Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination)) do |temp|
373373
temp.write content
374374
temp.rewind
375-
system(merge_tool, temp.path, destination)
375+
system(*merge_tool, temp.path, destination)
376376
end
377377
end
378378

379379
def merge_tool #:nodoc:
380-
@merge_tool ||= ENV["THOR_MERGE"] || "git difftool --no-index"
380+
@merge_tool ||= begin
381+
require "shellwords"
382+
Shellwords.split(ENV["THOR_MERGE"] || "git difftool --no-index")
383+
end
381384
end
382385
end
383386
end

spec/shell/basic_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,19 @@ def #456 Lanç...
564564
capture(:stdout) { shell.file_collision("foo") {} }
565565
end
566566

567+
it "invokes the merge tool with arguments when THOR_MERGE contains them" do
568+
allow(ENV).to receive(:[]).with("THOR_MERGE").and_return("nvim -d")
569+
expect(Thor::LineEditor).to receive(:readline).and_return("m")
570+
expect(shell).to receive(:system).with("nvim", "-d", /foo/, "foo")
571+
capture(:stdout) { shell.file_collision("foo") {} }
572+
end
573+
574+
it "invokes the merge tool with arguments when there is no THOR_MERGE" do
575+
expect(Thor::LineEditor).to receive(:readline).and_return("m")
576+
expect(shell).to receive(:system).with("git", "difftool", "--no-index", /foo/, "foo")
577+
capture(:stdout) { shell.file_collision("foo") {} }
578+
end
579+
567580
it "show warning if user chooses merge but merge tool is not specified" do
568581
allow(shell).to receive(:merge_tool).and_return("")
569582
expect(Thor::LineEditor).to receive(:readline).and_return("m")

0 commit comments

Comments
 (0)