diff options
author | The Bundler Bot <bot@bundler.io> | 2017-12-11 09:01:51 +0000 |
---|---|---|
committer | SHIBATA Hiroshi <hsbt@ruby-lang.org> | 2017-12-11 20:42:18 +0900 |
commit | beb3b8f1948bb5abcf72bc9c935378aa59859e9f (patch) | |
tree | 12b27a362a3f71bdc76df5c64e2597c8e395fc28 | |
parent | 031ac503f9ceca763abe77136ff5da01e5d0bed6 (diff) | |
download | bundler-beb3b8f1948bb5abcf72bc9c935378aa59859e9f.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 |