From beb3b8f1948bb5abcf72bc9c935378aa59859e9f Mon Sep 17 00:00:00 2001 From: The Bundler Bot Date: Mon, 11 Dec 2017 09:01:51 +0000 Subject: 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 --- lib/bundler/templates/Executable | 10 +++++++++- spec/commands/binstubs_spec.rb | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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 " 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 -- cgit v1.2.1