From bb1be7ef9dce0fda31200d6098bbffde0023c53e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 26 Aug 2020 16:03:47 +0200 Subject: [PATCH 1/2] Call `clear_available_cache` before and after `Git` specs. --- Library/Homebrew/test/utils/git_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index c44c2340ce..d2f28b90d8 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -3,9 +3,14 @@ require "utils/git" describe Utils::Git do - before do + around do |example| described_class.clear_available_cache + example.run + ensure + described_class.clear_available_cache + end + before do git = HOMEBREW_SHIMS_PATH/"scm/git" HOMEBREW_CACHE.cd do From 0129247391955d9ff98196cdf4b816aaa9ec3f13 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 27 Aug 2020 10:09:33 +0200 Subject: [PATCH 2/2] Refuse to install Git if `HOMEBREW_TEST_GENERIC_OS` is set. --- Library/Homebrew/test/utils/git_spec.rb | 2 ++ Library/Homebrew/utils/git.rb | 13 ++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index d2f28b90d8..3212eb8bf5 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -150,6 +150,8 @@ describe Utils::Git do end it "installs git" do + skip if ENV["HOMEBREW_TEST_GENERIC_OS"] + expect(described_class).to receive(:available?).and_return(false) expect(described_class).to receive(:safe_system).with(HOMEBREW_BREW_FILE, "install", "git").and_return(true) expect(described_class).to receive(:available?).and_return(true) diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 334a2c7281..56727092dd 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -94,13 +94,12 @@ module Utils begin oh1 "Installing #{Formatter.identifier("git")}" - # We need to unset `HOMEBREW_TEST_GENERIC_OS`, otherwise `git` will be - # installed from source in tests that need it. This is slow and will - # also likely fail due to `OS::Linux` and `OS::Mac` being undefined. - with_env "HOMEBREW_TEST_GENERIC_OS" => nil do - safe_system HOMEBREW_BREW_FILE, "install", "git" - clear_available_cache - end + # Otherwise `git` will be installed from source in tests that need it. This is slow + # and will also likely fail due to `OS::Linux` and `OS::Mac` being undefined. + raise "Refusing to install Git on a generic OS." if ENV["HOMEBREW_TEST_GENERIC_OS"] + + safe_system HOMEBREW_BREW_FILE, "install", "git" + clear_available_cache rescue raise "Git is unavailable" end