Class: VCSDownloadStrategy

Inherits:
AbstractDownloadStrategy show all
Defined in:
brew/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



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

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)


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

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

#fetchObject



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

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



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

def fetch_last_commit
  fetch
  last_commit
end

#head?Boolean

Returns:

  • (Boolean)


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

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.



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

def last_commit
  source_modified_time.to_i.to_s
end