Permalink
Browse files

Upgrade 0.9 lockfiles to 1.0 lockfiles in-place

  • Loading branch information...
1 parent ef62ee6 commit e0e79df7ccd3b665f631c120d4e8be573c76d651 @indirect indirect committed Jun 8, 2010
Showing with 26 additions and 7 deletions.
  1. +25 −0 lib/bundler.rb
  2. +1 −7 lib/bundler/lockfile_parser.rb
View
@@ -124,6 +124,7 @@ def definition(unlock = nil)
@definition = nil if unlock
@definition ||= begin
configure
+ upgrade_lockfile
lockfile = root.join("Gemfile.lock")
Definition.build(default_gemfile, lockfile, unlock)
end
@@ -200,5 +201,29 @@ def configure_gem_home_and_path
Gem.clear_paths
end
+
+ def upgrade_lockfile
+ lockfile = root.join("Gemfile.lock")
+ if lockfile.exist? && lockfile.read(3) == "---"
+ Bundler.ui.warn "Updating Gemfile.lock from 0.9 format to 1.0 format..."
+
+ lock = YAML.load_file(lockfile)
+
+ source_uris = lock["sources"].map{|s| s["Rubygems"]["uri"] }
+ sources = [Bundler::Source::Rubygems.new({"remotes" => source_uris})]
+
+ deps = lock["dependencies"].map do |name, opts|
+ version = opts.delete("version")
+ Bundler::Dependency.new(name, version, opts)
+ end
+
+ definition = Bundler::Definition.new(nil, deps, sources, {})
+
+ File.open(lockfile, 'w') do |f|
+ f.write definition.to_lock
+ end
+ end
+ end
+
end
end
@@ -11,13 +11,6 @@ def initialize(lockfile)
@specs = []
@state = :source
- # Check for 0.9 lockfile, removing it if found
- if lockfile[0..2] == "---"
- Bundler.ui.warn "Removing Gemfile.lock generated by Bundler 0.9"
- FileUtils.rm_rf(lockfile)
- return nil
- end
-
lockfile.split(/\n+/).each do |line|
if line == "DEPENDENCIES"
@state = :dependency
@@ -99,5 +92,6 @@ def parse_platform(line)
@platforms << Gem::Platform.new($1)
end
end
+
end
end

0 comments on commit e0e79df

Please sign in to comment.