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

Commit

Permalink
Raise a better error in the case that a git repo is not cloned yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Lerche committed Mar 9, 2010
1 parent b9f29ad commit 248ca34
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/bundler.rb
Expand Up @@ -36,6 +36,7 @@ class GemfileNotFound < BundlerError; status_code(10) ; end
class GemNotFound < BundlerError; status_code(7) ; end
class VersionConflict < BundlerError; status_code(6) ; end
class GemfileError < BundlerError; status_code(4) ; end
class PathError < BundlerError; status_code(13) ; end
class GitError < BundlerError; status_code(11) ; end
class DeprecatedMethod < BundlerError; status_code(12) ; end
class DeprecatedOption < BundlerError; status_code(12) ; end
Expand Down
3 changes: 1 addition & 2 deletions lib/bundler/installer.rb
Expand Up @@ -71,9 +71,8 @@ def resolve_locally

# Simple logic for now. Can improve later.
specs.length == actual_dependencies.length && specs
rescue Bundler::GemNotFound => e
rescue GemNotFound, PathError => e
nil
raise if ENV["OMG"]
end

def resolve_remotely
Expand Down
8 changes: 8 additions & 0 deletions lib/bundler/source.rb
Expand Up @@ -176,6 +176,8 @@ def load_spec_files
end

index << default_spec if default_spec && index.empty?
else
raise PathError, "The path `#{path}` does not exist."
end

index.freeze
Expand Down Expand Up @@ -271,6 +273,12 @@ def lock
checkout
end

def load_spec_files
super
rescue PathError
raise PathError, "#{to_s} is not checked out. Please run `bundle install`"
end

private

def git(command)
Expand Down
13 changes: 13 additions & 0 deletions spec/runtime/setup_spec.rb
Expand Up @@ -88,6 +88,19 @@
end
end

describe "with git" do
it "provides a useful exception when the git repo is not checked out yet" do
build_git "rack", "1.0.0"

gemfile <<-G
gem "foo", :git => "#{lib_path('rack-1.0.0')}"
G

run "1"
err.should include("#{lib_path('rack-1.0.0')} (at master) is not checked out. Please run `bundle install`")
end
end

describe "when locked" do
it "regenerates .bundle/environment.rb if it does not exist" do
system_gems "rack-1.0.0"
Expand Down
23 changes: 13 additions & 10 deletions spec/support/helpers.rb
Expand Up @@ -39,25 +39,28 @@ def lib
end

def bundle(cmd, options = {})
require "open3"
env = (options.delete(:env) || {}).map{|k,v| "#{k}='#{v}' "}.join
args = options.map { |k,v| " --#{k} #{v}"}.join
gemfile = File.expand_path('../../../bin/bundle', __FILE__)
input, out, err, waitthread = Open3.popen3("#{env}#{Gem.ruby} -I#{lib} #{gemfile} #{cmd}#{args}")
@err = err.read.strip
puts @err if $show_err && !@err.empty?
@out = out.read.strip
@exitstatus = nil
@exitstatus = waitthread.value.to_i if waitthread
sys_exec("#{env}#{Gem.ruby} -I#{lib} #{gemfile} #{cmd}#{args}")
end

def ruby(opts, ruby = nil)
ruby, opts = opts, nil unless ruby
ruby.gsub!(/(?=")/, "\\")
ruby.gsub!('$', '\\$')
out = %x{#{Gem.ruby} -I#{lib} #{opts} -e "#{ruby}"}.strip
@exitstatus = $?.exitstatus
out
sys_exec(%'#{Gem.ruby} -I#{lib} #{opts} -e "#{ruby}"')
end

def sys_exec(cmd)
require "open3"
input, out, err, waitthread = Open3.popen3(cmd)
@err = err.read.strip
puts @err if $show_err && !@err.empty?
@out = out.read.strip
@exitstatus = nil
@exitstatus = waitthread.value.to_i if waitthread
@out
end

def config(config = nil)
Expand Down

0 comments on commit 248ca34

Please sign in to comment.