Permalink
Browse files

Cleanup bundler modes

  • Loading branch information...
1 parent ce155f0 commit 2f4444e758743e414c5a5159555860e3677f408d Carlhuda committed Jan 6, 2010
Showing with 43 additions and 38 deletions.
  1. +15 −1 lib/bundler.rb
  2. +2 −11 lib/bundler/bundle.rb
  3. +2 −0 lib/bundler/cli.rb
  4. +3 −5 lib/bundler/environment.rb
  5. +13 −17 lib/bundler/source.rb
  6. +6 −4 spec/bundler/cli_spec.rb
  7. +2 −0 spec/support/helpers.rb
View
@@ -22,7 +22,7 @@ module Bundler
VERSION = "0.8.0"
class << self
- attr_writer :logger
+ attr_writer :logger, :mode
def logger
@logger ||= begin
@@ -31,5 +31,19 @@ def logger
logger
end
end
+
+ def local?
+ @mode == :local
+ end
+
+ def writable?
+ @mode != :readonly
+ end
+
+ def remote?
+ @mode == :readwrite
+ end
end
+
+ self.mode = :readonly
end
View
@@ -77,11 +77,6 @@ def install(options = {})
end
# ==========
- # TODO: clean this up
- sources.each do |s|
- s.local = options[:cached]
- end
-
# Check to see whether the existing cache meets all the requirements
begin
valid = nil
@@ -130,11 +125,7 @@ def list_outdated(options={})
end
def prune(options = {})
- dependencies, sources = @environment.gem_dependencies, @environment.sources
-
- sources.each do |s|
- s.local = true
- end
+ dependencies, sources = @environment.dependencies, @environment.sources
sources = only_local(sources)
bundle = Resolver.resolve(dependencies, [@cache] + sources)
@@ -181,7 +172,7 @@ def setup_environment
private
def only_local(sources)
- sources.select { |s| s.can_be_local? }
+ sources.select { |s| s.local? }
end
def download(bundle, options)
View
@@ -31,6 +31,7 @@ def self.run(command, options = {})
end
def initialize(options)
+ Bundler.mode = options[:cached] ? :local : :readwrite
@options = options
@bundle = Bundle.load(@options[:manifest])
end
@@ -62,6 +63,7 @@ def cache
end
def prune
+ Bundler.mode = :local
@bundle.prune(@options)
end
@@ -33,7 +33,9 @@ def require_env(env = nil)
end
def sources
- @priority_sources + [SystemGemSource.new(@bundle)] + @sources + @default_sources
+ sources = @priority_sources + [SystemGemSource.new(@bundle)] + @sources + @default_sources
+ sources.reject! {|s| !s.local? } if Bundler.local?
+ sources
end
def add_source(source)
@@ -49,10 +51,6 @@ def clear_sources
@default_sources.clear
end
- def gem_dependencies
- @gem_dependencies ||= dependencies.map { |d| d.to_gem_dependency }
- end
-
alias rubygems? rubygems
alias system_gems? system_gems
View
@@ -4,7 +4,6 @@ class GitSourceError < StandardError ; end
# Represents a source of rubygems. Initially, this is only gem repositories, but
# eventually, this will be git, svn, HTTP
class Source
- attr_accessor :local
attr_reader :bundle
def initialize(bundle, options)
@@ -33,7 +32,7 @@ def initialize(bundle, options)
raise ArgumentError, "The source must be an absolute URI" unless @uri.absolute?
end
- def can_be_local?
+ def local?
false
end
@@ -115,7 +114,7 @@ def initialize(bundle, options = {})
@source = Gem::SourceIndex.from_installed_gems
end
- def can_be_local?
+ def local?
false
end
@@ -149,7 +148,7 @@ def initialize(bundle, options)
@location = options[:location]
end
- def can_be_local?
+ def local?
true
end
@@ -205,7 +204,7 @@ def add_spec(path, name, version, require_paths = %w(lib))
end
end
- def can_be_local?
+ def local?
true
end
@@ -307,14 +306,19 @@ def initialize(bundle, options)
@ref = options[:ref] || "origin/#{@branch}"
end
+ def local?
+ raise SourceNotCached, "Git repository '#{@uri}' has not been cloned yet" unless location.directory?
+ super
+ end
+
def location
# TMP HAX to get the *.gemspec reading to work
bundle.gem_path.join('dirs', File.basename(@uri, '.git'))
end
def gems
- update
- checkout
+ update if Bundler.remote?
+ checkout if Bundler.writable?
super
end
@@ -336,19 +340,11 @@ def update
end
def fetch
- unless local
- Bundler.logger.info "Fetching git repository at: #{@uri}"
- Dir.chdir(location) { `git fetch origin` }
- end
+ Bundler.logger.info "Fetching git repository at: #{@uri}"
+ Dir.chdir(location) { `git fetch origin` }
end
def clone
- # Raise an error if the source should run in local mode,
- # but it has not been cached yet.
- if local
- raise SourceNotCached, "Git repository '#{@uri}' has not been cloned yet"
- end
-
Bundler.logger.info "Cloning git repository at: #{@uri}"
FileUtils.mkdir_p(location.dirname)
`git clone #{@uri} #{location} --no-hardlinks`
View
@@ -486,19 +486,21 @@
clear_sources
source "file://#{gem_repo1}"
gem "rack", "0.9.1"
+ gem "rspec"
Gemfile
- manifest.gem_path.should have_cached_gems("rack-0.9.1")
+ manifest.gem_path.should have_cached_gems("rack-0.9.1", "rspec-1.2.7")
manifest = install_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
+ gem "rspec"
Gemfile
- manifest.gem_path.should have_cached_gems("rack-0.9.1")
+ manifest.gem_path.should have_cached_gems("rack-0.9.1", "rspec-1.2.7")
Dir.chdir bundled_app
- out = gem_command :bundle, "--prune-cache"
- manifest.gem_path.should_not have_cached_gems("rack-0.9.1")
+ gem_command :bundle, "--prune-cache"
+ manifest.gem_path.should_not include_cached_gems("rack-0.9.1")
end
end
View
@@ -45,6 +45,8 @@ def build_manifest(*args)
end
def install_manifest(*args)
+ # TODO: Use the CLI directly
+ Bundler.mode = :readwrite
m = build_manifest(*args)
m.install
m

0 comments on commit 2f4444e

Please sign in to comment.