summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-02-10 02:54:24 +0000
committerThe Bundler Bot <bot@bundler.io>2017-02-10 02:54:24 +0000
commitf93accce1e9d948eaef79e2f380fd7d396687808 (patch)
treefecf56c27a7959f56150b59486ba4da2c393b647
parent1f99317050a556e53ef9b2cea0bec5926b0d5cf9 (diff)
parent9a15da144ed6f229a1d4d8d07f5937e31248c9c8 (diff)
downloadbundler-f93accce1e9d948eaef79e2f380fd7d396687808.tar.gz
Auto merge of #5415 - nodo:issue-5358-conflicts-in-bundle-gem, r=segiddins
[Fix #5358] Handle files conflicts when using `bundle gem` `bundle gem` command fails with an exception when creating a gem having the same name of a file in the specified path. For instance: > touch hello > bundle gem hello This bug is due to Thor gem. At the moment, Thor does not handle conflicts between files and directories. This commit mitigates the problem by rescuing the exception from Thor and gracefully exit with an error message. Fixes https://github.com/bundler/bundler/issues/5358
-rw-r--r--lib/bundler/cli/gem.rb7
-rw-r--r--spec/commands/newgem_spec.rb22
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 955989659c..971b55b282 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -122,7 +122,10 @@ module Bundler
end
templates.each do |src, dst|
- thor.template("newgem/#{src}", target.join(dst), config)
+ destination = target.join(dst)
+ SharedHelpers.filesystem_access(destination) do
+ thor.template("newgem/#{src}", destination, config)
+ end
end
executables.each do |file|
@@ -139,6 +142,8 @@ module Bundler
# Open gemspec in editor
open_editor(options["edit"], target.join("#{name}.gemspec")) if options[:edit]
+ rescue Errno::EEXIST => e
+ raise GenericSystemCallError.new(e, "There was a conflict while creating the new gem.")
end
private
diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb
index 354a038cc1..7c87b9e524 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -835,4 +835,26 @@ Usage: "bundle gem GEM [OPTIONS]"
expect(bundled_app("foobar/CODE_OF_CONDUCT.md")).to exist
end
end
+
+ context "on conflicts with a previously created file" do
+ it "should fail gracefully" do
+ in_app_root do
+ FileUtils.touch("conflict-foobar")
+ end
+ output = bundle "gem conflict-foobar"
+ expect(output).to include("Errno::EEXIST")
+ expect(exitstatus).to eql(32) if exitstatus
+ end
+ end
+
+ context "on conflicts with a previously created directory" do
+ it "should fail gracefully" do
+ in_app_root do
+ FileUtils.mkdir_p("conflict-foobar/Gemfile")
+ end
+ output = bundle "gem conflict-foobar"
+ expect(output).to include("Errno::EISDIR")
+ expect(exitstatus).to eql(32) if exitstatus
+ end
+ end
end