Class: GitHubGitDownloadStrategy

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

Constant Summary

Constants inherited from GitDownloadStrategy

GitDownloadStrategy::SHALLOW_CLONE_WHITELIST

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, #ohai, #puts, #shutup!, #stage

Constructor Details

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

Returns a new instance of GitHubGitDownloadStrategy



799
800
801
802
803
804
805
806
# File 'brew/Library/Homebrew/download_strategy.rb', line 799

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)


836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'brew/Library/Homebrew/download_strategy.rb', line 836

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



808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
# File 'brew/Library/Homebrew/download_strategy.rb', line 808

def github_last_commit
  return if ENV["HOMEBREW_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)


824
825
826
827
828
829
830
831
832
833
834
# File 'brew/Library/Homebrew/download_strategy.rb', line 824

def multiple_short_commits_exist?(commit)
  return if ENV["HOMEBREW_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