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 VCSDownloadStrategy

#cached_location

Attributes inherited from AbstractDownloadStrategy

#cache, #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, #cached_location, #clear_cache, #fetch, #quiet!, #quiet?, #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) ⇒ void

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.

Parameters:

[View source]

1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
# File 'download_strategy.rb', line 1227

def initialize(url, name, version, **meta)
  super
  @version = T.let(version, T.nilable(Version))

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

  @user = T.let(match_data[:user], T.nilable(String))
  @repo = T.let(match_data[:repo], T.nilable(String))
end

Instance Method Details

#commit_outdated?(commit) ⇒ Boolean

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.

Parameters:

Returns:

  • (Boolean)
[View source]

1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
# File 'download_strategy.rb', line 1239

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
      T.must(@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:

[View source]

1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
# File 'download_strategy.rb', line 1266

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

[View source]

1257
1258
1259
1260
1261
1262
1263
# File 'download_strategy.rb', line 1257

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