Class: GitDownloadStrategy

Inherits:
VCSDownloadStrategy show all
Defined in:
download_strategy.rb

Overview

Strategy for downloading a Git repository.

Direct Known Subclasses

GitHubGitDownloadStrategy

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 VCSDownloadStrategy

#commit_outdated?, #fetch, #fetch_last_commit, #head?

Methods inherited from AbstractDownloadStrategy

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

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(url, name, version, **meta) ⇒ GitDownloadStrategy

Returns a new instance of GitDownloadStrategy.



845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
# File 'download_strategy.rb', line 845

def initialize(url, name, version, **meta)
  # Needs to be before the call to `super`, as the VCSDownloadStrategy's
  # constructor calls `cache_tag` and sets the cache path.
  @only_path = meta[:only_path]

  if @only_path.present?
    # "Cone" mode of sparse checkout requires patterns to be directories
    @only_path = "/#{@only_path}" unless @only_path.start_with?("/")
    @only_path = "#{@only_path}/" unless @only_path.end_with?("/")
  end

  super
  @ref_type ||= :branch
  @ref ||= "master"
end

Instance Method Details

#last_commitString



872
873
874
875
# File 'download_strategy.rb', line 872

def last_commit
  out, = silent_command("git", args: ["--git-dir", git_dir, "rev-parse", "--short=7", "HEAD"])
  out.chomp
end

#source_modified_timeTime



864
865
866
867
# File 'download_strategy.rb', line 864

def source_modified_time
  out, = silent_command("git", args: ["--git-dir", git_dir, "show", "-s", "--format=%cD"])
  Time.parse(out)
end