Class: GitHubGitDownloadStrategy

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

#cached_location, #meta, #name, #resource, #shutup, #version

Instance Method Summary collapse

Methods inherited from GitDownloadStrategy

#last_commit, #source_modified_time, #stage

Methods inherited from VCSDownloadStrategy

#cached_location, #fetch, #fetch_last_commit, #last_commit

Methods inherited from AbstractDownloadStrategy

#clear_cache, #expand_safe_system_args, #fetch, #ohai, #puts, #quiet_safe_system, #safe_system, #shutup!, #source_modified_time, #stage

Methods included from FileUtils

#make, mkdir, mktemp, #old_mkdir, #old_ruby, #ruby, #scons, #xcodebuild

Constructor Details

#initialize(name, resource) ⇒ GitHubGitDownloadStrategy

Returns a new instance of GitHubGitDownloadStrategy



873
874
875
876
877
878
879
# File 'Library/Homebrew/download_strategy.rb', line 873

def initialize(name, resource)
  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)


909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
# File 'Library/Homebrew/download_strategy.rb', line 909

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



881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
# File 'Library/Homebrew/download_strategy.rb', line 881

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)


897
898
899
900
901
902
903
904
905
906
907
# File 'Library/Homebrew/download_strategy.rb', line 897

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