Class: GitHubGitDownloadStrategy

Inherits:
GitDownloadStrategy show all
Defined in:
download_strategy/github_git_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

Constants inherited from AbstractDownloadStrategy

AbstractDownloadStrategy::HOMEBREW_CONTROLLED_STRATEGIES

Instance Attribute Summary collapse

Attributes inherited from VCSDownloadStrategy

#cached_location

Attributes inherited from AbstractDownloadStrategy

#cache, #url

Instance Method Summary collapse

Methods inherited from GitDownloadStrategy

#clone_args, #fetch, #ref?, #source_modified_time, #source_revision

Methods inherited from VCSDownloadStrategy

#command_sandbox, #fetch, #fetch_last_commit, #fetching?, #head?, #sandbox_write_path

Methods inherited from AbstractDownloadStrategy

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

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods included from SystemCommand::Mixin

#command_sandbox, #system_command, #system_command!

Methods included from Context

current, current=, #debug?, #deferred_environment_expansion?, #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:



15
16
17
18
19
20
21
22
23
24
# File 'download_strategy/github_git_download_strategy.rb', line 15

def initialize(url, name, version, **meta)
  super
  @version = 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 Attribute Details

#repo ⇒ String? (readonly)

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:



12
13
14
# File 'download_strategy/github_git_download_strategy.rb', line 12

def repo
  @repo
end

#user ⇒ String? (readonly)

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:



9
10
11
# File 'download_strategy/github_git_download_strategy.rb', line 9

def user
  @user
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)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'download_strategy/github_git_download_strategy.rb', line 32

def commit_outdated?(commit)
  return true unless commit

  # Fall back to fetching the repository if the GitHub API cannot tell us the latest commit.
  last_commit = github_last_commit
  return super if last_commit.blank?
  return true unless last_commit.start_with?(commit)

  user, repo = github_user_and_repo
  if GitHub.multiple_short_commits_exist?(user, repo, commit)
    true
  else
    head_version.update_commit(commit)
    false
  end
end

#default_branch ⇒ String?

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:



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'download_strategy/github_git_download_strategy.rb', line 59

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_refspec ⇒ String

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:



50
51
52
53
54
55
56
# File 'download_strategy/github_git_download_strategy.rb', line 50

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

#last_commit ⇒ String

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:



27
28
29
# File 'download_strategy/github_git_download_strategy.rb', line 27

def last_commit
  github_last_commit || super
end