diff options
author | The Bundler Bot <bot@bundler.io> | 2017-12-11 09:01:51 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-12-11 09:01:51 +0000 |
commit | 6bb5666bec29fba0c56840ca0903935eace9162a (patch) | |
tree | 1dcbd102bea8c66b7be968dd7622a69acb441c57 | |
parent | 690b5bcf8eb283865a3fbe9065f0c8c7bf1b2fe2 (diff) | |
parent | af1f903b8fced5ef74828d245fbb5f6466c3d25a (diff) | |
download | bundler-6bb5666bec29fba0c56840ca0903935eace9162a.tar.gz |
Auto merge of #6202 - hsbt:warning-bundler-binstub, r=hsbt
Show warning message about binstub outside generation.
/cc @indirect
Fixes #6149.
Originated from https://github.com/bundler/bundler/issues/6149#issuecomment-347783823
-rwxr-xr-x | lib/bundler/templates/Executable | 10 | ||||
-rw-r--r-- | spec/commands/binstubs_spec.rb | 19 |
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/bundler/templates/Executable b/lib/bundler/templates/Executable index 4e35e586db..414a75898d 100755 --- a/lib/bundler/templates/Executable +++ b/lib/bundler/templates/Executable @@ -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" diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index d78ad50b61..24ee03ec3c 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -50,6 +50,25 @@ RSpec.describe "bundle binstubs <gem>" do 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 |