Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlhuda committed Jul 19, 2010
1 parent c26b2c3 commit eaa91b9
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ def show(gem_name = nil)
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."
Expand Down
28 changes: 23 additions & 5 deletions lib/bundler/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,18 @@ def load_spec_files
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
Expand Down Expand Up @@ -627,8 +633,20 @@ def has_revision_cached?
$? == 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?
Expand Down
1 change: 1 addition & 0 deletions spec/cache/gems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

system_gems []
bundle "install --local"
puts out

should_be_installed("rack 1.0.0", "foo 1.0")
end
Expand Down
50 changes: 48 additions & 2 deletions spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,62 @@
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
Expand Down
9 changes: 9 additions & 0 deletions spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ def with_gem_path_as(path)
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

Expand Down

0 comments on commit eaa91b9

Please sign in to comment.