Merge pull request #17456 from Homebrew/fix_tap_docs

This commit is contained in:
Mike McQuaid 2024-06-10 19:40:42 +01:00 committed by GitHub
commit 81fa3c4cc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 66 additions and 61 deletions

View File

@ -55,8 +55,8 @@ module Homebrew
# Verifies the given bottle against a cryptographic attestation of build provenance. # Verifies the given bottle against a cryptographic attestation of build provenance.
# #
# The provenance is verified as originating from `signing_repo`, which is a `String` # The provenance is verified as originating from `signing_repository`, which is a `String`
# that should be formatted as a GitHub `owner/repo`. # that should be formatted as a GitHub `owner/repository`.
# #
# Callers may additionally pass in `signing_workflow`, which will scope the attestation # Callers may additionally pass in `signing_workflow`, which will scope the attestation
# down to an exact GitHub Actions workflow, in # down to an exact GitHub Actions workflow, in

View File

@ -146,7 +146,7 @@ module Homebrew
updated_taps = [] updated_taps = []
Tap.installed.each do |tap| Tap.installed.each do |tap|
next if !tap.git? || tap.git_repo.origin_url.nil? next if !tap.git? || tap.git_repository.origin_url.nil?
next if (tap.core_tap? || tap.core_cask_tap?) && !Homebrew::EnvConfig.no_install_from_api? next if (tap.core_tap? || tap.core_cask_tap?) && !Homebrew::EnvConfig.no_install_from_api?
if ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"].present? && tap.core_tap? && if ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"].present? && tap.core_tap? &&
@ -321,7 +321,7 @@ module Homebrew
next unless tap.installed? next unless tap.installed?
if tap.git_branch == "master" && if tap.git_branch == "master" &&
(Date.parse(T.must(tap.git_repo.last_commit_date)) <= Date.today.prev_month) (Date.parse(T.must(tap.git_repository.last_commit_date)) <= Date.today.prev_month)
ohai "#{tap.name} is old and unneeded, untapping to save space..." ohai "#{tap.name} is old and unneeded, untapping to save space..."
tap.uninstall tap.uninstall
else else

View File

@ -130,7 +130,7 @@ module Homebrew
tap_remote_repo = formula.tap.full_name || formula.tap.remote_repo tap_remote_repo = formula.tap.full_name || formula.tap.remote_repo
remote = "origin" remote = "origin"
remote_branch = formula.tap.git_repo.origin_branch_name remote_branch = formula.tap.git_repository.origin_branch_name
previous_branch = "-" previous_branch = "-"
check_open_pull_requests(formula, tap_remote_repo) check_open_pull_requests(formula, tap_remote_repo)

View File

@ -98,7 +98,7 @@ module Homebrew
end end
odie "Could not find #{name}! The formula or version may not have existed." if test_formula.nil? odie "Could not find #{name}! The formula or version may not have existed." if test_formula.nil?
else else
# Search in the root directory of `repo` as well as recursively in all of its subdirectories. # Search in the root directory of `repository` as well as recursively in all of its subdirectories.
files = Dir[repo/"{,**/}"].filter_map do |dir| files = Dir[repo/"{,**/}"].filter_map do |dir|
Pathname.glob("#{dir}/#{name}.rb").find(&:file?) Pathname.glob("#{dir}/#{name}.rb").find(&:file?)
end end

View File

@ -95,7 +95,7 @@ module Homebrew
_, user, repo, pr = *url_match _, user, repo, pr = *url_match
odie "Not a GitHub pull request: #{arg}" unless pr odie "Not a GitHub pull request: #{arg}" unless pr
git_repo = tap.git_repo git_repo = tap.git_repository
if !git_repo.default_origin_branch? && !args.branch_okay? && !args.no_commit? && !args.no_cherry_pick? if !git_repo.default_origin_branch? && !args.branch_okay? && !args.no_commit? && !args.no_cherry_pick?
origin_branch_name = git_repo.origin_branch_name origin_branch_name = git_repo.origin_branch_name
opoo "Current branch is #{git_repo.branch_name}: do you need to pull inside #{origin_branch_name}?" opoo "Current branch is #{git_repo.branch_name}: do you need to pull inside #{origin_branch_name}?"
@ -341,7 +341,7 @@ module Homebrew
# TODO: fix test in `test/dev-cmd/pr-pull_spec.rb` and assume `cherry_picked: false`. # TODO: fix test in `test/dev-cmd/pr-pull_spec.rb` and assume `cherry_picked: false`.
def autosquash!(original_commit, tap:, reason: "", verbose: false, resolve: false, cherry_picked: true) def autosquash!(original_commit, tap:, reason: "", verbose: false, resolve: false, cherry_picked: true)
git_repo = tap.git_repo git_repo = tap.git_repository
original_head = git_repo.head_ref original_head = git_repo.head_ref
commits = Utils.safe_popen_read("git", "-C", tap.path, "rev-list", commits = Utils.safe_popen_read("git", "-C", tap.path, "rev-list",

View File

@ -127,7 +127,7 @@ module Homebrew
sig { params(repository_path: GitRepository, desired_origin: String).returns(T.nilable(String)) } sig { params(repository_path: GitRepository, desired_origin: String).returns(T.nilable(String)) }
def examine_git_origin(repository_path, desired_origin) def examine_git_origin(repository_path, desired_origin)
return if !Utils::Git.available? || !repository_path.git_repo? return if !Utils::Git.available? || !repository_path.git_repository?
current_origin = repository_path.origin_url current_origin = repository_path.origin_url
@ -156,7 +156,7 @@ module Homebrew
return unless Utils::Git.available? return unless Utils::Git.available?
repo = GitRepository.new(HOMEBREW_REPOSITORY) repo = GitRepository.new(HOMEBREW_REPOSITORY)
return unless repo.git_repo? return unless repo.git_repository?
message = <<~EOS message = <<~EOS
#{tap.full_name} was not tapped properly! Run: #{tap.full_name} was not tapped properly! Run:
@ -528,14 +528,14 @@ module Homebrew
core_tap.ensure_installed! core_tap.ensure_installed!
end end
broken_tap(core_tap) || examine_git_origin(core_tap.git_repo, Homebrew::EnvConfig.core_git_remote) broken_tap(core_tap) || examine_git_origin(core_tap.git_repository, Homebrew::EnvConfig.core_git_remote)
end end
def check_casktap_integrity def check_casktap_integrity
core_cask_tap = CoreCaskTap.instance core_cask_tap = CoreCaskTap.instance
return unless core_cask_tap.installed? return unless core_cask_tap.installed?
broken_tap(core_cask_tap) || examine_git_origin(core_cask_tap.git_repo, core_cask_tap.remote) broken_tap(core_cask_tap) || examine_git_origin(core_cask_tap.git_repository, core_cask_tap.remote)
end end
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }
@ -544,9 +544,9 @@ module Homebrew
return unless Utils::Git.available? return unless Utils::Git.available?
commands = Tap.installed.filter_map do |tap| commands = Tap.installed.filter_map do |tap|
next if tap.git_repo.default_origin_branch? next if tap.git_repository.default_origin_branch?
"git -C $(brew --repo #{tap.name}) checkout #{tap.git_repo.origin_branch_name}" "git -C $(brew --repo #{tap.name}) checkout #{tap.git_repository.origin_branch_name}"
end end
return if commands.blank? return if commands.blank?

View File

@ -289,8 +289,7 @@ class Formula
private private
# Allow full name logic to be re-used between names, aliases, # Allow full name logic to be re-used between names, aliases and installed aliases.
# and installed aliases.
def full_name_with_optional_tap(name) def full_name_with_optional_tap(name)
if name.nil? || @tap.nil? || @tap.core_tap? if name.nil? || @tap.nil? || @tap.core_tap?
name name

View File

@ -16,9 +16,11 @@ class GitRepository
end end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def git_repo? def git_repository?
pathname.join(".git").exist? pathname.join(".git").exist?
end end
# odeprecated: use git_repository? instead
alias git_repo? git_repository?
# Gets the URL of the Git origin remote. # Gets the URL of the Git origin remote.
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }

View File

@ -9,10 +9,10 @@ require "settings"
# A {Tap} is used to extend the formulae provided by Homebrew core. # A {Tap} is used to extend the formulae provided by Homebrew core.
# Usually, it's synced with a remote Git repository. And it's likely # Usually, it's synced with a remote Git repository. And it's likely
# a GitHub repository with the name of `user/homebrew-repo`. In such # a GitHub repository with the name of `user/homebrew-repository`. In such
# cases, `user/repo` will be used as the {#name} of this {Tap}, where # cases, `user/repository` will be used as the {#name} of this {Tap}, where
# {#user} represents the GitHub username and {#repo} represents the repository # {#user} represents the GitHub username and {#repository} represents the
# name without the leading `homebrew-`. # repository name without the leading `homebrew-`.
class Tap class Tap
extend Cachable extend Cachable
@ -160,11 +160,13 @@ class Tap
# The repository name of this {Tap} without the leading `homebrew-`. # The repository name of this {Tap} without the leading `homebrew-`.
# #
# @api public # @api public
attr_reader :repo attr_reader :repository
# odeprecated: use repository instead.
alias repo repository
# The name of this {Tap}. It combines {#user} and {#repo} with a slash. # The name of this {Tap}. It combines {#user} and {#repository} with a slash.
# {#name} is always in lowercase. # {#name} is always in lowercase.
# e.g. `user/repo` # e.g. `user/repository`
# #
# @api public # @api public
attr_reader :name attr_reader :name
@ -174,14 +176,14 @@ class Tap
def to_s = name def to_s = name
# The full name of this {Tap}, including the `homebrew-` prefix. # The full name of this {Tap}, including the `homebrew-` prefix.
# It combines {#user} and 'homebrew-'-prefixed {#repo} with a slash. # It combines {#user} and 'homebrew-'-prefixed {#repository} with a slash.
# e.g. `user/homebrew-repo` # e.g. `user/homebrew-repository`
# #
# @api public # @api public
attr_reader :full_name attr_reader :full_name
# The local path to this {Tap}. # The local path to this {Tap}.
# e.g. `/usr/local/Library/Taps/user/homebrew-repo` # e.g. `/usr/local/Library/Taps/user/homebrew-repository`
# #
# @api public # @api public
sig { returns(Pathname) } sig { returns(Pathname) }
@ -189,24 +191,24 @@ class Tap
# The git repository of this {Tap}. # The git repository of this {Tap}.
sig { returns(GitRepository) } sig { returns(GitRepository) }
attr_reader :git_repo attr_reader :git_repository
# Always use `Tap.fetch` instead of `Tap.new`. # Always use `Tap.fetch` instead of `Tap.new`.
private_class_method :new private_class_method :new
def initialize(user, repo) def initialize(user, repository)
@user = user @user = user
@repo = repo @repository = repository
@name = "#{@user}/#{@repo}".downcase @name = "#{@user}/#{@repository}".downcase
@full_name = "#{@user}/homebrew-#{@repo}" @full_name = "#{@user}/homebrew-#{@repository}"
@path = TAP_DIRECTORY/@full_name.downcase @path = TAP_DIRECTORY/@full_name.downcase
@git_repo = GitRepository.new(@path) @git_repository = GitRepository.new(@path)
end end
# Clear internal cache. # Clear internal cache.
def clear_cache def clear_cache
@remote = nil @remote = nil
@repo_var_suffix = nil @repository_var_suffix = nil
remove_instance_variable(:@private) if instance_variable_defined?(:@private) remove_instance_variable(:@private) if instance_variable_defined?(:@private)
@formula_dir = nil @formula_dir = nil
@ -253,17 +255,17 @@ class Tap
end end
# The remote path to this {Tap}. # The remote path to this {Tap}.
# e.g. `https://github.com/user/homebrew-repo` # e.g. `https://github.com/user/homebrew-repository`
# #
# @api public # @api public
def remote def remote
return default_remote unless installed? return default_remote unless installed?
@remote ||= git_repo.origin_url @remote ||= git_repository.origin_url
end end
# The remote repository name of this {Tap}. # The remote repository name of this {Tap}.
# e.g. `user/homebrew-repo` # e.g. `user/homebrew-repository`
# #
# @api public # @api public
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }
@ -282,18 +284,20 @@ class Tap
end end
sig { returns(String) } sig { returns(String) }
def repo_var_suffix def repository_var_suffix
@repo_var_suffix ||= path.to_s @repository_var_suffix ||= path.to_s
.delete_prefix(TAP_DIRECTORY.to_s) .delete_prefix(TAP_DIRECTORY.to_s)
.tr("^A-Za-z0-9", "_") .tr("^A-Za-z0-9", "_")
.upcase .upcase
end end
# odeprecated: use repository_var_suffix instead.
alias repo_var_suffix repository_var_suffix
# Check whether this {Tap} is a Git repository. # Check whether this {Tap} is a Git repository.
# #
# @api public # @api public
def git? def git?
git_repo.git_repo? git_repository.git_repository?
end end
# Git branch for this {Tap}. # Git branch for this {Tap}.
@ -302,7 +306,7 @@ class Tap
def git_branch def git_branch
raise TapUnavailableError, name unless installed? raise TapUnavailableError, name unless installed?
git_repo.branch_name git_repository.branch_name
end end
# Git HEAD for this {Tap}. # Git HEAD for this {Tap}.
@ -311,7 +315,7 @@ class Tap
def git_head def git_head
raise TapUnavailableError, name unless installed? raise TapUnavailableError, name unless installed?
@git_head ||= git_repo.head_ref @git_head ||= git_repository.head_ref
end end
# Time since last git commit for this {Tap}. # Time since last git commit for this {Tap}.
@ -320,7 +324,7 @@ class Tap
def git_last_commit def git_last_commit
raise TapUnavailableError, name unless installed? raise TapUnavailableError, name unless installed?
git_repo.last_committed git_repository.last_committed
end end
# The issues URL of this {Tap}. # The issues URL of this {Tap}.
@ -564,22 +568,22 @@ class Tap
end end
return unless remote return unless remote
current_upstream_head = T.must(git_repo.origin_branch_name) current_upstream_head = T.must(git_repository.origin_branch_name)
return if requested_remote.blank? && git_repo.origin_has_branch?(current_upstream_head) return if requested_remote.blank? && git_repository.origin_has_branch?(current_upstream_head)
args = %w[fetch] args = %w[fetch]
args << "--quiet" if quiet args << "--quiet" if quiet
args << "origin" args << "origin"
args << "+refs/heads/*:refs/remotes/origin/*" args << "+refs/heads/*:refs/remotes/origin/*"
safe_system "git", "-C", path, *args safe_system "git", "-C", path, *args
git_repo.set_head_origin_auto git_repository.set_head_origin_auto
new_upstream_head = T.must(git_repo.origin_branch_name) new_upstream_head = T.must(git_repository.origin_branch_name)
return if new_upstream_head == current_upstream_head return if new_upstream_head == current_upstream_head
safe_system "git", "-C", path, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*" safe_system "git", "-C", path, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"
git_repo.rename_branch old: current_upstream_head, new: new_upstream_head git_repository.rename_branch old: current_upstream_head, new: new_upstream_head
git_repo.set_upstream_branch local: new_upstream_head, origin: new_upstream_head git_repository.set_upstream_branch local: new_upstream_head, origin: new_upstream_head
return if quiet return if quiet

View File

@ -99,8 +99,8 @@ RSpec.describe Homebrew::DevCmd::PrPull do
File.write(formula_file, formula_version) File.write(formula_file, formula_version)
safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}" safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}"
pr_pull.autosquash!(original_hash, tap:) pr_pull.autosquash!(original_hash, tap:)
expect(tap.git_repo.commit_message).to include("foo 2.0") expect(tap.git_repository.commit_message).to include("foo 2.0")
expect(tap.git_repo.commit_message).to include("Co-authored-by: #{secondary_author}") expect(tap.git_repository.commit_message).to include("Co-authored-by: #{secondary_author}")
end end
(path/"Casks").mkpath (path/"Casks").mkpath
@ -130,8 +130,8 @@ RSpec.describe Homebrew::DevCmd::PrPull do
safe_system Utils::Git.git, "add", formula_file safe_system Utils::Git.git, "add", formula_file
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)" safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
end end
pr_pull.signoff!(tap.git_repo) pr_pull.signoff!(tap.git_repository)
expect(tap.git_repo.commit_message).to include("Signed-off-by:") expect(tap.git_repository.commit_message).to include("Signed-off-by:")
(path/"Casks").mkpath (path/"Casks").mkpath
cask_file.write(cask) cask_file.write(cask)
@ -139,8 +139,8 @@ RSpec.describe Homebrew::DevCmd::PrPull do
safe_system Utils::Git.git, "add", cask_file safe_system Utils::Git.git, "add", cask_file
safe_system Utils::Git.git, "commit", "-m", "food 1.0 (new cask)" safe_system Utils::Git.git, "commit", "-m", "food 1.0 (new cask)"
end end
pr_pull.signoff!(tap.git_repo) pr_pull.signoff!(tap.git_repository)
expect(tap.git_repo.commit_message).to include("Signed-off-by:") expect(tap.git_repository.commit_message).to include("Signed-off-by:")
end end
end end

View File

@ -695,7 +695,7 @@ module GitHub
old_contents = info[:old_contents] old_contents = info[:old_contents]
additional_files = info[:additional_files] || [] additional_files = info[:additional_files] || []
remote = info[:remote] || "origin" remote = info[:remote] || "origin"
remote_branch = info[:remote_branch] || tap.git_repo.origin_branch_name remote_branch = info[:remote_branch] || tap.git_repository.origin_branch_name
branch = info[:branch_name] branch = info[:branch_name]
commit_message = info[:commit_message] commit_message = info[:commit_message]
previous_branch = info[:previous_branch] || "-" previous_branch = info[:previous_branch] || "-"

View File

@ -18,9 +18,9 @@ If a formula in your tap has the same name as a Homebrew/homebrew-core formula t
## Installing ## Installing
If its on GitHub, users can install any of your formulae with `brew install user/repo/formula`. Homebrew will automatically add your `github.com/user/homebrew-repo` tap before installing the formula. `user/repo/formula` points to the `github.com/user/homebrew-repo/**/formula.rb` file here. If its on GitHub, users can install any of your formulae with `brew install user/repo/formula`. Homebrew will automatically add your `github.com/user/homebrew-repository` tap before installing the formula. `user/repo/formula` points to the `github.com/user/homebrew-repo/**/formula.rb` file here.
To install your tap without installing any formula at the same time, users can add it with the [`brew tap` command](Taps.md). If its on GitHub, they can use `brew tap user/repo`, where `user` is your GitHub username and `homebrew-repo` is your repository. If its hosted outside of GitHub, they have to use `brew tap user/repo <URL>`, where `user` and `repo` will be used to refer to your tap and `<URL>` is your Git clone URL. To install your tap without installing any formula at the same time, users can add it with the [`brew tap` command](Taps.md). If its on GitHub, they can use `brew tap user/repository`, where `user` is your GitHub username and `homebrew-repository` is your repository. If its hosted outside of GitHub, they have to use `brew tap user/repo <URL>`, where `user` and `repository` will be used to refer to your tap and `<URL>` is your Git clone URL.
Users can then install your formulae either with `brew install foo` if theres no core formula with the same name, or with `brew install user/repo/foo` to avoid conflicts. Users can then install your formulae either with `brew install foo` if theres no core formula with the same name, or with `brew install user/repo/foo` to avoid conflicts.