Skip to content

Commit

Permalink
Merge pull request #6194 from reitermarkus/brew-cask-upgrade
Browse files Browse the repository at this point in the history
Output all upgradable casks before upgrading.
  • Loading branch information
reitermarkus authored May 31, 2019
2 parents 4ce405f + e2369fc commit 7640dfe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 14 additions & 8 deletions Library/Homebrew/cask/cmd/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,28 @@ def run
ohai "Casks with `auto_updates` or `version :latest` will not be upgraded" if args.empty? && !greedy?
oh1 "Upgrading #{outdated_casks.count} #{"outdated package".pluralize(outdated_casks.count)}:"
caught_exceptions = []
outdated_casks.each do |cask|

upgradable_casks = outdated_casks.map { |c| [CaskLoader.load(c.installed_caskfile), c] }

puts upgradable_casks
.map { |(old_cask, new_cask)| "#{new_cask.full_name} #{old_cask.version} -> #{new_cask.version}" }
.join(", ")

upgradable_casks.each do |(old_cask, new_cask)|
begin
old_cask = CaskLoader.load(cask.installed_caskfile)
puts "#{cask.full_name} #{old_cask.version} -> #{cask.version}"
upgrade_cask(old_cask)
upgrade_cask(old_cask, new_cask)
rescue CaskError => e
caught_exceptions << e
next
end
end

return if caught_exceptions.empty?
raise MultipleCaskErrors, caught_exceptions if caught_exceptions.count > 1
raise caught_exceptions.first if caught_exceptions.count == 1
end

def upgrade_cask(old_cask)
def upgrade_cask(old_cask, new_cask)
odebug "Started upgrade process for Cask #{old_cask}"
old_config = old_cask.config

Expand All @@ -59,8 +65,6 @@ def upgrade_cask(old_cask)
force: force?,
upgrade: true)

new_cask = CaskLoader.load(old_cask.token)

new_cask.config = Config.global.merge(old_config)

new_cask_installer =
Expand All @@ -76,10 +80,12 @@ def upgrade_cask(old_cask)
new_artifacts_installed = false

begin
oh1 "Upgrading #{Formatter.identifier(old_cask)}"

# Start new Cask's installation steps
new_cask_installer.check_conflicts

puts new_cask_installer.caveats
puts new_cask_installer.caveats if new_cask_installer.caveats

new_cask_installer.fetch

Expand Down
2 changes: 0 additions & 2 deletions Library/Homebrew/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,6 @@ def remove_config_file
end

def start_upgrade
oh1 "Starting upgrade for Cask #{Formatter.identifier(@cask)}"

uninstall_artifacts
backup
end
Expand Down

0 comments on commit 7640dfe

Please sign in to comment.