mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
formula_auditor: split audit_revision_and_version_scheme
.
Separate this into two methods so we can have separate skips for each.
This commit is contained in:
parent
dca9ff865a
commit
724e14ee25
@ -797,7 +797,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
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?
|
new_formula_problem("New formulae should not define a revision.") if @new_formula && !formula.revision.zero?
|
||||||
|
|
||||||
return unless @git
|
return unless @git
|
||||||
@ -806,20 +806,10 @@ module Homebrew
|
|||||||
return if formula.stable.blank?
|
return if formula.stable.blank?
|
||||||
|
|
||||||
current_version = formula.stable.version
|
current_version = formula.stable.version
|
||||||
current_version_scheme = formula.version_scheme
|
|
||||||
current_revision = formula.revision
|
current_revision = formula.revision
|
||||||
|
|
||||||
previous_committed, newest_committed = committed_version_info
|
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] ||
|
if (previous_committed[:version] != newest_committed[:version] ||
|
||||||
current_version != newest_committed[:version]) &&
|
current_version != newest_committed[:version]) &&
|
||||||
!current_revision.zero? &&
|
!current_revision.zero? &&
|
||||||
@ -836,6 +826,26 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
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
|
def audit_unconfirmed_checksum_change
|
||||||
return unless @git
|
return unless @git
|
||||||
return unless formula.tap # skip formula not from core or any taps
|
return unless formula.tap # skip formula not from core or any taps
|
||||||
|
@ -961,10 +961,10 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#audit_revision_and_version_scheme" do
|
describe "#audit_revision" do
|
||||||
subject do
|
subject do
|
||||||
fa = described_class.new(Formulary.factory(formula_path), git: true)
|
fa = described_class.new(Formulary.factory(formula_path), git: true)
|
||||||
fa.audit_revision_and_version_scheme
|
fa.audit_revision
|
||||||
fa.problems.first&.fetch(:message)
|
fa.problems.first&.fetch(:message)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1001,7 +1001,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
fa.audit_revision_and_version_scheme
|
fa.audit_revision
|
||||||
|
|
||||||
expect(fa.new_formula_problems).to include(
|
expect(fa.new_formula_problems).to include(
|
||||||
a_hash_including(message: a_string_matching(/should not define a revision/)),
|
a_hash_including(message: a_string_matching(/should not define a revision/)),
|
||||||
@ -1083,6 +1083,38 @@ module Homebrew
|
|||||||
it { is_expected.to be_nil }
|
it { is_expected.to be_nil }
|
||||||
end
|
end
|
||||||
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 "version_schemes" do
|
||||||
describe "should not decrease with the same version" do
|
describe "should not decrease with the same version" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user