Class: VCSDownloadStrategy

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

Constant Summary collapse

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

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cache, #cached_location, #source_modified_time, #url

Instance Method Summary collapse

Methods inherited from AbstractDownloadStrategy

#basename, #clear_cache, #ohai, #puts, #shutup!, #stage

Constructor Details

#initialize(url, name, version, **meta) ⇒ VCSDownloadStrategy

Returns a new instance of VCSDownloadStrategy.


122
123
124
125
126
127
# File 'Library/Homebrew/download_strategy.rb', line 122

def initialize(url, name, version, **meta)
  super
  @ref_type, @ref = extract_ref(meta)
  @revision = meta[:revision]
  @cached_location = @cache/"#{name}--#{cache_tag}"
end

Instance Method Details

#commit_outdated?(commit) ⇒ Boolean

Returns:

  • (Boolean)

160
161
162
163
# File 'Library/Homebrew/download_strategy.rb', line 160

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

#fetchObject


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'Library/Homebrew/download_strategy.rb', line 129

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


155
156
157
158
# File 'Library/Homebrew/download_strategy.rb', line 155

def fetch_last_commit
  fetch
  last_commit
end

#head?Boolean

Returns:

  • (Boolean)

165
166
167
# File 'Library/Homebrew/download_strategy.rb', line 165

def head?
  version.respond_to?(:head?) && version.head?
end

#last_commitObject

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


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

def last_commit
  source_modified_time.to_i.to_s
end