summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-07-20 12:06:49 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-07-20 12:06:49 -0700
commit9a196d1894ea15795851ee293a367ed5c5e1b144 (patch)
treec548beaa79caf1304172831c84077b8164975c0f
parent10cedc45d8bee13899d76d076124bac2936e7656 (diff)
downloadbundler-9a196d1894ea15795851ee293a367ed5c5e1b144.tar.gz
Don't run any git commands when in runtime mode (aka Bundler.setup)
-rw-r--r--lib/bundler/cli.rb9
-rw-r--r--lib/bundler/runtime.rb5
-rw-r--r--lib/bundler/source.rb26
-rw-r--r--spec/install/gems/packed_spec.rb2
-rw-r--r--spec/install/git_spec.rb2
-rw-r--r--spec/runtime/setup_spec.rb50
-rw-r--r--spec/support/helpers.rb9
7 files changed, 86 insertions, 17 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 2b205eed06..c882677f82 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -113,7 +113,7 @@ module Bundler
Bundler.ui.be_quiet! if opts[:quiet]
Installer.install(Bundler.root, Bundler.definition, opts)
- cache if Bundler.root.join("vendor/cache").exist?
+ Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
Bundler.ui.confirm "Your bundle is complete! " +
"Use `bundle show [gemname]` to see where a bundled gem is installed."
rescue GemNotFound => e
@@ -141,7 +141,7 @@ module Bundler
end
Installer.install Bundler.root, Bundler.definition, "update" => true
- cache if Bundler.root.join("vendor/cache").exist?
+ Bundler.load.cache if Bundler.root.join("vendor/cache").exist?
Bundler.ui.confirm "Your bundle is updated! " +
"Use `bundle show [gemname]` to see where a bundled gem is installed."
end
@@ -178,8 +178,9 @@ module Bundler
desc "cache", "Cache all the gems to vendor/cache", :hide => true
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
def cache
+ Bundler.definition.resolve_with_cache!
Bundler.load.cache
- Bundler.load.prune_cache unless options[:no_prune]
+ Bundler.settings[:no_prune] = true if options[:no_prune]
Bundler.load.lock
rescue GemNotFound => e
Bundler.ui.error(e.message)
@@ -198,7 +199,7 @@ module Bundler
def package
install
# TODO: move cache contents here now that all bundles are locked
- cache
+ Bundler.load.cache
end
map %w(pack) => :package
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 4d952aca2b..03eba5e71c 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -4,10 +4,6 @@ module Bundler
class Runtime < Environment
include SharedHelpers
- def initialize(*)
- super
- end
-
def setup(*groups)
# Has to happen first
clean_load_path
@@ -82,6 +78,7 @@ module Bundler
next if spec.name == 'bundler'
spec.source.cache(spec) if spec.source.respond_to?(:cache)
end
+ prune_cache unless Bundler.settings[:no_prune]
end
def prune_cache
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index 6d4250f33a..4032f1be94 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -553,12 +553,18 @@ module Bundler
private
def git(command)
- out = %x{git #{command}}
+ if allow_git_ops?
+ out = %x{git #{command}}
- if $? != 0
- raise GitError, "An error has occurred in git. Cannot complete bundling."
+ if $? != 0
+ raise GitError, "An error has occurred in git. Cannot complete bundling."
+ end
+ out
+ else
+ raise GitError, "Bundler is trying to run a `git #{command}` at runtime. You probably need to run `bundle install`. However, " \
+ "this error message could probably be more useful. Please submit a ticket at http://github.com/carlhuda/bundler/issues " \
+ "with steps to reproduce as well as the following\n\nCALLER: #{caller.join("\n")}"
end
- out
end
def base_name
@@ -627,8 +633,18 @@ module Bundler
$? == 0
end
+ def allow_git_ops?
+ @allow_remote || @allow_cached
+ end
+
def revision
- @revision ||= in_cache { git("rev-parse #{ref}").strip }
+ @revision ||= begin
+ if allow_git_ops?
+ in_cache { git("rev-parse #{ref}").strip }
+ else
+ raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application"
+ end
+ end
end
def cached?
diff --git a/spec/install/gems/packed_spec.rb b/spec/install/gems/packed_spec.rb
index 92633150ec..ed1f01187a 100644
--- a/spec/install/gems/packed_spec.rb
+++ b/spec/install/gems/packed_spec.rb
@@ -54,4 +54,4 @@ describe "bundle install with gem sources" do
end
end
end
-end \ No newline at end of file
+end
diff --git a/spec/install/git_spec.rb b/spec/install/git_spec.rb
index ab3b60e1da..a40f5bbd12 100644
--- a/spec/install/git_spec.rb
+++ b/spec/install/git_spec.rb
@@ -336,9 +336,9 @@ describe "bundle install with git sources" do
gem "has_submodule"
end
G
+ out.should =~ /Could not find gem 'submodule'/
should_not_be_installed "has_submodule 1.0", :expect_err => true
- err.should =~ /Could not find gem 'submodule'/
end
it "handles repos with submodules" do
diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb
index d614412f99..8e53ce6ced 100644
--- a/spec/runtime/setup_spec.rb
+++ b/spec/runtime/setup_spec.rb
@@ -179,16 +179,62 @@ describe "Bundler.setup" do
end
describe "with git" do
- it "provides a useful exception when the git repo is not checked out yet" do
+ before do
build_git "rack", "1.0.0"
gemfile <<-G
- gem "foo", :git => "#{lib_path('rack-1.0.0')}"
+ gem "rack", :git => "#{lib_path('rack-1.0.0')}"
G
+ end
+ it "provides a useful exception when the git repo is not checked out yet" do
run "1", :expect_err => true
err.should include("#{lib_path('rack-1.0.0')} (at master) is not checked out. Please run `bundle install`")
end
+
+ it "does not hit the git binary if the lockfile is available and up to date" do
+ bundle "install"
+
+ break_git!
+
+ ruby <<-R
+ require 'rubygems'
+ require 'bundler'
+
+ begin
+ Bundler.setup
+ puts "WIN"
+ rescue Exception => e
+ puts "FAIL"
+ end
+ R
+
+ out.should == "WIN"
+ end
+
+ it "provides a good exception if the lockfile is unavailable" do
+ bundle "install"
+
+ FileUtils.rm(bundled_app("Gemfile.lock"))
+
+ break_git!
+
+ ruby <<-R
+ require "rubygems"
+ require "bundler"
+
+ begin
+ Bundler.setup
+ puts "FAIL"
+ rescue Bundler::GitError => e
+ puts e.message
+ end
+ R
+
+ run "puts 'FAIL'", :expect_err => true
+
+ err.should_not include "This is not the git you are looking for"
+ end
end
describe "when excluding groups" do
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index ab60a6381f..63dd7eb76a 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -157,6 +157,15 @@ module Spec
ENV['GEM_HOME'], ENV['GEM_PATH'] = gem_home, gem_path
end
+ def break_git!
+ FileUtils.mkdir_p(tmp("broken_path"))
+ File.open(tmp("broken_path/git"), "w", 0755) do |f|
+ f.puts "#!/usr/bin/env ruby\nSTDERR.puts 'This is not the git you are looking for'\nexit 1"
+ end
+
+ ENV["PATH"] = "#{tmp("broken_path")}:#{ENV["PATH"]}"
+ end
+
def system_gems(*gems)
gems = gems.flatten