Class: VCSDownloadStrategy

Inherits:
AbstractDownloadStrategy show all
Defined in:
Library/Homebrew/download_strategy.rb

Constant Summary

REF_TYPES =
[:tag, :branch, :revisions, :revision].freeze

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#meta, #name, #resource, #shutup, #version

Instance Method Summary collapse

Methods inherited from AbstractDownloadStrategy

#clear_cache, #expand_safe_system_args, #ohai, #puts, #quiet_safe_system, #safe_system, #shutup!, #source_modified_time, #stage

Methods included from FileUtils

#make, mkdir, mktemp, #rake, #ruby, #scons, #xcodebuild

Constructor Details

#initialize(name, resource) ⇒ VCSDownloadStrategy

Returns a new instance of VCSDownloadStrategy



139
140
141
142
143
144
# File 'Library/Homebrew/download_strategy.rb', line 139

def initialize(name, resource)
  super
  @ref_type, @ref = extract_ref(meta)
  @revision = meta[:revision]
  @clone = HOMEBREW_CACHE/cache_filename
end

Instance Method Details

#cached_locationObject



181
182
183
# File 'Library/Homebrew/download_strategy.rb', line 181

def cached_location
  @clone
end

#commit_outdated?(commit) ⇒ Boolean

Returns:

  • (Boolean)


176
177
178
179
# File 'Library/Homebrew/download_strategy.rb', line 176

def commit_outdated?(commit)
  @last_commit ||= fetch_last_commit
  commit != @last_commit
end

#fetchObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'Library/Homebrew/download_strategy.rb', line 146

def fetch
  ohai "Cloning #{@url}"

  if cached_location.exist? && repo_valid?
    puts "Updating #{cached_location}"
    update
  elsif cached_location.exist?
    puts "Removing invalid repository from cache"
    clear_cache
    clone_repo
  else
    clone_repo
  end

  version.update_commit(last_commit) if head?

  return unless @ref_type == :tag
  return unless @revision && current_revision
  return if current_revision == @revision
  raise <<-EOS.undent
    #{@ref} tag should be #{@revision}
    but is actually #{current_revision}
  EOS
end

#fetch_last_commitObject



171
172
173
174
# File 'Library/Homebrew/download_strategy.rb', line 171

def fetch_last_commit
  fetch
  last_commit
end

#last_commitObject

Return last commit's unique identifier for the repository. Return most recent modified timestamp unless overridden.



189
190
191
# File 'Library/Homebrew/download_strategy.rb', line 189

def last_commit
  source_modified_time.to_i.to_s
end