diff options
-rw-r--r-- | lib/bundler/runtime.rb | 9 | ||||
-rw-r--r-- | lib/bundler/source.rb | 31 | ||||
-rw-r--r-- | spec/lock/git_spec.rb | 14 |
3 files changed, 39 insertions, 15 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 283a52f1..1a29edb5 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -44,6 +44,15 @@ module Bundler Bundler.ui.info("The bundle is now unlocked. The dependencies may be changed.") end + def lock + Bundler.ui.info("The bundle is already locked, relocking.") if locked? + sources.each { |s| s.lock if s.respond_to?(:lock) } + FileUtils.mkdir_p("#{root}/.bundle") + write_yml_lock + write_rb_lock + Bundler.ui.info("The bundle is now locked. Use `bundle show` to list the gems in the environment.") + end + def locked? File.exist?("#{root}/Gemfile.lock") end diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 593f0e47..70d89f8d 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -180,7 +180,7 @@ module Bundler end class Git < Path - attr_reader :uri, :ref + attr_reader :uri, :ref, :options def initialize(options) @options = options @@ -194,10 +194,6 @@ module Bundler "#{@uri} (at #{ref})" end - def options - @options.merge("ref" => revision) - end - def path Bundler.install_path.join("#{base_name}-#{uri_hash}-#{ref}") end @@ -239,18 +235,16 @@ module Bundler Bundler.ui.debug " * Already checked out revision: #{ref}" else Bundler.ui.debug " * Checking out revision: #{ref}" - FileUtils.mkdir_p(path) - Dir.chdir(path) do - unless File.exist?(".git") - %x(git clone --no-checkout #{cache_path} #{path}) - end - git "fetch --quiet" - git "reset --hard #{revision}" - end + checkout @installed = true end end + def lock + @ref = @options["ref"] = revision + checkout + end + private def git(command) @@ -284,6 +278,17 @@ module Bundler end end + def checkout + FileUtils.mkdir_p(path) + Dir.chdir(path) do + unless File.exist?(".git") + %x(git clone --no-checkout #{cache_path} #{path}) + end + git "fetch --quiet" + git "reset --hard #{revision}" + end + end + def revision @revision ||= in_cache { git("rev-parse #{ref}").strip } end diff --git a/spec/lock/git_spec.rb b/spec/lock/git_spec.rb index 1d34fd3c..d36d1043 100644 --- a/spec/lock/git_spec.rb +++ b/spec/lock/git_spec.rb @@ -1,9 +1,19 @@ require File.expand_path('../../spec_helper', __FILE__) describe "gemfile lock with git" do - it "locks a git source to the current ref" do - in_app_root + it "doesn't break right after running lock" do + build_git "foo" + install_gemfile <<-G + git "#{lib_path('foo-1.0')}" + gem 'foo' + G + + bundle :lock + should_be_installed "foo 1.0.0" + end + + it "locks a git source to the current ref" do build_git "foo" install_gemfile <<-G |