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.



1098
1099
1100
1101
1102
1103
1104
1105
1106
# File 'download_strategy.rb', line 1098

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)


1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
# File 'download_strategy.rb', line 1108

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:



1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'download_strategy.rb', line 1135

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:



1126
1127
1128
1129
1130
1131
1132
# File 'download_strategy.rb', line 1126

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