Class: GitHubGitDownloadStrategy

Inherits:
GitDownloadStrategy show all
Defined in:
download_strategy.rb

Overview

Strategy for downloading a Git repository from GitHub.

Constant Summary

Constants inherited from GitDownloadStrategy

GitDownloadStrategy::MINIMUM_COMMIT_HASH_LENGTH

Constants inherited from VCSDownloadStrategy

VCSDownloadStrategy::REF_TYPES

Instance Attribute Summary

Attributes inherited from VCSDownloadStrategy

#cached_location

Attributes inherited from AbstractDownloadStrategy

#cache, #url

Instance Method Summary collapse

Methods inherited from GitDownloadStrategy

#source_modified_time

Methods inherited from VCSDownloadStrategy

#fetch, #fetch_last_commit, #head?

Methods inherited from AbstractDownloadStrategy

#basename, #cached_location, #clear_cache, #fetch, #fetched_size, #ohai, #quiet!, #quiet?, #source_modified_time, #stage, #total_size

Methods included from Utils::Output::Mixin

#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled

Methods included from SystemCommand::Mixin

#system_command, #system_command!

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

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

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:



1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
# File 'download_strategy.rb', line 1254

def initialize(url, name, version, **meta)
  super
  @version = T.let(version, T.nilable(Version))

  match_data = %r{^https?://github\.com/(?<user>[^/]+)/(?<repo>[^/]+)\.git$}.match(@url)
  return unless match_data

  @user = T.let(match_data[:user], T.nilable(String))
  @repo = T.let(match_data[:repo], T.nilable(String))
end

Instance Method Details

#commit_outdated?(commit) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
# File 'download_strategy.rb', line 1272

def commit_outdated?(commit)
  return true unless commit
  return super if last_commit.blank?
  return true unless last_commit.start_with?(commit)

  if GitHub.multiple_short_commits_exist?(@user, @repo, commit)
    true
  else
    T.must(@version).update_commit(commit)
    false
  end
end

#default_branchString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
# File 'download_strategy.rb', line 1295

def default_branch
  return @default_branch if defined?(@default_branch)

  command! "git",
           args:  ["remote", "set-head", "origin", "--auto"],
           chdir: cached_location

  result = command! "git",
                    args:  ["symbolic-ref", "refs/remotes/origin/HEAD"],
                    chdir: cached_location

  @default_branch = T.let(result.stdout[%r{^refs/remotes/origin/(.*)$}, 1], T.nilable(String))
end

#default_refspecString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



1286
1287
1288
1289
1290
1291
1292
# File 'download_strategy.rb', line 1286

def default_refspec
  if default_branch
    "+refs/heads/#{default_branch}:refs/remotes/origin/#{default_branch}"
  else
    super
  end
end

#last_commitString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



1266
1267
1268
1269
# File 'download_strategy.rb', line 1266

def last_commit
  @last_commit ||= GitHub.last_commit(@user, @repo, @ref, version, length: MINIMUM_COMMIT_HASH_LENGTH)
  @last_commit || super
end