Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Install explicit commit (from lockfil) instead of the actual HEAD.

  • Loading branch information...
commit fb052a6e9adef04bce18f82388a8fd0f88f563a3 1 parent e00b503
Eloy Durán authored September 05, 2012
18  lib/cocoapods/dependency.rb
@@ -18,29 +18,25 @@ def initialize(*name_and_version_requirements, &block)
18 18
       elsif !name_and_version_requirements.empty? && block.nil?
19 19
         version = name_and_version_requirements.last
20 20
         if name_and_version_requirements.last.is_a?(Hash)
21  
-          @external_source = ExternalSource.from_params(name_and_version_requirements[0].split('/').first, name_and_version_requirements.pop)
22  
-        elsif version.is_a?(Symbol) && version == :head || version.is_a?(Version) && version.head?
  21
+          name = name_and_version_requirements[0].split('/').first
  22
+          params = name_and_version_requirements.pop
  23
+          @external_source = ExternalSource.from_params(name, params)
  24
+        elsif version.is_a?(Symbol) && version == :head
23 25
           name_and_version_requirements.pop
24 26
           @head = true
  27
+        # Don't remove version requirement from arguments
  28
+        elsif version.is_a?(Version) && version.head?
  29
+          @head = true
25 30
         end
26 31
 
27 32
         super(*name_and_version_requirements)
28 33
 
29  
-        if head? && !latest_version?
30  
-          raise Informative, "A `:head' dependency may not specify version requirements."
31  
-        end
32  
-
33 34
       else
34 35
         raise Informative, "A dependency needs either a name and version requirements, " \
35 36
                            "a source hash, or a block which defines a podspec."
36 37
       end
37 38
     end
38 39
 
39  
-    def latest_version?
40  
-      versions = @version_requirements.requirements.map(&:last)
41  
-      versions == [Gem::Version.new('0')]
42  
-    end
43  
-
44 40
     def ==(other)
45 41
       super && (head? == other.head?) && (@specification ? @specification == other.specification : @external_source == other.external_source)
46 42
     end
2  lib/cocoapods/downloader.rb
@@ -12,7 +12,7 @@ class Downloader
12 12
 
13 13
     def self.for_pod(pod)
14 14
       spec = pod.top_specification
15  
-      for_target(pod.root, spec.source.dup)
  15
+      for_target(pod.root, (spec.explicit_head_source || spec.source).dup)
16 16
     end
17 17
 
18 18
     attr_reader :target_path, :url, :options
1  lib/cocoapods/downloader/git.rb
@@ -155,7 +155,6 @@ def clone(from, to)
155 155
       def update_current_head_source
156 156
         Dir.chdir(target_path) do
157 157
           @current_head_source = { :git => url, :commit => options[:commit] || git('log -n1 --pretty=format:%h') }
158  
-          p @current_head_source
159 158
         end
160 159
       end
161 160
     end
2  lib/cocoapods/installer.rb
@@ -73,7 +73,7 @@ def install_dependencies!
73 73
     def download_pod(pod)
74 74
       downloader = Downloader.for_pod(pod)
75 75
       # Force the `bleeding edge' version if necessary.
76  
-      if pod.top_specification.version.head?
  76
+      if pod.top_specification.version.head? && pod.top_specification.explicit_head_source.nil?
77 77
         if downloader.respond_to?(:download_head)
78 78
           downloader.download_head
79 79
         else
34  lib/cocoapods/lockfile.rb
@@ -74,25 +74,37 @@ def pods_names
74 74
     #   of the installed Pods as the keys and their corresponding {Version}
75 75
     #   as the values.
76 76
     #
77  
-    def pods_versions
78  
-      unless @pods_versions
79  
-        @pods_versions = {}
  77
+    def pod_versions
  78
+      unless @pod_versions
  79
+        @pod_versions = {}
80 80
         pods.each do |pod|
81 81
           pod = pod.keys.first unless pod.is_a?(String)
82 82
           name, version = name_and_version_for_pod(pod)
83  
-          @pods_versions[name] = version
  83
+          @pod_versions[name] = version
84 84
         end
85 85
       end
86  
-      @pods_versions
  86
+      @pod_versions
  87
+    end
  88
+
  89
+    def pod_dependencies
  90
+      unless @pod_dependencies
  91
+        @pod_dependencies = {}
  92
+        pods.each do |pod|
  93
+          pod = pod.keys.first unless pod.is_a?(String)
  94
+          dep = dependency_from_string(pod)
  95
+          @pod_dependencies[dep.name] = dep
  96
+        end
  97
+      end
  98
+      @pod_dependencies
87 99
     end
88 100
 
89 101
     # @return [Dependency] A dependency that describes the exact installed version
90 102
     #   of a Pod.
91 103
     #
92 104
     def dependency_for_installed_pod_named(name)
93  
-      version = pods_versions[name]
94  
-      raise Informative, "Attempt to lock a Pod without an known version." unless version
95  
-      dependency = Dependency.new(name, version)
  105
+      unless dependency = pod_dependencies[name]
  106
+        raise Informative, "Attempt to lock a Pod without an known version."
  107
+      end
96 108
       if external_source = external_sources[name]
97 109
         dependency.external_source = Dependency::ExternalSource.from_params(dependency.name, external_source)
98 110
       end
@@ -126,7 +138,7 @@ def name_and_version_for_pod(string)
126 138
     #       "libPusher (= 1.0)"
127 139
     #       "libPusher (~> 1.0.1)"
128 140
     #       "libPusher (> 1.0, < 2.0)"
129  
-    #       "libPusher (HEAD)"
  141
+    #       "libPusher (HEAD based on 1.2.3)"
130 142
     #       "libPusher (from `www.example.com')"
131 143
     #       "libPusher (defined in Podfile)"
132 144
     #       "RestKit/JSON"
@@ -153,7 +165,7 @@ def dependency_from_string(string)
153 165
         end
154 166
         Dependency.new(name, external_source_info)
155 167
       when /HEAD/
156  
-        dep = Dependency.new(name, :head)
  168
+        dep = Dependency.new(name, Version.from_string(version.strip))
157 169
         dep.explicit_head_source = sources[name]
158 170
         dep
159 171
       else
@@ -192,7 +204,7 @@ def detect_changes_with_podfile(podfile)
192 204
       user_installed_pods.each do |pod_name|
193 205
         dependency = deps_to_install.find { |d| d.name == pod_name }
194 206
         deps_to_install.delete(dependency)
195  
-        version = pods_versions[pod_name]
  207
+        version = pod_versions[pod_name]
196 208
         external_source = Dependency::ExternalSource.from_params(pod_name, external_sources[pod_name])
197 209
 
198 210
         if dependency.nil?
9  lib/cocoapods/resolver.rb
@@ -121,7 +121,7 @@ def pods_to_install
121 121
       unless @pods_to_install
122 122
         if lockfile
123 123
           @pods_to_install = specs.select do |spec|
124  
-            spec.version != lockfile.pods_versions[spec.pod_name]
  124
+            spec.version != lockfile.pod_versions[spec.pod_name]
125 125
           end.map(&:name)
126 126
           if update_mode
127 127
             @pods_to_install += specs.select do |spec|
@@ -206,7 +206,12 @@ def find_dependency_specs(dependent_specification, dependencies, target_definiti
206 206
           @cached_specs[spec.name] = spec
207 207
           # Configure the specification
208 208
           spec.activate_platform(target_definition.platform)
209  
-          spec.version.head = dependency.head?
  209
+          if spec.version.head = dependency.head?
  210
+            # Override the source if this dependency has been locked before.
  211
+            if source = dependency.explicit_head_source
  212
+              spec.explicit_head_source = source
  213
+            end
  214
+          end
210 215
           # And recursively load the dependencies of the spec.
211 216
           find_dependency_specs(spec, spec.dependencies, target_definition) if spec.dependencies
212 217
         end
1  lib/cocoapods/specification.rb
@@ -199,6 +199,7 @@ def available_platforms
199 199
 
200 200
     top_attr_accessor :defined_in_file
201 201
     top_attr_accessor :source
  202
+    top_attr_accessor :explicit_head_source
202 203
     top_attr_accessor :homepage
203 204
     top_attr_accessor :summary
204 205
     top_attr_accessor :documentation
4  lib/cocoapods/version.rb
@@ -10,6 +10,10 @@ def self.from_string(string)
10 10
         v = Version.new($2)
11 11
         v.head = true
12 12
         v
  13
+      elsif string =~ /HEAD/
  14
+        v = Version.new('0')
  15
+        v.head = true
  16
+        v
13 17
       else
14 18
         Version.new(string)
15 19
       end

0 notes on commit fb052a6

Please sign in to comment.
Something went wrong with that request. Please try again.