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

#last_commit

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?

Methods inherited from AbstractDownloadStrategy

#basename, #clear_cache, #fetch, #quiet?, #shutup!, #stage

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.



1064
1065
1066
1067
1068
1069
1070
1071
# File 'download_strategy.rb', line 1064

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)


1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
# File 'download_strategy.rb', line 1073

def commit_outdated?(commit)
  @last_commit ||= GitHub.last_commit(@user, @repo, @ref)
  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

Returns:



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

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

Returns:



1091
1092
1093
1094
1095
1096
1097
# File 'download_strategy.rb', line 1091

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