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, #ruby, #scons, #xcodebuild

Constructor Details

#initialize(name, resource) ⇒ VCSDownloadStrategy

Returns a new instance of VCSDownloadStrategy



136
137
138
139
140
141
# File 'Library/Homebrew/download_strategy.rb', line 136

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



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

def cached_location
  @clone
end

#commit_outdated?(commit) ⇒ Boolean

Returns:

  • (Boolean)


173
174
175
176
# File 'Library/Homebrew/download_strategy.rb', line 173

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

#fetchObject



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

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
    #{@ref} tag should be #{@revision}
    but is actually #{current_revision}
  EOS
end

#fetch_last_commitObject



168
169
170
171
# File 'Library/Homebrew/download_strategy.rb', line 168

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.



186
187
188
# File 'Library/Homebrew/download_strategy.rb', line 186

def last_commit
  source_modified_time.to_i.to_s
end