diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index a3736fede8..1a53d2e88a 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -154,6 +154,20 @@ module Homebrew end end + # Optimization for the core tap which has many monthly commits + if tap.core_tap? + # Check if the formula has been deleted in the last month. + diff_command = ["git", "diff", "--diff-filter=D", "--name-only", + "@{'1 month ago'}", "--", relative_path] + deleted_formula = Utils.popen_read(*diff_command) + + if deleted_formula.blank? + ofail "No previously deleted formula found." unless silent + return + end + end + + # Find commit where formula was deleted in the last month. log_command = "git log --since='1 month ago' --diff-filter=D " \ "--name-only --max-count=1 " \ "--format=%H\\\\n%h\\\\n%B -- #{relative_path}" diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb index cd95bc393e..d93851f460 100644 --- a/Library/Homebrew/test/missing_formula_spec.rb +++ b/Library/Homebrew/test/missing_formula_spec.rb @@ -75,16 +75,28 @@ describe Homebrew::MissingFormula do end end - context "with a deleted formula" do - let(:formula) { "homebrew/foo/deleted-formula" } + shared_examples "it detects deleted formulae" do + context "with a deleted formula" do + let(:formula) { "homebrew/foo/deleted-formula" } - it { is_expected.not_to be_nil } + it { is_expected.not_to be_nil } + end + + context "with a formula that never existed" do + let(:formula) { "homebrew/foo/missing-formula" } + + it { is_expected.to be_nil } + end end - context "with a formula that never existed" do - let(:formula) { "homebrew/foo/missing-formula" } + include_examples "it detects deleted formulae" - it { is_expected.to be_nil } + describe "on the core tap" do + before do + allow_any_instance_of(Tap).to receive(:core_tap?).and_return(true) + end + + include_examples "it detects deleted formulae" end end