diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index b5093730bf..8041908da1 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -674,6 +674,8 @@ module Homebrew end def audit_revision_and_version_scheme + new_formula_problem("New formulae should not define a revision.") if @new_formula && !formula.revision.zero? + return unless @git return unless formula.tap # skip formula not from core or any taps return unless formula.tap.git? # git log is required diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index 4faf5b6536..27560df7fc 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -854,18 +854,12 @@ module Homebrew end describe "#audit_revision_and_version_scheme" do - subject { - fa = described_class.new(Formulary.factory(formula_path), git: true) - fa.audit_revision_and_version_scheme - fa.problems.first&.fetch(:message) - } - - let(:origin_tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } - let(:foo_version) { Count.increment } - let(:formula_subpath) { "Formula/foo#{foo_version}.rb" } - let(:origin_formula_path) { origin_tap_path/formula_subpath } - let(:tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-bar" } let(:formula_path) { tap_path/formula_subpath } + let(:tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-bar" } + let(:origin_formula_path) { origin_tap_path/formula_subpath } + let(:formula_subpath) { "Formula/foo#{foo_version}.rb" } + let(:foo_version) { Count.increment } + let(:origin_tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } before do origin_formula_path.dirname.mkpath @@ -891,6 +885,29 @@ module Homebrew end end + describe "new formulae should not have a revision" do + it "doesn't allow new formulae to have a revision" do + fa = formula_auditor "foo", <<~RUBY, new_formula: true + class Foo < Formula + url "https://brew.sh/foo-1.0.tgz" + revision 1 + end + RUBY + + fa.audit_revision_and_version_scheme + + expect(fa.new_formula_problems).to include( + a_hash_including(message: a_string_matching(/should not define a revision/)), + ) + end + end + + subject { + fa = described_class.new(Formulary.factory(formula_path), git: true) + fa.audit_revision_and_version_scheme + fa.problems.first&.fetch(:message) + } + def formula_gsub(before, after = "") text = formula_path.read text.gsub! before, after