Class: GitHubGitDownloadStrategy

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

Overview

Strategy for downloading a Git repository from GitHub.

Constant Summary

Constants inherited from GitDownloadStrategy

GitDownloadStrategy::SHALLOW_CLONE_ALLOWLIST

Constants inherited from VCSDownloadStrategy

VCSDownloadStrategy::REF_TYPES

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cache, #cached_location, #source_modified_time, #url

Instance Method Summary collapse

Methods inherited from GitDownloadStrategy

#last_commit, #source_modified_time

Methods inherited from VCSDownloadStrategy

#fetch, #fetch_last_commit, #head?, #last_commit

Methods inherited from AbstractDownloadStrategy

#basename, #clear_cache, #fetch, #shutup!, #stage

Methods included from Context

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

Constructor Details

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

Returns a new instance of GitHubGitDownloadStrategy.


876
877
878
879
880
881
882
883
# File 'Library/Homebrew/download_strategy.rb', line 876

def initialize(url, name, version, **meta)
  super

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

  @user = user
  @repo = repo
end

Instance Method Details

#commit_outdated?(commit) ⇒ Boolean

Returns:

  • (Boolean)

913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
# File 'Library/Homebrew/download_strategy.rb', line 913

def commit_outdated?(commit)
  @last_commit ||= github_last_commit
  if !@last_commit
    super
  else
    return true unless commit
    return true unless @last_commit.start_with?(commit)

    if multiple_short_commits_exist?(commit)
      true
    else
      version.update_commit(commit)
      false
    end
  end
end

#github_last_commitObject


885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
# File 'Library/Homebrew/download_strategy.rb', line 885

def github_last_commit
  return if Homebrew::EnvConfig.no_github_api?

  output, _, status = curl_output(
    "--silent", "--head", "--location",
    "-H", "Accept: application/vnd.github.v3.sha",
    "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}"
  )

  return unless status.success?

  commit = output[/^ETag: "(\h+)"/, 1]
  version.update_commit(commit) if commit
  commit
end

#multiple_short_commits_exist?(commit) ⇒ Boolean

Returns:

  • (Boolean)

901
902
903
904
905
906
907
908
909
910
911
# File 'Library/Homebrew/download_strategy.rb', line 901

def multiple_short_commits_exist?(commit)
  return if Homebrew::EnvConfig.no_github_api?

  output, _, status = curl_output(
    "--silent", "--head", "--location",
    "-H", "Accept: application/vnd.github.v3.sha",
    "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}"
  )

  !(status.success? && output && output[/^Status: (200)/, 1] == "200")
end