summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerence Lee <hone02@gmail.com>2012-12-27 22:47:00 -0500
committerTerence Lee <hone02@gmail.com>2012-12-27 22:47:00 -0500
commit885ed215c21575bcb264038543c9834bb4a98744 (patch)
tree37bdba187d771357e6d7ed558c27e188875f19db
parentdd11095592351c6c8b6f0f7866f4f1d80ebda60f (diff)
downloadbundler-885ed215c21575bcb264038543c9834bb4a98744.tar.gz
handle the case where the binstub already exists, also --force
-rw-r--r--lib/bundler/cli.rb4
-rw-r--r--lib/bundler/installer.rb17
-rw-r--r--spec/other/binstubs_spec.rb39
3 files changed, 56 insertions, 4 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index c26fe1f211..3167afdb37 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -338,6 +338,8 @@ module Bundler
D
method_option "binstubs", :type => :string, :lazy_default => "bin", :banner =>
"Generate bin stubs for bundled gems to ./bin"
+ method_option "force", :type => :boolean, :default => false, :banner =>
+ "forces clean even if --path is not set"
def binstubs(gem_name)
Bundler.definition.validate_ruby!
Bundler.settings[:bin] = options["binstubs"] if options["binstubs"]
@@ -346,7 +348,7 @@ module Bundler
spec = installer.specs.find{|s| s.name == gem_name }
raise GemNotFound, not_found_message(name, Bundler.load.specs) unless spec
- installer.generate_bundler_executable_stubs(spec)
+ installer.generate_bundler_executable_stubs(spec, :force => options[:force])
end
desc "outdated [GEM]", "list installed gems with newer versions available"
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 2073b443f6..ce069a143e 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -126,7 +126,7 @@ module Bundler
raise Bundler::InstallError, msg
end
- def generate_bundler_executable_stubs(spec)
+ def generate_bundler_executable_stubs(spec, options = {})
# double-assignment to avoid warnings about variables that will be used by ERB
bin_path = bin_path = Bundler.bin_path
template = template = File.read(File.expand_path('../templates/Executable', __FILE__))
@@ -134,9 +134,20 @@ module Bundler
ruby_command = ruby_command = Thor::Util.ruby_command
spec.executables.each do |executable|
+ write = true
+ binstub_path = "#{bin_path}/#{executable}"
next if executable == "bundle"
- File.open "#{bin_path}/#{executable}", 'w', 0755 do |f|
- f.puts ERB.new(template, nil, '-').result(binding)
+ if File.exists?(binstub_path) && !options[:force]
+ write = false
+ Bundler.ui.warn <<-MSG
+ Skipping #{executable}, since it already exists.
+ MSG
+ end
+
+ if write
+ File.open binstub_path, 'w', 0755 do |f|
+ f.puts ERB.new(template, nil, '-').result(binding)
+ end
end
end
end
diff --git a/spec/other/binstubs_spec.rb b/spec/other/binstubs_spec.rb
index faab6c0a20..2a14241fb4 100644
--- a/spec/other/binstubs_spec.rb
+++ b/spec/other/binstubs_spec.rb
@@ -92,4 +92,43 @@ describe "bundle binstubs <gem>" do
expect(bundled_app("exec/rails")).to exist
end
end
+
+ context "when the bin already exists" do
+ it "don't override it and warn" do
+ FileUtils.mkdir_p(bundled_app("bin"))
+ File.open(bundled_app("bin/rackup"), 'wb') do |file|
+ file.print "OMG"
+ end
+
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+
+ bundle "binstubs rack"
+
+ expect(bundled_app("bin/rackup")).to exist
+ expect(File.read(bundled_app("bin/rackup"))).to eq("OMG")
+ expect(out).to eq("Skipping rackup, since it already exists.")
+ end
+
+ context "when using --force" do
+ it "overrides the binstub" do
+ FileUtils.mkdir_p(bundled_app("bin"))
+ File.open(bundled_app("bin/rackup"), 'wb') do |file|
+ file.print "OMG"
+ end
+
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+
+ bundle "binstubs rack --force"
+
+ expect(bundled_app("bin/rackup")).to exist
+ expect(File.read(bundled_app("bin/rackup"))).not_to eq("OMG")
+ end
+ end
+ end
end