Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a13804f
commit 1b172c1
Showing
2 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ def self.fetch(user, repo = T.unsafe(nil)) | |
cache.fetch(cache_key) { |key| cache[key] = Tap.new(user, repo) } | ||
end | ||
|
||
# sig { params(path: T.any(String, Pathname)).returns(T.nilable(T.attached_class)) } | ||
def self.from_path(path) | ||
match = File.expand_path(path).match(HOMEBREW_TAP_PATH_REGEX) | ||
return if match.blank? || match[:user].blank? || match[:repo].blank? | ||
|
@@ -105,6 +106,7 @@ def self.install_default_cask_tap_if_necessary(force: false) | |
attr_reader :git_repo | ||
|
||
# @private | ||
sig { params(user: String, repo: String).void } | ||
def initialize(user, repo) | ||
@user = user | ||
@repo = repo | ||
|
@@ -115,6 +117,7 @@ def initialize(user, repo) | |
end | ||
|
||
# Clear internal cache. | ||
sig { void } | ||
def clear_cache | ||
@remote = nil | ||
@repo_var = nil | ||
|
@@ -163,6 +166,7 @@ def ensure_installed! | |
|
||
# The remote path to this {Tap}. | ||
# e.g. `https://github.com/user/homebrew-repo` | ||
sig { returns(T.nilable(String)) } | ||
def remote | ||
return default_remote unless installed? | ||
|
||
|
@@ -171,6 +175,7 @@ def remote | |
|
||
# The remote repository name of this {Tap}. | ||
# e.g. `user/homebrew-repo` | ||
sig { returns(T.nilable(String)) } | ||
def remote_repo | ||
@remote_repo ||= remote&.delete_prefix("https://github.com/") | ||
&.delete_prefix("[email protected]:") | ||
|
@@ -184,30 +189,35 @@ def default_remote | |
end | ||
|
||
# @private | ||
sig { returns(String) } | ||
def repo_var | ||
@repo_var ||= path.relative_path_from(TAP_DIRECTORY).to_s.tr("^A-Za-z0-9", "_").upcase | ||
end | ||
|
||
# True if this {Tap} is a Git repository. | ||
sig { returns(T::Boolean) } | ||
def git? | ||
git_repo.git_repo? | ||
end | ||
|
||
# Git branch for this {Tap}. | ||
sig { returns(T.nilable(String)) } | ||
def git_branch | ||
raise TapUnavailableError, name unless installed? | ||
|
||
git_repo.branch_name | ||
end | ||
|
||
# Git HEAD for this {Tap}. | ||
sig { returns(T.nilable(String)) } | ||
def git_head | ||
raise TapUnavailableError, name unless installed? | ||
|
||
@git_head ||= git_repo.head_ref | ||
end | ||
|
||
# Time since last git commit for this {Tap}. | ||
sig { returns(T.nilable(String)) } | ||
def git_last_commit | ||
raise TapUnavailableError, name unless installed? | ||
|
||
|
@@ -223,16 +233,19 @@ def issues_url | |
"#{default_remote}/issues" | ||
end | ||
|
||
sig { returns(String) } | ||
def to_s | ||
name | ||
end | ||
|
||
# True if this {Tap} is an official Homebrew tap. | ||
sig { returns(T::Boolean) } | ||
def official? | ||
user == "Homebrew" | ||
end | ||
|
||
# True if the remote of this {Tap} is a private repository. | ||
sig { returns(T::Boolean) } | ||
def private? | ||
return @private if instance_variable_defined?(:@private) | ||
|
||
|
@@ -248,11 +261,13 @@ def config | |
end | ||
|
||
# True if this {Tap} has been installed. | ||
sig { returns(T::Boolean) } | ||
def installed? | ||
path.directory? | ||
end | ||
|
||
# True if this {Tap} is not a full clone. | ||
sig { returns(T::Boolean) } | ||
def shallow? | ||
(path/".git/shallow").exist? | ||
end | ||
|
@@ -278,6 +293,10 @@ def core_cask_tap? | |
# @param custom_remote [Boolean] If set, change the tap's remote if already installed. | ||
# @param verify [Boolean] If set, verify all the formula, casks and aliases in the tap are valid. | ||
# @param force [Boolean] If set, force core and cask taps to install even under API mode. | ||
sig { | ||
params(quiet: T::Boolean, clone_target: T.nilable(T.any(String, Pathname)), force_auto_update: T.nilable(T::Boolean), | ||
custom_remote: T::Boolean, verify: T::Boolean, force: T::Boolean).void | ||
} | ||
def install(quiet: false, clone_target: nil, force_auto_update: nil, | ||
custom_remote: false, verify: false, force: false) | ||
require "descriptions" | ||
|
@@ -295,7 +314,7 @@ def install(quiet: false, clone_target: nil, force_auto_update: nil, | |
requested_remote = clone_target || default_remote | ||
|
||
if installed? && !custom_remote | ||
raise TapRemoteMismatchError.new(name, @remote, requested_remote) if clone_target && requested_remote != remote | ||
raise TapRemoteMismatchError.new(name, remote, requested_remote) if clone_target && requested_remote != remote | ||
raise TapAlreadyTappedError, name if force_auto_update.nil? && !shallow? | ||
end | ||
|
||
|
@@ -403,6 +422,7 @@ def install(quiet: false, clone_target: nil, force_auto_update: nil, | |
EOS | ||
end | ||
|
||
sig { void } | ||
def link_completions_and_manpages | ||
command = "brew tap --repair" | ||
Utils::Link.link_manpages(path, command) | ||
|
@@ -415,6 +435,7 @@ def link_completions_and_manpages | |
end | ||
end | ||
|
||
sig { params(requested_remote: T.nilable(String), quiet: T::Boolean).void } | ||
def fix_remote_configuration(requested_remote: nil, quiet: false) | ||
if requested_remote.present? | ||
path.cd do | ||
|
@@ -448,6 +469,7 @@ def fix_remote_configuration(requested_remote: nil, quiet: false) | |
end | ||
|
||
# Uninstall this {Tap}. | ||
sig { params(manual: T::Boolean).void } | ||
def uninstall(manual: false) | ||
require "descriptions" | ||
raise TapUnavailableError, name unless installed? | ||
|
@@ -484,6 +506,7 @@ def uninstall(manual: false) | |
end | ||
|
||
# True if the {#remote} of {Tap} is customized. | ||
sig { returns(T::Boolean) } | ||
def custom_remote? | ||
!remote&.casecmp(default_remote)&.zero? | ||
end | ||
|
@@ -526,6 +549,8 @@ def relative_cask_path(token) | |
.delete_prefix("#{path}/") | ||
end | ||
|
||
# @private | ||
sig { returns(T::Array[String]) } | ||
def contents | ||
contents = [] | ||
|
||
|
@@ -830,6 +855,11 @@ def ==(other) | |
self.class == other.class && name == other.name | ||
end | ||
|
||
sig { | ||
override.params( | ||
block: T.nilable(T.proc.params(arg0: T.attached_class).returns(T.untyped)), | ||
).returns(T::Enumerable[T.attached_class]) | ||
} | ||
def self.each(&block) | ||
return to_enum unless block | ||
|
||
|
@@ -882,6 +912,7 @@ def alias_file_to_name(file) | |
"#{name}/#{file.basename}" | ||
end | ||
|
||
sig { params(list: Symbol, formula_or_cask: String, value: T.untyped).returns(T.untyped) } | ||
def audit_exception(list, formula_or_cask, value = nil) | ||
return false if audit_exceptions.blank? | ||
return false unless audit_exceptions.key? list | ||
|
@@ -893,14 +924,15 @@ def audit_exception(list, formula_or_cask, value = nil) | |
list.include? formula_or_cask | ||
when Hash | ||
return false unless list.include? formula_or_cask | ||
return list[formula_or_cask] if value.blank? | ||
return list[formula_or_cask] if value.nil? | ||
|
||
list[formula_or_cask] == value | ||
end | ||
end | ||
|
||
private | ||
|
||
sig { returns(T::Boolean) } | ||
def read_or_set_private_config | ||
case config["private"] | ||
when "true" then true | ||
|
@@ -986,7 +1018,7 @@ class CoreTap < AbstractCoreTap | |
# @private | ||
sig { void } | ||
def initialize | ||
super "Homebrew", "core" | ||
super("Homebrew", "core") | ||
end | ||
|
||
sig { override.void } | ||
|
@@ -996,14 +1028,18 @@ def ensure_installed! | |
super | ||
end | ||
|
||
sig { returns(String) } | ||
sig { override.returns(T.nilable(String)) } | ||
def remote | ||
return super if Homebrew::EnvConfig.no_install_from_api? | ||
|
||
Homebrew::EnvConfig.core_git_remote | ||
end | ||
|
||
# CoreTap never allows shallow clones (on request from GitHub). | ||
sig { | ||
override.params(quiet: T::Boolean, clone_target: T.nilable(T.any(String, Pathname)), force_auto_update: T.nilable(T::Boolean), | ||
custom_remote: T::Boolean, verify: T::Boolean, force: T::Boolean).void | ||
} | ||
def install(quiet: false, clone_target: nil, force_auto_update: nil, | ||
custom_remote: false, verify: false, force: false) | ||
remote = Homebrew::EnvConfig.core_git_remote # set by HOMEBREW_CORE_GIT_REMOTE | ||
|
@@ -1021,15 +1057,15 @@ def install(quiet: false, clone_target: nil, force_auto_update: nil, | |
end | ||
|
||
# @private | ||
sig { params(manual: T::Boolean).void } | ||
sig { override.params(manual: T::Boolean).void } | ||
def uninstall(manual: false) | ||
raise "Tap#uninstall is not available for CoreTap" if Homebrew::EnvConfig.no_install_from_api? | ||
|
||
super | ||
end | ||
|
||
# @private | ||
sig { returns(T::Boolean) } | ||
sig { override.returns(T::Boolean) } | ||
def core_tap? | ||
true | ||
end | ||
|
@@ -1041,7 +1077,7 @@ def linuxbrew_core? | |
end | ||
|
||
# @private | ||
sig { returns(Pathname) } | ||
sig { override.returns(Pathname) } | ||
def formula_dir | ||
@formula_dir ||= begin | ||
ensure_installed! | ||
|
@@ -1083,15 +1119,15 @@ def formula_renames | |
end | ||
|
||
# @private | ||
sig { returns(Hash) } | ||
sig { override.returns(T::Hash[String, String]) } | ||
def tap_migrations | ||
@tap_migrations ||= if Homebrew::EnvConfig.no_install_from_api? | ||
ensure_installed! | ||
super | ||
else | ||
migrations, = Homebrew::API.fetch_json_api_file "formula_tap_migrations.jws.json", | ||
stale_seconds: TAP_MIGRATIONS_STALE_SECONDS | ||
migrations | ||
T.cast(migrations, T::Hash[String, String]) | ||
end | ||
end | ||
|
||
|
@@ -1182,7 +1218,7 @@ class CoreCaskTap < AbstractCoreTap | |
# @private | ||
sig { void } | ||
def initialize | ||
super "Homebrew", "cask" | ||
super("Homebrew", "cask") | ||
end | ||
|
||
# @private | ||
|
@@ -1234,14 +1270,15 @@ def cask_renames | |
end | ||
end | ||
|
||
sig { override.returns(Hash) } | ||
# @private | ||
sig { override.returns(T::Hash[String, String]) } | ||
def tap_migrations | ||
@tap_migrations ||= if Homebrew::EnvConfig.no_install_from_api? | ||
super | ||
else | ||
migrations, = Homebrew::API.fetch_json_api_file "cask_tap_migrations.jws.json", | ||
stale_seconds: TAP_MIGRATIONS_STALE_SECONDS | ||
migrations | ||
T.cast(migrations, T::Hash[String, String]) | ||
end | ||
end | ||
end | ||
|