Permalink
Browse files

Fix a bug with git repos and bundle lock breaking the install

  • Loading branch information...
1 parent e993e6f commit 4ebd4da3ec4220c448aa16dd096b35008532fa43 Carl Lerche committed Feb 4, 2010
Showing with 39 additions and 15 deletions.
  1. +9 −0 lib/bundler/runtime.rb
  2. +18 −13 lib/bundler/source.rb
  3. +12 −2 spec/lock/git_spec.rb
View
@@ -44,6 +44,15 @@ def unlock
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
View
@@ -180,7 +180,7 @@ def install(spec)
end
class Git < Path
- attr_reader :uri, :ref
+ attr_reader :uri, :ref, :options
def initialize(options)
@options = options
@@ -194,10 +194,6 @@ def to_s
"#{@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 @@ def install(spec)
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 @@ def cache
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
View
@@ -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

0 comments on commit 4ebd4da

Please sign in to comment.