Skip to content

Commit

Permalink
Auto merge of rubygems#6202 - hsbt:warning-bundler-binstub, r=hsbt
Browse files Browse the repository at this point in the history
Show warning message about binstub outside generation.

/cc @indirect

Fixes rubygems#6149.

Originated from rubygems#6149 (comment)
  • Loading branch information
bundlerbot authored and hsbt committed Dec 11, 2017
1 parent 031ac50 commit beb3b8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/bundler/templates/Executable
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../<%= relative_gemfile_path %>",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)
load(bundle_binstub) if File.file?(bundle_binstub)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"
Expand Down
19 changes: 19 additions & 0 deletions spec/commands/binstubs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@
expect(out).to include("`bundle binstubs` needs at least one gem to run.")
end

context "when generating bundle binstub outside bundler" do
it "should abort" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
G

bundle "binstubs rack"

File.open("bin/bundle", "wb") do |file|
file.print "OMG"
end

sys_exec "bin/rackup"

expect(last_command.stderr).to include("was not generated by Bundler")
end
end

context "the bundle binstub" do
before do
if system_bundler_version == :bundler
Expand Down

0 comments on commit beb3b8f

Please sign in to comment.