Skip to content

Commit

Permalink
Merge pull request #8496 from reitermarkus/debug-git
Browse files Browse the repository at this point in the history
Properly fix Git error in tests.
  • Loading branch information
reitermarkus committed Aug 29, 2020
2 parents 747223e + 0129247 commit a39aae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 8 additions & 1 deletion Library/Homebrew/test/utils/git_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -145,6 +150,8 @@
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)
Expand Down
13 changes: 6 additions & 7 deletions Library/Homebrew/utils/git.rb
Expand Up @@ -94,13 +94,12 @@ def ensure_installed!
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
Expand Down

0 comments on commit a39aae8

Please sign in to comment.