Class: GitHubGitDownloadStrategy

Inherits:
GitDownloadStrategy show all
Defined in:
download_strategy.rb

Overview

Strategy for downloading a Git repository from GitHub.

Constant Summary

Constants inherited from VCSDownloadStrategy

VCSDownloadStrategy::REF_TYPES

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cache, #cached_location, #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!, #quiet?, #shutup!, #source_modified_time, #stage

Methods included from SystemCommand::Mixin

#system_command, #system_command!

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.



1104
1105
1106
1107
1108
1109
1110
1111
1112
# File 'download_strategy.rb', line 1104

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

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

  @user = match_data[:user]
  @repo = match_data[:repo]
end

Instance Method Details

#commit_outdated?(commit) ⇒ Boolean

Returns:

  • (Boolean)


1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'download_strategy.rb', line 1114

def commit_outdated?(commit)
  @last_commit ||= GitHub.last_commit(@user, @repo, @ref, version)
  if @last_commit
    return true unless commit
    return true unless @last_commit.start_with?(commit)

    if GitHub.multiple_short_commits_exist?(@user, @repo, commit)
      true
    else
      version.update_commit(commit)
      false
    end
  else
    super
  end
end

#default_branchString?

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:



1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
# File 'download_strategy.rb', line 1141

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 = result.stdout[%r{^refs/remotes/origin/(.*)$}, 1]
end

#default_refspecString

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:



1132
1133
1134
1135
1136
1137
1138
# File 'download_strategy.rb', line 1132

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