Skip to content
Browse files

Force gem "foo", :git => "..." to actually pull foo from the git repo…

… even if there is a newer version available in another source.
  • Loading branch information...
1 parent 150d8bc commit 4752a88ccbb3def5fdeca38c3018fe117a55cc62 Carl Lerche committed
View
5 lib/bundler/dependency.rb
@@ -2,7 +2,8 @@ module Bundler
class InvalidEnvironmentName < StandardError; end
class Dependency
- attr_reader :name, :version, :require_as, :only, :except, :bundle
+ attr_reader :name, :version, :require_as, :only, :except
+ attr_accessor :source
def initialize(name, options = {}, &block)
options.each do |k, v|
@@ -14,7 +15,7 @@ def initialize(name, options = {}, &block)
@require_as = options["require_as"]
@only = options["only"]
@except = options["except"]
- @bundle = options.key?("bundle") ? options["bundle"] : true
+ @source = options["source"]
@block = block
if (@only && @only.include?("rubygems")) || (@except && @except.include?("rubygems"))
View
14 lib/bundler/dsl.rb
@@ -58,8 +58,9 @@ def directory(path, options = {})
@directory = DirectorySource.new(options.merge(:location => path))
@directory_sources << @directory
@environment.add_priority_source(@directory)
- yield if block_given?
+ retval = yield if block_given?
@directory = nil
+ retval
end
def git(uri, options = {})
@@ -67,8 +68,9 @@ def git(uri, options = {})
@git = GitSource.new(options.merge(:uri => uri))
@git_sources[uri] = @git
@environment.add_priority_source(@git)
- yield if block_given?
+ retval = yield if block_given?
@git = nil
+ retval
end
def clear_sources
@@ -90,11 +92,11 @@ def gem(name, *args)
dep = Dependency.new(name, options.merge(:version => version))
if options.key?(:bundle) && !options[:bundle]
- # We're using system gems for this one
+ dep.source = SystemGemSource.instance
elsif @git || options[:git]
- _handle_git_option(name, version, options)
+ dep.source = _handle_git_option(name, version, options)
elsif @directory || options[:path]
- _handle_vendored_option(name, version, options)
+ dep.source = _handle_vendored_option(name, version, options)
end
@environment.dependencies << dep
@@ -108,6 +110,7 @@ def _handle_vendored_option(name, version, options)
if dir
dir.required_specs << name
dir.add_spec(path, name, version) if version
+ dir
else
directory options[:path] do
_handle_vendored_option(name, version, {})
@@ -145,6 +148,7 @@ def _handle_git_option(name, version, options)
source.required_specs << name
source.add_spec(Pathname.new(options[:path] || '.'), name, version) if version
+ source
else
git(git, :ref => ref, :branch => branch) do
_handle_git_option(name, version, options)
View
6 lib/bundler/environment.rb
@@ -50,12 +50,14 @@ def install(options = {})
dependencies.reject! { |d| !only_envs.any? {|env| d.in?(env) } }
end
- no_bundle = dependencies.map { |dep| !dep.bundle && dep.name }.compact
+ no_bundle = dependencies.map do |dep|
+ dep.source == SystemGemSource.instance && dep.name
+ end.compact
update = options[:update]
cached = options[:cached]
- repository.install(gem_dependencies, sources,
+ repository.install(dependencies, sources,
:rubygems => rubygems,
:system_gems => system_gems,
:manifest => filename,
View
5 lib/bundler/repository.rb
@@ -21,8 +21,9 @@ def install(dependencies, sources, options = {})
end
source_requirements = {}
- options[:no_bundle].each do |name|
- source_requirements[name] = SystemGemSource.instance
+ dependencies = dependencies.map do |dep|
+ source_requirements[dep.name] = dep.source if dep.source
+ dep.to_gem_dependency
end
# Check to see whether the existing cache meets all the requirements
View
1 lib/bundler/resolver.rb
@@ -86,6 +86,7 @@ def initialize(sources, source_requirements)
end
def debug
+ $debug ||= false
puts yield if $debug
end
View
17 spec/bundler/directory_spec.rb
@@ -137,6 +137,23 @@
`#{tmp_bindir('very_simple')}`.strip.should == 'OMG'
end
+ it "always pulls the dependency from the directory even if there is a newer gem available" do
+ path = lib_builder('abstract', '0.5')
+
+ install_manifest <<-Gemfile
+ clear_sources
+ source "file://#{gem_repo1}"
+ gem "abstract", :path => "#{path}"
+ Gemfile
+
+ out = run_in_context <<-RUBY
+ Bundler.require_env
+ puts ABSTRACT
+ RUBY
+
+ out.should == '0.5'
+ end
+
describe "validating gemspecs" do
it "does not use a gemspec if any of the require paths are missing" do
install_manifest <<-Gemfile
View
18 spec/bundler/git_spec.rb
@@ -182,6 +182,24 @@
:default.should have_const("OMG")
end
+ it "always pulls the dependency from git even if there is a newer gem available" do
+ lib_builder "abstract", "0.5"
+ gitify("#{tmp_path}/dirs/abstract")
+
+ install_manifest <<-Gemfile
+ clear_sources
+ source "file://#{gem_repo1}"
+ gem "abstract", :git => "#{tmp_path}/dirs/abstract"
+ Gemfile
+
+ out = run_in_context <<-RUBY
+ Bundler.require_env
+ puts ABSTRACT
+ RUBY
+
+ out.should == '0.5'
+ end
+
it "raises an exception when nesting calls to git" do
lambda {
install_manifest <<-Gemfile
View
4 spec/bundler/installer_spec.rb
@@ -85,8 +85,10 @@ def setup
it "keeps bin files for already installed gems" do
setup
+ bundled_app("bin", "rails").should_not exist
@manifest.install
- lambda { @manifest.install }.should_not change { bundled_app("bin", "rails").mtime }
+ @manifest.install
+ bundled_app("bin", "rails").should exist
end
it "does not remove bin files when updating gems" do
View
2 spec/support/helpers.rb
@@ -18,7 +18,7 @@ def gem_command(command, args = "", options = {})
args = %["#{args}"]
end
lib = File.join(File.dirname(__FILE__), '..', '..', 'lib')
- %x{#{Gem.ruby} -I#{lib} -rubygems -S gem #{command} #{args}}.strip
+ %x{#{Gem.ruby} -I#{lib} -rubygems -S gem --backtrace #{command} #{args}}.strip
end
def build_manifest_file(*args)

0 comments on commit 4752a88

Please sign in to comment.
Something went wrong with that request. Please try again.