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, #quiet?, #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.


893
894
895
896
897
898
899
900
# File 'Library/Homebrew/download_strategy.rb', line 893

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)

930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
# File 'Library/Homebrew/download_strategy.rb', line 930

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


902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
# File 'Library/Homebrew/download_strategy.rb', line 902

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)

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

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