Browse files

Don't write env.rb from inside an env.rb bundle

  • Loading branch information...
1 parent b45e010 commit 63b145d7942fbeb84f899fb7a301a607525d313f @indirect indirect committed Apr 22, 2010
Showing with 23 additions and 11 deletions.
  1. +6 −10 lib/bundler/environment.rb
  2. +1 −1 lib/bundler/runtime.rb
  3. +16 −0 spec/runtime/environment_rb_spec.rb
View
16 lib/bundler/environment.rb
@@ -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
View
2 lib/bundler/runtime.rb
@@ -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)
View
16 spec/runtime/environment_rb_spec.rb
@@ -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.