From abc591e702620a26a7c6aa6710c90433f38b59e3 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 23 Feb 2024 15:05:37 +0100 Subject: [PATCH 1/2] Simplify `Tap#custom_remote?`. --- Library/Homebrew/tap.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 31f53fe8b35fe..68b470677e582 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -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}. From e369689794421535ffe5efaf752ec98b462bd676 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 4 Mar 2024 14:47:57 +0100 Subject: [PATCH 2/2] Add test for `Tap#custom_remote?`. --- Library/Homebrew/test/tap_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Library/Homebrew/test/tap_spec.rb b/Library/Homebrew/test/tap_spec.rb index 0fd9fb11d9181..cc7b7f5edaa1f 100644 --- a/Library/Homebrew/test/tap_spec.rb +++ b/Library/Homebrew/test/tap_spec.rb @@ -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) { "git@github.com:Homebrew/homebrew-services" } + + its(:custom_remote?) { is_expected.to be true } + end + end + specify "Git variant" do touch path/"README" setup_git_repo