From 724e14ee25c833215e78730dc93ad73490c00c9b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 12 Jan 2024 14:18:00 +0000 Subject: [PATCH] formula_auditor: split `audit_revision_and_version_scheme`. Separate this into two methods so we can have separate skips for each. --- Library/Homebrew/formula_auditor.rb | 32 +++++++++++------ Library/Homebrew/test/dev-cmd/audit_spec.rb | 38 +++++++++++++++++++-- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 035c491c3d..66b6fc60f8 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -797,7 +797,7 @@ module Homebrew end end - def audit_revision_and_version_scheme + def audit_revision new_formula_problem("New formulae should not define a revision.") if @new_formula && !formula.revision.zero? return unless @git @@ -806,20 +806,10 @@ module Homebrew return if formula.stable.blank? current_version = formula.stable.version - current_version_scheme = formula.version_scheme current_revision = formula.revision previous_committed, newest_committed = committed_version_info - unless previous_committed[:version_scheme].nil? - if current_version_scheme < previous_committed[:version_scheme] - problem "version_scheme should not decrease (from #{previous_committed[:version_scheme]} " \ - "to #{current_version_scheme})" - elsif current_version_scheme > (previous_committed[:version_scheme] + 1) - problem "version_schemes should only increment by 1" - end - end - if (previous_committed[:version] != newest_committed[:version] || current_version != newest_committed[:version]) && !current_revision.zero? && @@ -836,6 +826,26 @@ module Homebrew end end + def audit_version_scheme + return unless @git + return unless formula.tap # skip formula not from core or any taps + return unless formula.tap.git? # git log is required + return if formula.stable.blank? + + current_version_scheme = formula.version_scheme + + previous_committed, = committed_version_info + + return if previous_committed[:version_scheme].nil? + + if current_version_scheme < previous_committed[:version_scheme] + problem "version_scheme should not decrease (from #{previous_committed[:version_scheme]} " \ + "to #{current_version_scheme})" + elsif current_version_scheme > (previous_committed[:version_scheme] + 1) + problem "version_schemes should only increment by 1" + end + end + def audit_unconfirmed_checksum_change return unless @git return unless formula.tap # skip formula not from core or any taps diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index cf0d39c095..88ddb2ad2e 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -961,10 +961,10 @@ module Homebrew end end - describe "#audit_revision_and_version_scheme" do + describe "#audit_revision" do subject do fa = described_class.new(Formulary.factory(formula_path), git: true) - fa.audit_revision_and_version_scheme + fa.audit_revision fa.problems.first&.fetch(:message) end @@ -1001,7 +1001,7 @@ module Homebrew end RUBY - fa.audit_revision_and_version_scheme + fa.audit_revision expect(fa.new_formula_problems).to include( a_hash_including(message: a_string_matching(/should not define a revision/)), @@ -1083,6 +1083,38 @@ module Homebrew it { is_expected.to be_nil } end end + end + + describe "#audit_version_scheme" do + subject do + fa = described_class.new(Formulary.factory(formula_path), git: true) + fa.audit_version_scheme + fa.problems.first&.fetch(:message) + end + + before do + origin_formula_path.dirname.mkpath + origin_formula_path.write <<~RUBY + class Foo#{foo_version} < Formula + url "https://brew.sh/foo-1.0.tar.gz" + sha256 "31cccfc6630528db1c8e3a06f6decf2a370060b982841cfab2b8677400a5092e" + revision 2 + version_scheme 1 + end + RUBY + + origin_tap_path.mkpath + origin_tap_path.cd do + system "git", "init" + system "git", "add", "--all" + system "git", "commit", "-m", "init" + end + + tap_path.mkpath + tap_path.cd do + system "git", "clone", origin_tap_path, "." + end + end describe "version_schemes" do describe "should not decrease with the same version" do