Skip to content

Commit 515b31d

Browse files
committed
bump: fix newer_than_upstream comparison
The `newer_than_upstream` booleans can be incorrect when there's one current version but multiple new versions or vice versa. This occurs because the related comparisons are strictly done between the same `BumpVersionParser` values and it doesn't work as expected in this scenario (i.e., the `:arm`/`:intel` values are `nil` when `:general` is used for the version and vice versa). This adds additional logic to define which comparisons are used depending on whether the current and/or new versions have multiple versions, notably comparing against the `:general` version when there's a difference between current and new. One caveat is that `bump` will fall back to the `newer_than_upstream[:arm]` value when the current version uses one version and `:general` isn't present (as is the case when `multiple_versions[:new]` is true) but this aligns with other usage of ARM as the favored arch in `bump` and `bump-cask-pr`. This isn't the most elegant solution overall but it works as expected (I wasn't able to achieve the same result through more modest modifications, not to say that it's not possible).
1 parent ef2e8ce commit 515b31d

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Library/Homebrew/dev-cmd/bump.rb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,35 @@ def retrieve_versions_by_arch(formula_or_cask:, repositories:, name:)
405405
new_version = BumpVersionParser.new(general: "unable to get versions")
406406
end
407407

408+
comparison_pairs = []
409+
if !multiple_versions[:current] && !multiple_versions[:new]
410+
comparison_pairs << [:general, :general]
411+
elsif multiple_versions[:current] && multiple_versions[:new]
412+
comparison_pairs << [:arm, :arm]
413+
comparison_pairs << [:intel, :intel]
414+
elsif multiple_versions[:current]
415+
comparison_pairs << [:arm, :general]
416+
comparison_pairs << [:intel, :general]
417+
elsif multiple_versions[:new]
418+
comparison_pairs << [:general, :arm]
419+
comparison_pairs << [:general, :intel]
420+
end
421+
408422
newer_than_upstream = {}
409-
BumpVersionParser::VERSION_SYMBOLS.each do |version_type|
410-
new_version_value = new_version.send(version_type)
423+
comparison_pairs.each do |current_version_type, new_version_type|
424+
current_version_value = current_version.send(current_version_type)
425+
next unless current_version_value.is_a?(Version)
426+
427+
new_version_value = new_version.send(new_version_type)
411428
next unless new_version_value.is_a?(Version)
412429

430+
version_type = if !multiple_versions[:current] && multiple_versions[:new]
431+
new_version_type
432+
else
433+
current_version_type
434+
end
435+
413436
newer_than_upstream[version_type] =
414-
(current_version_value = current_version.send(version_type)).is_a?(Version) &&
415437
(Livecheck::LivecheckVersion.create(formula_or_cask, current_version_value) >
416438
Livecheck::LivecheckVersion.create(formula_or_cask, new_version_value))
417439
end
@@ -497,7 +519,7 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
497519
"#{" (deprecated)" if deprecated[:intel]}"
498520
else
499521
"#{current_version.general}" \
500-
"#{NEWER_THAN_UPSTREAM_MSG if newer_than_upstream[:general]}" \
522+
"#{NEWER_THAN_UPSTREAM_MSG if newer_than_upstream[:general] || newer_than_upstream[:arm]}" \
501523
"#{" (deprecated)" if deprecated[:general]}"
502524
end
503525

0 commit comments

Comments
 (0)