Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Tap#custom_remote?. #16778

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,11 @@ def uninstall(manual: false)
end

# True if the {#remote} of {Tap} is customized.
sig { returns(T::Boolean) }
def custom_remote?
return true unless remote
return true unless (remote = self.remote)

remote.casecmp(default_remote).nonzero?
!remote.casecmp(default_remote).zero?
end

# Path to the directory of all {Formula} files for this {Tap}.
Expand Down
31 changes: 31 additions & 0 deletions Library/Homebrew/test/tap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,37 @@ def setup_completion(link:)
end
end

describe "#custom_remote?" do
subject(:tap) { described_class.new("Homebrew", "services") }

let(:remote) { nil }

before do
tap.path.mkpath
system "git", "-C", tap.path, "init"
system "git", "-C", tap.path, "remote", "add", "origin", remote if remote
end

context "if no remote is available" do
it "returns true" do
expect(tap.remote).to be_nil
expect(tap.custom_remote?).to be true
end
end

context "when using the default remote" do
let(:remote) { "https://github.com/Homebrew/homebrew-services" }

its(:custom_remote?) { is_expected.to be false }
end

context "when using a non-default remote" do
let(:remote) { "[email protected]:Homebrew/homebrew-services" }

its(:custom_remote?) { is_expected.to be true }
end
end

specify "Git variant" do
touch path/"README"
setup_git_repo
Expand Down