From c033a4673cfacf219a75e4649b777fefef91734c Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Mon, 23 Oct 2023 19:17:35 -0700 Subject: [PATCH] dev-cmd/bump-cask-pr: replace url before downloading files Previously it was possible for both the version and url to be changed. This would cause the old url to be used to download the cask and check the checksum since the version and checksum were replaced in the cask first and then the url would be replaced. This meant that the resulting checksum was wrong if a url was provided and might be completely invalid if it was interpolated. --- Library/Homebrew/dev-cmd/bump-cask-pr.rb | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-cask-pr.rb b/Library/Homebrew/dev-cmd/bump-cask-pr.rb index 91cd4da0c4852..cc0f8c0d120ac 100644 --- a/Library/Homebrew/dev-cmd/bump-cask-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-cask-pr.rb @@ -116,22 +116,6 @@ def bump_cask_pr branch_name = "bump-#{cask.token}" commit_message = nil - if new_version.present? - # For simplicity, our naming defers to the arm version if we multiple architectures are specified - branch_version = new_version.arm || new_version.general - if branch_version.is_a?(Cask::DSL::Version) - commit_version = if branch_version.before_comma == cask.version.before_comma - branch_version - else - branch_version.before_comma - end - branch_name = "bump-#{cask.token}-#{branch_version.tr(",:", "-")}" - commit_message ||= "#{cask.token} #{commit_version}" - end - replacement_pairs = replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs) - end - # Now that we have all replacement pairs, we will replace them further down - old_contents = File.read(cask.sourcefile_path) if new_base_url @@ -148,6 +132,22 @@ def bump_cask_pr ] end + if new_version.present? + # For simplicity, our naming defers to the arm version if we multiple architectures are specified + branch_version = new_version.arm || new_version.general + if branch_version.is_a?(Cask::DSL::Version) + commit_version = if branch_version.before_comma == cask.version.before_comma + branch_version + else + branch_version.before_comma + end + branch_name = "bump-#{cask.token}-#{branch_version.tr(",:", "-")}" + commit_message ||= "#{cask.token} #{commit_version}" + end + replacement_pairs = replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs) + end + # Now that we have all replacement pairs, we will replace them further down + commit_message ||= "#{cask.token}: update checksum" if new_hash # Remove nested arrays where elements are identical