Skip to content

Commit

Permalink
Use repository consistently instead of repo
Browse files Browse the repository at this point in the history
The documentation linting job doesn't like `repo` so let's fix this
globally rather than naming it differently in documentation and code.
  • Loading branch information
MikeMcQuaid committed Jun 10, 2024
1 parent f8b1d1f commit d8b2e5b
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Library/Homebrew/attestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def self.gh_executable

# Verifies the given bottle against a cryptographic attestation of build provenance.
#
# The provenance is verified as originating from `signing_repo`, which is a `String`
# that should be formatted as a GitHub `owner/repo`.
# The provenance is verified as originating from `signing_repository`, which is a `String`
# that should be formatted as a GitHub `owner/repository`.
#
# Callers may additionally pass in `signing_workflow`, which will scope the attestation
# down to an exact GitHub Actions workflow, in
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def output_update_report

updated_taps = []
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?

if ENV["HOMEBREW_MIGRATE_LINUXBREW_FORMULAE"].present? && tap.core_tap? &&
Expand Down Expand Up @@ -321,7 +321,7 @@ def tap_or_untap_core_taps_if_necessary
next unless tap.installed?

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)

Check warning on line 324 in Library/Homebrew/cmd/update-report.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/update-report.rb#L324

Added line #L324 was not covered by tests
ohai "#{tap.name} is old and unneeded, untapping to save space..."
tap.uninstall
else
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/bump-formula-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def run

tap_remote_repo = formula.tap.full_name || formula.tap.remote_repo
remote = "origin"
remote_branch = formula.tap.git_repo.origin_branch_name
remote_branch = formula.tap.git_repository.origin_branch_name

Check warning on line 133 in Library/Homebrew/dev-cmd/bump-formula-pr.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bump-formula-pr.rb#L133

Added line #L133 was not covered by tests
previous_branch = "-"

check_open_pull_requests(formula, tap_remote_repo)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run
end
odie "Could not find #{name}! The formula or version may not have existed." if test_formula.nil?
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|
Pathname.glob("#{dir}/#{name}.rb").find(&:file?)
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/pr-pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def run
_, user, repo, pr = *url_match
odie "Not a GitHub pull request: #{arg}" unless pr

git_repo = tap.git_repo
git_repo = tap.git_repository

Check warning on line 98 in Library/Homebrew/dev-cmd/pr-pull.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/pr-pull.rb#L98

Added line #L98 was not covered by tests
if !git_repo.default_origin_branch? && !args.branch_okay? && !args.no_commit? && !args.no_cherry_pick?
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}?"
Expand Down Expand Up @@ -341,7 +341,7 @@ def squash_package_commits(commits, file, git_repo:, reason: "", verbose: 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)
git_repo = tap.git_repo
git_repo = tap.git_repository
original_head = git_repo.head_ref

commits = Utils.safe_popen_read("git", "-C", tap.path, "rev-list",
Expand Down
12 changes: 6 additions & 6 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def please_create_pull_requests(what = "unsupported configuration")

sig { params(repository_path: GitRepository, desired_origin: String).returns(T.nilable(String)) }
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

Expand Down Expand Up @@ -156,7 +156,7 @@ def broken_tap(tap)
return unless Utils::Git.available?

repo = GitRepository.new(HOMEBREW_REPOSITORY)
return unless repo.git_repo?
return unless repo.git_repository?

message = <<~EOS
#{tap.full_name} was not tapped properly! Run:
Expand Down Expand Up @@ -528,14 +528,14 @@ def check_coretap_integrity
core_tap.ensure_installed!
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)

Check warning on line 531 in Library/Homebrew/diagnostic.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/diagnostic.rb#L531

Added line #L531 was not covered by tests
end

def check_casktap_integrity
core_cask_tap = CoreCaskTap.instance
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)

Check warning on line 538 in Library/Homebrew/diagnostic.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/diagnostic.rb#L538

Added line #L538 was not covered by tests
end

sig { returns(T.nilable(String)) }
Expand All @@ -544,9 +544,9 @@ def check_tap_git_branch
return unless Utils::Git.available?

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}"

Check warning on line 549 in Library/Homebrew/diagnostic.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/diagnostic.rb#L549

Added line #L549 was not covered by tests
end

return if commands.blank?
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/git_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ def initialize(pathname)
end

sig { returns(T::Boolean) }
def git_repo?
def git_repository?
pathname.join(".git").exist?
end
# odeprecated: use git_repository? instead
alias git_repo? git_repository?

# Gets the URL of the Git origin remote.
sig { returns(T.nilable(String)) }
Expand Down
70 changes: 37 additions & 33 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

# 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
# a GitHub repository with the name of `user/homebrew-repo`. In such
# cases, `user/repo` will be used as the {#name} of this {Tap}, where
# {#user} represents the GitHub username and {#repo} represents the repository
# name without the leading `homebrew-`.
# a GitHub repository with the name of `user/homebrew-repository`. In such
# cases, `user/repository` will be used as the {#name} of this {Tap}, where
# {#user} represents the GitHub username and {#repository} represents the
# repository name without the leading `homebrew-`.
class Tap
extend Cachable

Expand Down Expand Up @@ -160,11 +160,13 @@ def self.forbidden_taps
# The repository name of this {Tap} without the leading `homebrew-`.
#
# @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.
# {#name} is always in lowercase.
# e.g. `user/repo`
# e.g. `user/repository`
#
# @api public
attr_reader :name
Expand All @@ -175,38 +177,38 @@ def to_s = name

# The full name of this {Tap}, including the `homebrew-` prefix.
# It combines {#user} and 'homebrew-'-prefixed {#repo} with a slash.
# e.g. `user/homebrew-repo`
# e.g. `user/homebrew-repository`
#
# @api public
attr_reader :full_name

# 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
sig { returns(Pathname) }
attr_reader :path

# The git repository of this {Tap}.
sig { returns(GitRepository) }
attr_reader :git_repo
attr_reader :git_repository

# Always use `Tap.fetch` instead of `Tap.new`.
private_class_method :new

def initialize(user, repo)
def initialize(user, repository)
@user = user
@repo = repo
@name = "#{@user}/#{@repo}".downcase
@full_name = "#{@user}/homebrew-#{@repo}"
@repository = repository
@name = "#{@user}/#{@repository}".downcase
@full_name = "#{@user}/homebrew-#{@repository}"
@path = TAP_DIRECTORY/@full_name.downcase
@git_repo = GitRepository.new(@path)
@git_repository = GitRepository.new(@path)
end

# Clear internal cache.
def clear_cache
@remote = nil
@repo_var_suffix = nil
@repository_var_suffix = nil
remove_instance_variable(:@private) if instance_variable_defined?(:@private)

@formula_dir = nil
Expand Down Expand Up @@ -253,17 +255,17 @@ def ensure_installed!
end

# The remote path to this {Tap}.
# e.g. `https://github.com/user/homebrew-repo`
# e.g. `https://github.com/user/homebrew-repository`
#
# @api public
def remote
return default_remote unless installed?

@remote ||= git_repo.origin_url
@remote ||= git_repository.origin_url
end

# The remote repository name of this {Tap}.
# e.g. `user/homebrew-repo`
# e.g. `user/homebrew-repository`
#
# @api public
sig { returns(T.nilable(String)) }
Expand All @@ -282,18 +284,20 @@ def default_remote
end

sig { returns(String) }
def repo_var_suffix
@repo_var_suffix ||= path.to_s
.delete_prefix(TAP_DIRECTORY.to_s)
.tr("^A-Za-z0-9", "_")
.upcase
def repository_var_suffix
@repository_var_suffix ||= path.to_s
.delete_prefix(TAP_DIRECTORY.to_s)
.tr("^A-Za-z0-9", "_")
.upcase
end
# odeprecated: use repository_var_suffix instead.
alias repo_var_suffix repository_var_suffix

# Check whether this {Tap} is a Git repository.
#
# @api public
def git?
git_repo.git_repo?
git_repository.git_repository?
end

# Git branch for this {Tap}.
Expand All @@ -302,7 +306,7 @@ def git?
def git_branch
raise TapUnavailableError, name unless installed?

git_repo.branch_name
git_repository.branch_name
end

# Git HEAD for this {Tap}.
Expand All @@ -311,7 +315,7 @@ def git_branch
def git_head
raise TapUnavailableError, name unless installed?

@git_head ||= git_repo.head_ref
@git_head ||= git_repository.head_ref
end

# Time since last git commit for this {Tap}.
Expand All @@ -320,7 +324,7 @@ def git_head
def git_last_commit
raise TapUnavailableError, name unless installed?

git_repo.last_committed
git_repository.last_committed
end

# The issues URL of this {Tap}.
Expand Down Expand Up @@ -564,22 +568,22 @@ def fix_remote_configuration(requested_remote: nil, quiet: false)
end
return unless remote

current_upstream_head = T.must(git_repo.origin_branch_name)
return if requested_remote.blank? && git_repo.origin_has_branch?(current_upstream_head)
current_upstream_head = T.must(git_repository.origin_branch_name)

Check warning on line 571 in Library/Homebrew/tap.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap.rb#L571

Added line #L571 was not covered by tests
return if requested_remote.blank? && git_repository.origin_has_branch?(current_upstream_head)

args = %w[fetch]
args << "--quiet" if quiet
args << "origin"
args << "+refs/heads/*:refs/remotes/origin/*"
safe_system "git", "-C", path, *args
git_repo.set_head_origin_auto
git_repository.set_head_origin_auto

Check warning on line 579 in Library/Homebrew/tap.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap.rb#L579

Added line #L579 was not covered by tests

new_upstream_head = T.must(git_repo.origin_branch_name)
new_upstream_head = T.must(git_repository.origin_branch_name)

Check warning on line 581 in Library/Homebrew/tap.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap.rb#L581

Added line #L581 was not covered by tests
return if new_upstream_head == current_upstream_head

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_repo.set_upstream_branch local: new_upstream_head, origin: new_upstream_head
git_repository.rename_branch old: current_upstream_head, new: new_upstream_head
git_repository.set_upstream_branch local: new_upstream_head, origin: new_upstream_head

Check warning on line 586 in Library/Homebrew/tap.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap.rb#L585-L586

Added lines #L585 - L586 were not covered by tests

return if quiet

Expand Down
12 changes: 6 additions & 6 deletions Library/Homebrew/test/dev-cmd/pr-pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class Foo < Formula
File.write(formula_file, formula_version)
safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}"
pr_pull.autosquash!(original_hash, tap:)
expect(tap.git_repo.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("foo 2.0")
expect(tap.git_repository.commit_message).to include("Co-authored-by: #{secondary_author}")
end

(path/"Casks").mkpath
Expand Down Expand Up @@ -130,17 +130,17 @@ class Foo < Formula
safe_system Utils::Git.git, "add", formula_file
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
end
pr_pull.signoff!(tap.git_repo)
expect(tap.git_repo.commit_message).to include("Signed-off-by:")
pr_pull.signoff!(tap.git_repository)
expect(tap.git_repository.commit_message).to include("Signed-off-by:")

(path/"Casks").mkpath
cask_file.write(cask)
cd path do
safe_system Utils::Git.git, "add", cask_file
safe_system Utils::Git.git, "commit", "-m", "food 1.0 (new cask)"
end
pr_pull.signoff!(tap.git_repo)
expect(tap.git_repo.commit_message).to include("Signed-off-by:")
pr_pull.signoff!(tap.git_repository)
expect(tap.git_repository.commit_message).to include("Signed-off-by:")
end
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def self.create_bump_pr(info, args:)
old_contents = info[:old_contents]
additional_files = info[:additional_files] || []
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

Check warning on line 698 in Library/Homebrew/utils/github.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/github.rb#L698

Added line #L698 was not covered by tests
branch = info[:branch_name]
commit_message = info[:commit_message]
previous_branch = info[:previous_branch] || "-"
Expand Down
4 changes: 2 additions & 2 deletions docs/How-to-Create-and-Maintain-a-Tap.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ If a formula in your tap has the same name as a Homebrew/homebrew-core formula t

## Installing

If it’s 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 it’s 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 it’s on GitHub, they can use `brew tap user/repo`, where `user` is your GitHub username and `homebrew-repo` is your repository. If it’s 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 it’s on GitHub, they can use `brew tap user/repository`, where `user` is your GitHub username and `homebrew-repository` is your repository. If it’s 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 there’s no core formula with the same name, or with `brew install user/repo/foo` to avoid conflicts.

Expand Down

0 comments on commit d8b2e5b

Please sign in to comment.