Class: GitDownloadStrategy
- Inherits:
-
VCSDownloadStrategy
- Object
- AbstractDownloadStrategy
- VCSDownloadStrategy
- GitDownloadStrategy
- Defined in:
- download_strategy/git_download_strategy.rb
Overview
Strategy for downloading a Git repository.
Direct Known Subclasses
Constant Summary collapse
- MINIMUM_COMMIT_HASH_LENGTH =
7
Constants inherited from VCSDownloadStrategy
VCSDownloadStrategy::REF_TYPES
Constants inherited from AbstractDownloadStrategy
AbstractDownloadStrategy::HOMEBREW_CONTROLLED_STRATEGIES
Instance Attribute Summary
Attributes inherited from VCSDownloadStrategy
Attributes inherited from AbstractDownloadStrategy
Class Method Summary collapse
-
.sandboxed_env ⇒ Hash{String => String}
private
Preserve user configuration, helper executables and SSH agents during downloads.
-
.sandboxed_git(sandbox, *args, timeout: nil) ⇒ SystemCommand::Result
private
Capture non-interactive Git output using the download environment and permissions.
Instance Method Summary collapse
- #clone_args ⇒ Array<String> private
- #fetch(timeout: nil) ⇒ void private
-
#initialize(url, name, version, **meta) ⇒ void
constructor
private
Formula
urlspecs reach download strategies as arbitrary options. -
#last_commit ⇒ String
Return last commit's unique identifier for the repository if fetched locally.
- #ref? ⇒ Boolean private
-
#source_modified_time ⇒ Time
Returns the most recent modified time for all files in the current working directory after stage.
- #source_revision ⇒ String? private
Methods inherited from VCSDownloadStrategy
#command_sandbox, #commit_outdated?, #fetch_last_commit, #fetching?, #head?, #sandbox_write_path
Methods inherited from AbstractDownloadStrategy
#basename, #cached_location, #chdir, #clear_cache, expand_deferred_environment_for?, #fetched_size, #ohai, #quiet!, #quiet?, #stage, #total_size
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Methods included from SystemCommand::Mixin
#command_sandbox, #system_command, #system_command!
Methods included from Context
current, current=, #debug?, #deferred_environment_expansion?, #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.
Formula url specs reach download strategies as arbitrary options.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'download_strategy/git_download_strategy.rb', line 17 def initialize(url, name, version, **) # Needs to be before the call to `super`, as the VCSDownloadStrategy's # constructor calls `cache_tag` and sets the cache path. @only_path = [:only_path] if @only_path.present? # "Cone" mode of sparse checkout requires patterns to be directories @only_path = T.let("/#{@only_path}", String) unless @only_path.start_with?("/") @only_path = T.let("#{@only_path}/", String) unless @only_path.end_with?("/") end super @ref_type ||= T.let(:branch, T.nilable(Symbol)) @ref ||= T.let("master", T.untyped) end |
Class Method Details
.sandboxed_env ⇒ Hash{String => String}
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.
Preserve user configuration, helper executables and SSH agents during downloads.
110 111 112 113 114 115 116 117 118 |
# File 'download_strategy/git_download_strategy.rb', line 110 def self.sandboxed_env { "GIT_TERMINAL_PROMPT" => "0", "HOME" => Dir.home(ENV.fetch("USER")), "PATH" => PATH.new(ENV.fetch("PATH"), ORIGINAL_PATHS).to_s, "SSH_ASKPASS" => "/usr/bin/false", "SSH_ASKPASS_REQUIRE" => "force", }.merge(ENV.slice("SSH_AUTH_SOCK")) end |
.sandboxed_git(sandbox, *args, timeout: nil) ⇒ SystemCommand::Result
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.
Capture non-interactive Git output using the download environment and permissions.
98 99 100 101 102 103 104 105 106 |
# File 'download_strategy/git_download_strategy.rb', line 98 def self.sandboxed_git(sandbox, *args, timeout: nil) require "utils/git" sandbox.capture( "/usr/bin/env", args: [*sandboxed_env.map { |key, value| "#{key}=#{value}" }, Utils::Git.git, *args], timeout:, must_succeed: false, print_stderr: false, debug: false, verbose: false ) end |
Instance Method Details
#clone_args ⇒ Array<String>
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.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'download_strategy/git_download_strategy.rb', line 77 def clone_args # Fetch submodules separately without the top-level token, even when Git configuration enables recursion. args = ["clone", NO_RECURSE_SUBMODULES] case @ref_type when :branch, :tag args << "--branch" << @ref end args << "--no-checkout" << "--filter=blob:none" if partial_clone_sparse_checkout? args << "--config" << "advice.detachedHead=false" # Silences “detached head” warning. args << "--config" << "core.fsmonitor=false" # Prevent `fsmonitor` from watching this repository. args << "--end-of-options" << @url << cached_location.to_s end |
#fetch(timeout: nil) ⇒ 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.
This method returns an undefined value.
34 35 36 37 38 |
# File 'download_strategy/git_download_strategy.rb', line 34 def fetch(timeout: nil) require "utils/git" Utils::Git.ensure_installed! super end |
#last_commit ⇒ String
Return last commit's unique identifier for the repository if fetched locally.
59 60 61 62 63 |
# File 'download_strategy/git_download_strategy.rb', line 59 def last_commit args = ["--git-dir", git_dir, "rev-parse", "--short=#{MINIMUM_COMMIT_HASH_LENGTH}", "HEAD"] @last_commit ||= system_command("git", args:, env: local_git_env, print_stderr: false).stdout.chomp.presence @last_commit || "" end |
#ref? ⇒ 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.
66 67 68 69 70 71 72 73 74 |
# File 'download_strategy/git_download_strategy.rb', line 66 def ref? # Git before 2.45 ignores GIT_NO_LAZY_FETCH, so deny transports during the cache check too. system_command( "git", args: ["--git-dir", git_dir, "rev-parse", "-q", "--verify", "--end-of-options", "#{@ref}^{commit}"], env: env.merge("GIT_NO_LAZY_FETCH" => "1", "GIT_ALLOW_PROTOCOL" => ""), print_stderr: false, ).success? end |
#source_modified_time ⇒ Time
Returns the most recent modified time for all files in the current working directory after stage.
44 45 46 47 48 49 50 |
# File 'download_strategy/git_download_strategy.rb', line 44 def source_modified_time result = system_command("git", args: ["--git-dir", git_dir, "show", "-s", "--format=%cD"], env: local_git_env, print_stderr: false) raise "Failed to read the Git commit time:\n#{result.stderr}" unless result.success? Time.parse(result.stdout) end |
#source_revision ⇒ String?
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.
53 |
# File 'download_strategy/git_download_strategy.rb', line 53 def source_revision = current_revision.presence |