buo / homebrew-cask-upgrade

A command line tool for upgrading every outdated app installed by Homebrew Cask
MIT License
2.39k stars 89 forks source link

Fix `undefined method versions for #<Cask` #236

Closed jcsanti closed 10 months ago

jcsanti commented 10 months ago

fixes #231

To fix this error, I believe we should simply use the Cask::Cask#installed_version method instead of calling .versions.first on the cask variable in Bcu::Pin::Add#run_add_pin.

Here are the steps to reproduce+fix the issue on your side.

brew info --cask deepl
# ==> deepl: 4.5.542015 (auto_updates)
# https://www.deepl.com/
# /opt/homebrew/Caskroom/deepl/4.4.513804 (119B)

brew cu pin deepl
# Error: undefined method `versions' for #<Cask deepl>

At this stage, simply apply the fix to your local install of homebrew-cask-upgrade:

# macOS/BSD syntax
sed -i '' -E 's/(cask\.)versions\.first/\1installed_version/' \
  "$HOMEBREW_REPOSITORY/Library/Taps/buo/homebrew-cask-upgrade/lib/bcu/command/pin_add.rb"

Pinning should now be working again:

brew cu unpin deepl
# Unpinned: deepl

brew cu pin deepl
# Pinned: deepl in version 4.4.513804

(optionally) Clean your local install (which reverts to the broken version):

cd "$HOMEBREW_REPOSITORY/Library/Taps/buo/homebrew-cask-upgrade/" && git checkout -- .