Permalink
Browse files

Improve Podfile.lock version when the `:head` option is used.

  • Loading branch information...
1 parent aad3fb4 commit 0350fff6b0f890f3e6d4da2a93f67232784e7e50 @alloy alloy committed Aug 23, 2012
Showing with 34 additions and 14 deletions.
  1. +7 −7 lib/cocoapods/lockfile.rb
  2. +11 −7 lib/cocoapods/version.rb
  3. +16 −0 spec/unit/version_spec.rb
View
@@ -99,17 +99,17 @@ def dependency_for_installed_pod_named(name)
# @example Strings examples
# "libPusher"
# "libPusher (1.0)"
- # "libPusher (HEAD from 1.0)"
+ # "libPusher (HEAD based on 1.0)"
# "RestKit/JSON"
#
# @return [String, Version] The name and the version of a
# pod.
#
def name_and_version_for_pod(string)
- match_data = string.match(/(\S*) \((.*)\)/)
- name = match_data[1]
- vers = Version.from_s(match_data[2])
- return [name, vers]
+ match_data = string.match(/(\S*) \((.*)\)/)
+ name = match_data[1]
+ vers = Version.from_string(match_data[2])
+ [name, vers]
end
# @param [String] The string that describes a {Dependency} generated
@@ -241,7 +241,7 @@ def self.generate_hash_from_podfile(podfile, specs)
end
end
pod_and_deps = tmp.sort_by(&:first).map do |name, deps|
- deps.empty? ? name : {name => deps}
+ deps.empty? ? name : { name => deps }
end
hash["PODS"] = pod_and_deps
@@ -253,7 +253,7 @@ def self.generate_hash_from_podfile(podfile, specs)
hash["EXTERNAL SOURCES"] = external_sources unless external_sources.empty?
checksums = {}
- specs.select {|spec| !spec.defined_in_file.nil? }.each do |spec|
+ specs.select { |spec| !spec.defined_in_file.nil? }.each do |spec|
checksum = Digest::SHA1.hexdigest(File.read(spec.defined_in_file))
checksum = checksum.encode('UTF-8') if checksum.respond_to?(:encode)
checksums[spec.name] = checksum
View
@@ -3,19 +3,23 @@ class Version < Gem::Version
# @returns A Version described by its #to_s method.
#
- def self.from_s(string)
- match = string.match(/HEAD from (.*)/)
- string = match[1] if match
- vers = Version.new(string)
- vers.head = true if match
- vers
+ # @TODO The `from' part of the regexp should be remove before 1.0.0.
+ #
+ def self.from_string(string)
+ if string =~ /HEAD (based on|from) (.*)/
+ v = Version.new($2)
+ v.head = true
+ v
+ else
+ Version.new(string)
+ end
end
attr_accessor :head
alias_method :head?, :head
def to_s
- head? ? "HEAD from #{super}" : super
+ head? ? "HEAD based on #{super}" : super
end
end
end
View
@@ -8,5 +8,21 @@ module Pod
version.head = true
version.should.be.head
end
+
+ it "serializes to and from a string" do
+ version = Version.from_string('1.2.3')
+ version.to_s.should == '1.2.3'
+ version.should.not.be.head
+
+ version = Version.from_string('HEAD based on 1.2.3')
+ version.should.be.head
+ version.to_s.should == 'HEAD based on 1.2.3'
+ end
+
+ it "supports the previous way that a HEAD version was described" do
+ version = Version.from_string('HEAD from 1.2.3')
+ version.should.be.head
+ version.to_s.should == 'HEAD based on 1.2.3'
+ end
end
end

2 comments on commit 0350fff

Owner

alloy replied Aug 23, 2012

@irrationalfab I tried to keep compatibility, but what are your plans with regards to upgrading? Will CP always delete the old version (< 0.14.0) lockfile first?

Owner

fabiopelosin replied Aug 23, 2012

No, according to my quick test the old lockfile is respected. The only issues that I'm aware if iirc is that the external sources are not stored so they are reinstalled as the lockfile recognizes them as changed.

Please sign in to comment.