Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Don't write env.rb from inside an env.rb bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Apr 22, 2010
1 parent b45e010 commit 63b145d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
16 changes: 6 additions & 10 deletions lib/bundler/environment.rb
Expand Up @@ -76,16 +76,12 @@ def locked?
end

def write_rb_lock
if Bundler.env_file.exist? && !Bundler.env_file.writable?
Bundler.ui.warn "Cannot write to outdated .bundle/environment.rb to update it"
else
shared_helpers = File.read(File.expand_path("../shared_helpers.rb", __FILE__))
template = File.read(File.expand_path("../templates/environment.erb", __FILE__))
erb = ERB.new(template, nil, '-')
Bundler.env_file.dirname.mkpath
File.open(Bundler.env_file, 'w') do |f|
f.puts erb.result(binding)
end
shared_helpers = File.read(File.expand_path("../shared_helpers.rb", __FILE__))
template = File.read(File.expand_path("../templates/environment.erb", __FILE__))
erb = ERB.new(template, nil, '-')
Bundler.env_file.dirname.mkpath
File.open(Bundler.env_file, 'w') do |f|
f.puts erb.result(binding)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/runtime.rb
Expand Up @@ -6,7 +6,7 @@ class Runtime < Environment

def initialize(*)
super
write_rb_lock if locked?
write_rb_lock if locked? && !defined?(Bundler::ENV_LOADED)
end

def setup(*groups)
Expand Down
16 changes: 16 additions & 0 deletions spec/runtime/environment_rb_spec.rb
Expand Up @@ -261,5 +261,21 @@ def require(*a, &b)
RUBY
err.should be_empty
end

it "does not write out env.rb if env.rb has already been loaded" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "bundler", :path => "#{File.expand_path("..", lib)}"
gem "rake"
G
bundle :lock

FileUtils.chmod 0444, env_file
run <<-RUBY, :lite_runtime => true
require 'bundler'
Bundler.runtime
RUBY
env_file.rmtree
end
end
end

0 comments on commit 63b145d

Please sign in to comment.