summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-07-19 15:02:02 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-07-19 15:02:02 -0700
commiteaa91b9c088187c76d802c44005afc0225e4142f (patch)
tree2c5e7c65c606c988de432002166057bfc086eece
parentc26b2c309432bdcc5397ac0d3bac3831c2a30929 (diff)
downloadbundler-dont_run_git_commands_during_runtime.tar.gz
-rw-r--r--lib/bundler/cli.rb5
-rw-r--r--lib/bundler/source.rb28
-rw-r--r--spec/cache/gems_spec.rb1
-rw-r--r--spec/runtime/setup_spec.rb50
-rw-r--r--spec/support/helpers.rb9
5 files changed, 84 insertions, 9 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 3a26a3be9d..32d68f1be5 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -175,8 +175,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.load.cache
- Bundler.load.prune_cache unless options[:no_prune]
+ environment = Bundler.load
+ environment.cache
+ environment.prune_cache unless options[:no_prune]
rescue GemNotFound => e
Bundler.ui.error(e.message)
Bundler.ui.warn "Run `bundle install` to install missing gems."
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index 68c49ef3a1..210d12349a 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,20 @@ module Bundler
$? == 0
end
+ def allow_git_ops?
+ STDERR.puts "----"
+ STDERR.puts [@allow_remote, @allow_cache].inspect
+ STDERR.puts caller
+ STDERR.puts "----"
+ @allow_remote || @allow_cache
+ end
+
def revision
- @revision ||= in_cache { git("rev-parse #{ref}").strip }
+ if allow_git_ops?
+ @revision ||= 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
def cached?
diff --git a/spec/cache/gems_spec.rb b/spec/cache/gems_spec.rb
index 088a34709d..7e6adf0e65 100644
--- a/spec/cache/gems_spec.rb
+++ b/spec/cache/gems_spec.rb
@@ -68,6 +68,7 @@ describe "bundle cache" do
system_gems []
bundle "install --local"
+ puts out
should_be_installed("rack 1.0.0", "foo 1.0")
end
diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb
index 62b37c4018..1469cba01a 100644
--- a/spec/runtime/setup_spec.rb
+++ b/spec/runtime/setup_spec.rb
@@ -165,16 +165,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