From f23d0ce37376f2e2c32788e9d7284e208cc942d3 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:21:42 -0400 Subject: [PATCH] livecheck: convert head-only strings to Versions `brew livecheck` currently gives a Sorbet type error when run on a HEAD-only formula: `Parameter 'version': Expected type Version, got type String with value "c06c10d"`. This happens because the `current` and `latest` values are strings but `LivecheckVersion#create` expects a `Version` object. This addresses the issue by creating a `Version` object from the related commit strings. This ensures that the type of these variables is more uniform, which makes them easier to reason about. --- Library/Homebrew/livecheck/livecheck.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 51b6fe6bbf..3203bf7f72 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -270,7 +270,7 @@ module Homebrew # comparison. current = if formula if formula.head_only? - formula.any_installed_version.version.commit + Version.new(formula.any_installed_version.version.commit) else T.must(formula.stable).version end @@ -279,10 +279,10 @@ module Homebrew end current_str = current.to_s - current = LivecheckVersion.create(formula_or_cask, current) unless formula&.head_only? + current = LivecheckVersion.create(formula_or_cask, current) latest = if formula&.head_only? - T.must(formula.head).downloader.fetch_last_commit + Version.new(T.must(formula.head).downloader.fetch_last_commit) else version_info = latest_version( formula_or_cask, @@ -345,7 +345,7 @@ module Homebrew end latest_str = latest.to_s - latest = LivecheckVersion.create(formula_or_cask, latest) unless formula&.head_only? + latest = LivecheckVersion.create(formula_or_cask, latest) is_outdated = if formula&.head_only? # A HEAD-only formula is considered outdated if the latest upstream