Merge pull request #14913 from hyuraku/move-cask/cmd/upgrade-to-cask/upgrade
Move `cask/cmd/upgrade` to `cask/upgrade`
This commit is contained in:
commit
cb5e8298a2
@ -15,7 +15,6 @@ require "cask/cmd/fetch"
|
|||||||
require "cask/cmd/install"
|
require "cask/cmd/install"
|
||||||
require "cask/cmd/reinstall"
|
require "cask/cmd/reinstall"
|
||||||
require "cask/cmd/uninstall"
|
require "cask/cmd/uninstall"
|
||||||
require "cask/cmd/upgrade"
|
|
||||||
|
|
||||||
module Cask
|
module Cask
|
||||||
# Implementation of the `brew cask` command-line interface.
|
# Implementation of the `brew cask` command-line interface.
|
||||||
|
@ -1,257 +0,0 @@
|
|||||||
# typed: false
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require "env_config"
|
|
||||||
require "cask/config"
|
|
||||||
|
|
||||||
module Cask
|
|
||||||
class Cmd
|
|
||||||
# Cask implementation of the `brew upgrade` command.
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
class Upgrade < AbstractCommand
|
|
||||||
extend T::Sig
|
|
||||||
|
|
||||||
OPTIONS = [
|
|
||||||
[:switch, "--skip-cask-deps", {
|
|
||||||
description: "Skip installing cask dependencies.",
|
|
||||||
}],
|
|
||||||
[:switch, "-g", "--greedy", {
|
|
||||||
description: "Also include casks with `auto_updates true` or `version :latest`.",
|
|
||||||
}],
|
|
||||||
[:switch, "--greedy-latest", {
|
|
||||||
description: "Also include casks with `version :latest`.",
|
|
||||||
}],
|
|
||||||
[:switch, "--greedy-auto-updates", {
|
|
||||||
description: "Also include casks with `auto_updates true`.",
|
|
||||||
}],
|
|
||||||
].freeze
|
|
||||||
|
|
||||||
sig { returns(Homebrew::CLI::Parser) }
|
|
||||||
def self.parser
|
|
||||||
super do
|
|
||||||
switch "--force",
|
|
||||||
description: "Force overwriting existing files."
|
|
||||||
switch "--dry-run",
|
|
||||||
description: "Show what would be upgraded, but do not actually upgrade anything."
|
|
||||||
|
|
||||||
OPTIONS.map(&:dup).each do |option|
|
|
||||||
kwargs = option.pop
|
|
||||||
send(*option, **kwargs)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { void }
|
|
||||||
def run
|
|
||||||
verbose = ($stdout.tty? || args.verbose?) && !args.quiet?
|
|
||||||
self.class.upgrade_casks(
|
|
||||||
*casks,
|
|
||||||
force: args.force?,
|
|
||||||
greedy: args.greedy?,
|
|
||||||
greedy_latest: args.greedy_latest?,
|
|
||||||
greedy_auto_updates: args.greedy_auto_updates?,
|
|
||||||
dry_run: args.dry_run?,
|
|
||||||
binaries: args.binaries?,
|
|
||||||
quarantine: args.quarantine?,
|
|
||||||
require_sha: args.require_sha?,
|
|
||||||
skip_cask_deps: args.skip_cask_deps?,
|
|
||||||
verbose: verbose,
|
|
||||||
args: args,
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
sig {
|
|
||||||
params(
|
|
||||||
casks: Cask,
|
|
||||||
args: Homebrew::CLI::Args,
|
|
||||||
force: T.nilable(T::Boolean),
|
|
||||||
greedy: T.nilable(T::Boolean),
|
|
||||||
greedy_latest: T.nilable(T::Boolean),
|
|
||||||
greedy_auto_updates: T.nilable(T::Boolean),
|
|
||||||
dry_run: T.nilable(T::Boolean),
|
|
||||||
skip_cask_deps: T.nilable(T::Boolean),
|
|
||||||
verbose: T.nilable(T::Boolean),
|
|
||||||
binaries: T.nilable(T::Boolean),
|
|
||||||
quarantine: T.nilable(T::Boolean),
|
|
||||||
require_sha: T.nilable(T::Boolean),
|
|
||||||
).returns(T::Boolean)
|
|
||||||
}
|
|
||||||
def self.upgrade_casks(
|
|
||||||
*casks,
|
|
||||||
args:,
|
|
||||||
force: false,
|
|
||||||
greedy: false,
|
|
||||||
greedy_latest: false,
|
|
||||||
greedy_auto_updates: false,
|
|
||||||
dry_run: false,
|
|
||||||
skip_cask_deps: false,
|
|
||||||
verbose: false,
|
|
||||||
binaries: nil,
|
|
||||||
quarantine: nil,
|
|
||||||
require_sha: nil
|
|
||||||
)
|
|
||||||
|
|
||||||
quarantine = true if quarantine.nil?
|
|
||||||
|
|
||||||
outdated_casks = if casks.empty?
|
|
||||||
Caskroom.casks(config: Config.from_args(args)).select do |cask|
|
|
||||||
cask.outdated?(greedy: greedy, greedy_latest: greedy_latest,
|
|
||||||
greedy_auto_updates: greedy_auto_updates)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
casks.select do |cask|
|
|
||||||
raise CaskNotInstalledError, cask if !cask.installed? && !force
|
|
||||||
|
|
||||||
if cask.outdated?(greedy: true)
|
|
||||||
true
|
|
||||||
elsif cask.version.latest?
|
|
||||||
opoo "Not upgrading #{cask.token}, the downloaded artifact has not changed"
|
|
||||||
false
|
|
||||||
else
|
|
||||||
opoo "Not upgrading #{cask.token}, the latest version is already installed"
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
manual_installer_casks = outdated_casks.select do |cask|
|
|
||||||
cask.artifacts.any?(Artifact::Installer::ManualInstaller)
|
|
||||||
end
|
|
||||||
|
|
||||||
if manual_installer_casks.present?
|
|
||||||
count = manual_installer_casks.count
|
|
||||||
ofail "Not upgrading #{count} `installer manual` #{::Utils.pluralize("cask", count)}."
|
|
||||||
puts manual_installer_casks.map(&:to_s)
|
|
||||||
outdated_casks -= manual_installer_casks
|
|
||||||
end
|
|
||||||
|
|
||||||
return false if outdated_casks.empty?
|
|
||||||
|
|
||||||
if casks.empty? && !greedy
|
|
||||||
if !greedy_auto_updates && !greedy_latest
|
|
||||||
ohai "Casks with 'auto_updates true' or 'version :latest' " \
|
|
||||||
"will not be upgraded; pass `--greedy` to upgrade them."
|
|
||||||
end
|
|
||||||
if greedy_auto_updates && !greedy_latest
|
|
||||||
ohai "Casks with 'version :latest' will not be upgraded; pass `--greedy-latest` to upgrade them."
|
|
||||||
end
|
|
||||||
if !greedy_auto_updates && greedy_latest
|
|
||||||
ohai "Casks with 'auto_updates true' will not be upgraded; pass `--greedy-auto-updates` to upgrade them."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
verb = dry_run ? "Would upgrade" : "Upgrading"
|
|
||||||
oh1 "#{verb} #{outdated_casks.count} outdated #{::Utils.pluralize("package", outdated_casks.count)}:"
|
|
||||||
|
|
||||||
caught_exceptions = []
|
|
||||||
|
|
||||||
upgradable_casks = outdated_casks.map do |c|
|
|
||||||
if !c.installed_caskfile.exist? && c.tap.to_s == "homebrew/cask" &&
|
|
||||||
Homebrew::API::Cask.all_casks.key?(c.token)
|
|
||||||
odie <<~EOS
|
|
||||||
The cask '#{c.token}' was affected by a bug and cannot be upgraded as-is. To fix this, run:
|
|
||||||
brew reinstall --cask --force #{c.token}
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
[CaskLoader.load(c.installed_caskfile), c]
|
|
||||||
end
|
|
||||||
|
|
||||||
puts upgradable_casks
|
|
||||||
.map { |(old_cask, new_cask)| "#{new_cask.full_name} #{old_cask.version} -> #{new_cask.version}" }
|
|
||||||
.join("\n")
|
|
||||||
return true if dry_run
|
|
||||||
|
|
||||||
upgradable_casks.each do |(old_cask, new_cask)|
|
|
||||||
upgrade_cask(
|
|
||||||
old_cask, new_cask,
|
|
||||||
binaries: binaries, force: force, skip_cask_deps: skip_cask_deps, verbose: verbose,
|
|
||||||
quarantine: quarantine, require_sha: require_sha
|
|
||||||
)
|
|
||||||
rescue => e
|
|
||||||
caught_exceptions << e.exception("#{new_cask.full_name}: #{e}")
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
return true if caught_exceptions.empty?
|
|
||||||
raise MultipleCaskErrors, caught_exceptions if caught_exceptions.count > 1
|
|
||||||
raise caught_exceptions.first if caught_exceptions.count == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.upgrade_cask(
|
|
||||||
old_cask, new_cask,
|
|
||||||
binaries:, force:, quarantine:, require_sha:, skip_cask_deps:, verbose:
|
|
||||||
)
|
|
||||||
require "cask/installer"
|
|
||||||
|
|
||||||
start_time = Time.now
|
|
||||||
odebug "Started upgrade process for Cask #{old_cask}"
|
|
||||||
old_config = old_cask.config
|
|
||||||
|
|
||||||
old_options = {
|
|
||||||
binaries: binaries,
|
|
||||||
verbose: verbose,
|
|
||||||
force: force,
|
|
||||||
upgrade: true,
|
|
||||||
}.compact
|
|
||||||
|
|
||||||
old_cask_installer =
|
|
||||||
Installer.new(old_cask, **old_options)
|
|
||||||
|
|
||||||
new_cask.config = new_cask.default_config.merge(old_config)
|
|
||||||
|
|
||||||
new_options = {
|
|
||||||
binaries: binaries,
|
|
||||||
verbose: verbose,
|
|
||||||
force: force,
|
|
||||||
skip_cask_deps: skip_cask_deps,
|
|
||||||
require_sha: require_sha,
|
|
||||||
upgrade: true,
|
|
||||||
quarantine: quarantine,
|
|
||||||
}.compact
|
|
||||||
|
|
||||||
new_cask_installer =
|
|
||||||
Installer.new(new_cask, **new_options)
|
|
||||||
|
|
||||||
started_upgrade = false
|
|
||||||
new_artifacts_installed = false
|
|
||||||
|
|
||||||
begin
|
|
||||||
oh1 "Upgrading #{Formatter.identifier(old_cask)}"
|
|
||||||
|
|
||||||
# Start new cask's installation steps
|
|
||||||
new_cask_installer.check_conflicts
|
|
||||||
|
|
||||||
if (caveats = new_cask_installer.caveats)
|
|
||||||
puts caveats
|
|
||||||
end
|
|
||||||
|
|
||||||
new_cask_installer.fetch
|
|
||||||
|
|
||||||
# Move the old cask's artifacts back to staging
|
|
||||||
old_cask_installer.start_upgrade
|
|
||||||
# And flag it so in case of error
|
|
||||||
started_upgrade = true
|
|
||||||
|
|
||||||
# Install the new cask
|
|
||||||
new_cask_installer.stage
|
|
||||||
|
|
||||||
new_cask_installer.install_artifacts
|
|
||||||
new_artifacts_installed = true
|
|
||||||
|
|
||||||
# If successful, wipe the old cask from staging
|
|
||||||
old_cask_installer.finalize_upgrade
|
|
||||||
rescue => e
|
|
||||||
new_cask_installer.uninstall_artifacts if new_artifacts_installed
|
|
||||||
new_cask_installer.purge_versioned_files
|
|
||||||
old_cask_installer.revert_upgrade if started_upgrade
|
|
||||||
raise e
|
|
||||||
end
|
|
||||||
|
|
||||||
end_time = Time.now
|
|
||||||
Homebrew.messages.package_installed(new_cask.token, end_time - start_time)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
204
Library/Homebrew/cask/upgrade.rb
Normal file
204
Library/Homebrew/cask/upgrade.rb
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "env_config"
|
||||||
|
require "cask/config"
|
||||||
|
|
||||||
|
module Cask
|
||||||
|
# @api private
|
||||||
|
class Upgrade
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(
|
||||||
|
casks: Cask,
|
||||||
|
args: Homebrew::CLI::Args,
|
||||||
|
force: T.nilable(T::Boolean),
|
||||||
|
greedy: T.nilable(T::Boolean),
|
||||||
|
greedy_latest: T.nilable(T::Boolean),
|
||||||
|
greedy_auto_updates: T.nilable(T::Boolean),
|
||||||
|
dry_run: T.nilable(T::Boolean),
|
||||||
|
skip_cask_deps: T.nilable(T::Boolean),
|
||||||
|
verbose: T.nilable(T::Boolean),
|
||||||
|
binaries: T.nilable(T::Boolean),
|
||||||
|
quarantine: T.nilable(T::Boolean),
|
||||||
|
require_sha: T.nilable(T::Boolean),
|
||||||
|
).returns(T::Boolean)
|
||||||
|
}
|
||||||
|
def self.upgrade_casks(
|
||||||
|
*casks,
|
||||||
|
args:,
|
||||||
|
force: false,
|
||||||
|
greedy: false,
|
||||||
|
greedy_latest: false,
|
||||||
|
greedy_auto_updates: false,
|
||||||
|
dry_run: false,
|
||||||
|
skip_cask_deps: false,
|
||||||
|
verbose: false,
|
||||||
|
binaries: nil,
|
||||||
|
quarantine: nil,
|
||||||
|
require_sha: nil
|
||||||
|
)
|
||||||
|
|
||||||
|
quarantine = true if quarantine.nil?
|
||||||
|
|
||||||
|
outdated_casks = if casks.empty?
|
||||||
|
Caskroom.casks(config: Config.from_args(args)).select do |cask|
|
||||||
|
cask.outdated?(greedy: greedy, greedy_latest: greedy_latest,
|
||||||
|
greedy_auto_updates: greedy_auto_updates)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
casks.select do |cask|
|
||||||
|
raise CaskNotInstalledError, cask if !cask.installed? && !force
|
||||||
|
|
||||||
|
if cask.outdated?(greedy: true)
|
||||||
|
true
|
||||||
|
elsif cask.version.latest?
|
||||||
|
opoo "Not upgrading #{cask.token}, the downloaded artifact has not changed"
|
||||||
|
false
|
||||||
|
else
|
||||||
|
opoo "Not upgrading #{cask.token}, the latest version is already installed"
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
manual_installer_casks = outdated_casks.select do |cask|
|
||||||
|
cask.artifacts.any?(Artifact::Installer::ManualInstaller)
|
||||||
|
end
|
||||||
|
|
||||||
|
if manual_installer_casks.present?
|
||||||
|
count = manual_installer_casks.count
|
||||||
|
ofail "Not upgrading #{count} `installer manual` #{::Utils.pluralize("cask", count)}."
|
||||||
|
puts manual_installer_casks.map(&:to_s)
|
||||||
|
outdated_casks -= manual_installer_casks
|
||||||
|
end
|
||||||
|
|
||||||
|
return false if outdated_casks.empty?
|
||||||
|
|
||||||
|
if casks.empty? && !greedy
|
||||||
|
if !greedy_auto_updates && !greedy_latest
|
||||||
|
ohai "Casks with 'auto_updates true' or 'version :latest' " \
|
||||||
|
"will not be upgraded; pass `--greedy` to upgrade them."
|
||||||
|
end
|
||||||
|
if greedy_auto_updates && !greedy_latest
|
||||||
|
ohai "Casks with 'version :latest' will not be upgraded; pass `--greedy-latest` to upgrade them."
|
||||||
|
end
|
||||||
|
if !greedy_auto_updates && greedy_latest
|
||||||
|
ohai "Casks with 'auto_updates true' will not be upgraded; pass `--greedy-auto-updates` to upgrade them."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
verb = dry_run ? "Would upgrade" : "Upgrading"
|
||||||
|
oh1 "#{verb} #{outdated_casks.count} outdated #{::Utils.pluralize("package", outdated_casks.count)}:"
|
||||||
|
|
||||||
|
caught_exceptions = []
|
||||||
|
|
||||||
|
upgradable_casks = outdated_casks.map do |c|
|
||||||
|
if !c.installed_caskfile.exist? && c.tap.to_s == "homebrew/cask" &&
|
||||||
|
Homebrew::API::Cask.all_casks.key?(c.token)
|
||||||
|
odie <<~EOS
|
||||||
|
The cask '#{c.token}' was affected by a bug and cannot be upgraded as-is. To fix this, run:
|
||||||
|
brew reinstall --cask --force #{c.token}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
[CaskLoader.load(c.installed_caskfile), c]
|
||||||
|
end
|
||||||
|
|
||||||
|
puts upgradable_casks
|
||||||
|
.map { |(old_cask, new_cask)| "#{new_cask.full_name} #{old_cask.version} -> #{new_cask.version}" }
|
||||||
|
.join("\n")
|
||||||
|
return true if dry_run
|
||||||
|
|
||||||
|
upgradable_casks.each do |(old_cask, new_cask)|
|
||||||
|
upgrade_cask(
|
||||||
|
old_cask, new_cask,
|
||||||
|
binaries: binaries, force: force, skip_cask_deps: skip_cask_deps, verbose: verbose,
|
||||||
|
quarantine: quarantine, require_sha: require_sha
|
||||||
|
)
|
||||||
|
rescue => e
|
||||||
|
caught_exceptions << e.exception("#{new_cask.full_name}: #{e}")
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
return true if caught_exceptions.empty?
|
||||||
|
raise MultipleCaskErrors, caught_exceptions if caught_exceptions.count > 1
|
||||||
|
raise caught_exceptions.first if caught_exceptions.count == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.upgrade_cask(
|
||||||
|
old_cask, new_cask,
|
||||||
|
binaries:, force:, quarantine:, require_sha:, skip_cask_deps:, verbose:
|
||||||
|
)
|
||||||
|
require "cask/installer"
|
||||||
|
|
||||||
|
start_time = Time.now
|
||||||
|
odebug "Started upgrade process for Cask #{old_cask}"
|
||||||
|
old_config = old_cask.config
|
||||||
|
|
||||||
|
old_options = {
|
||||||
|
binaries: binaries,
|
||||||
|
verbose: verbose,
|
||||||
|
force: force,
|
||||||
|
upgrade: true,
|
||||||
|
}.compact
|
||||||
|
|
||||||
|
old_cask_installer =
|
||||||
|
Installer.new(old_cask, **old_options)
|
||||||
|
|
||||||
|
new_cask.config = new_cask.default_config.merge(old_config)
|
||||||
|
|
||||||
|
new_options = {
|
||||||
|
binaries: binaries,
|
||||||
|
verbose: verbose,
|
||||||
|
force: force,
|
||||||
|
skip_cask_deps: skip_cask_deps,
|
||||||
|
require_sha: require_sha,
|
||||||
|
upgrade: true,
|
||||||
|
quarantine: quarantine,
|
||||||
|
}.compact
|
||||||
|
|
||||||
|
new_cask_installer =
|
||||||
|
Installer.new(new_cask, **new_options)
|
||||||
|
|
||||||
|
started_upgrade = false
|
||||||
|
new_artifacts_installed = false
|
||||||
|
|
||||||
|
begin
|
||||||
|
oh1 "Upgrading #{Formatter.identifier(old_cask)}"
|
||||||
|
|
||||||
|
# Start new cask's installation steps
|
||||||
|
new_cask_installer.check_conflicts
|
||||||
|
|
||||||
|
if (caveats = new_cask_installer.caveats)
|
||||||
|
puts caveats
|
||||||
|
end
|
||||||
|
|
||||||
|
new_cask_installer.fetch
|
||||||
|
|
||||||
|
# Move the old cask's artifacts back to staging
|
||||||
|
old_cask_installer.start_upgrade
|
||||||
|
# And flag it so in case of error
|
||||||
|
started_upgrade = true
|
||||||
|
|
||||||
|
# Install the new cask
|
||||||
|
new_cask_installer.stage
|
||||||
|
|
||||||
|
new_cask_installer.install_artifacts
|
||||||
|
new_artifacts_installed = true
|
||||||
|
|
||||||
|
# If successful, wipe the old cask from staging
|
||||||
|
old_cask_installer.finalize_upgrade
|
||||||
|
rescue => e
|
||||||
|
new_cask_installer.uninstall_artifacts if new_artifacts_installed
|
||||||
|
new_cask_installer.purge_versioned_files
|
||||||
|
old_cask_installer.revert_upgrade if started_upgrade
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
|
||||||
|
end_time = Time.now
|
||||||
|
Homebrew.messages.package_installed(new_cask.token, end_time - start_time)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -7,6 +7,7 @@ require "install"
|
|||||||
require "upgrade"
|
require "upgrade"
|
||||||
require "cask/cmd"
|
require "cask/cmd"
|
||||||
require "cask/utils"
|
require "cask/utils"
|
||||||
|
require "cask/upgrade"
|
||||||
require "cask/macos"
|
require "cask/macos"
|
||||||
require "api"
|
require "api"
|
||||||
|
|
||||||
@ -87,8 +88,19 @@ module Homebrew
|
|||||||
description: "Treat all named arguments as casks. If no named arguments " \
|
description: "Treat all named arguments as casks. If no named arguments " \
|
||||||
"are specified, upgrade only outdated casks.",
|
"are specified, upgrade only outdated casks.",
|
||||||
}],
|
}],
|
||||||
|
[:switch, "--skip-cask-deps", {
|
||||||
|
description: "Skip installing cask dependencies.",
|
||||||
|
}],
|
||||||
|
[:switch, "-g", "--greedy", {
|
||||||
|
description: "Also include casks with `auto_updates true` or `version :latest`.",
|
||||||
|
}],
|
||||||
|
[:switch, "--greedy-latest", {
|
||||||
|
description: "Also include casks with `version :latest`.",
|
||||||
|
}],
|
||||||
|
[:switch, "--greedy-auto-updates", {
|
||||||
|
description: "Also include casks with `auto_updates true`.",
|
||||||
|
}],
|
||||||
*Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup),
|
*Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup),
|
||||||
*Cask::Cmd::Upgrade::OPTIONS.map(&:dup),
|
|
||||||
].each do |args|
|
].each do |args|
|
||||||
options = args.pop
|
options = args.pop
|
||||||
send(*args, **options)
|
send(*args, **options)
|
||||||
@ -230,7 +242,7 @@ module Homebrew
|
|||||||
def upgrade_outdated_casks(casks, args:)
|
def upgrade_outdated_casks(casks, args:)
|
||||||
return false if args.formula?
|
return false if args.formula?
|
||||||
|
|
||||||
Cask::Cmd::Upgrade.upgrade_casks(
|
Cask::Upgrade.upgrade_casks(
|
||||||
*casks,
|
*casks,
|
||||||
force: args.force?,
|
force: args.force?,
|
||||||
greedy: args.greedy?,
|
greedy: args.greedy?,
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
# typed: false
|
# typed: false
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe Cask::Cmd::Upgrade, :cask do
|
require "cask/upgrade"
|
||||||
|
|
||||||
|
describe Cask::Upgrade, :cask do
|
||||||
let(:version_latest_path_2) { version_latest.config.appdir.join("Caffeine Pro.app") }
|
let(:version_latest_path_2) { version_latest.config.appdir.join("Caffeine Pro.app") }
|
||||||
let(:version_latest_path_1) { version_latest.config.appdir.join("Caffeine Mini.app") }
|
let(:version_latest_path_1) { version_latest.config.appdir.join("Caffeine Mini.app") }
|
||||||
let(:version_latest) { Cask::CaskLoader.load("version-latest") }
|
let(:version_latest) { Cask::CaskLoader.load("version-latest") }
|
||||||
@ -11,6 +13,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
let(:local_transmission) { Cask::CaskLoader.load("local-transmission") }
|
let(:local_transmission) { Cask::CaskLoader.load("local-transmission") }
|
||||||
let(:local_caffeine_path) { local_caffeine.config.appdir.join("Caffeine.app") }
|
let(:local_caffeine_path) { local_caffeine.config.appdir.join("Caffeine.app") }
|
||||||
let(:local_caffeine) { Cask::CaskLoader.load("local-caffeine") }
|
let(:local_caffeine) { Cask::CaskLoader.load("local-caffeine") }
|
||||||
|
let(:args) { Homebrew::CLI::Args.new }
|
||||||
|
|
||||||
context "when the upgrade is successful" do
|
context "when the upgrade is successful" do
|
||||||
let(:installed) do
|
let(:installed) do
|
||||||
@ -38,7 +41,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(local_transmission_path).to be_a_directory
|
expect(local_transmission_path).to be_a_directory
|
||||||
expect(local_transmission.versions).to include("2.60")
|
expect(local_transmission.versions).to include("2.60")
|
||||||
|
|
||||||
described_class.run
|
described_class.upgrade_casks(args: args)
|
||||||
|
|
||||||
expect(local_caffeine).to be_installed
|
expect(local_caffeine).to be_installed
|
||||||
expect(local_caffeine_path).to be_a_directory
|
expect(local_caffeine_path).to be_a_directory
|
||||||
@ -58,7 +61,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(local_transmission_path).to be_a_directory
|
expect(local_transmission_path).to be_a_directory
|
||||||
expect(local_transmission.versions).to include("2.60")
|
expect(local_transmission.versions).to include("2.60")
|
||||||
|
|
||||||
described_class.run("local-caffeine")
|
described_class.upgrade_casks(local_caffeine, args: args)
|
||||||
|
|
||||||
expect(local_caffeine).to be_installed
|
expect(local_caffeine).to be_installed
|
||||||
expect(local_caffeine_path).to be_a_directory
|
expect(local_caffeine_path).to be_a_directory
|
||||||
@ -78,7 +81,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(auto_updates_path).to be_a_directory
|
expect(auto_updates_path).to be_a_directory
|
||||||
expect(auto_updates.versions).to include("2.57")
|
expect(auto_updates.versions).to include("2.57")
|
||||||
|
|
||||||
described_class.run("local-caffeine", "auto-updates")
|
described_class.upgrade_casks(local_caffeine, auto_updates, args: args)
|
||||||
|
|
||||||
expect(local_caffeine).to be_installed
|
expect(local_caffeine).to be_installed
|
||||||
expect(local_caffeine_path).to be_a_directory
|
expect(local_caffeine_path).to be_a_directory
|
||||||
@ -111,7 +114,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
version_latest.download_sha_path.write("fake download sha")
|
version_latest.download_sha_path.write("fake download sha")
|
||||||
expect(version_latest.outdated_download_sha?).to be(true)
|
expect(version_latest.outdated_download_sha?).to be(true)
|
||||||
|
|
||||||
described_class.run("--greedy")
|
described_class.upgrade_casks(greedy: true, args: args)
|
||||||
|
|
||||||
expect(local_caffeine).to be_installed
|
expect(local_caffeine).to be_installed
|
||||||
expect(local_caffeine_path).to be_a_directory
|
expect(local_caffeine_path).to be_a_directory
|
||||||
@ -136,13 +139,13 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(auto_updates_path).to be_a_directory
|
expect(auto_updates_path).to be_a_directory
|
||||||
expect(auto_updates.versions).to include("2.57")
|
expect(auto_updates.versions).to include("2.57")
|
||||||
|
|
||||||
described_class.run("auto-updates", "--greedy")
|
described_class.upgrade_casks(auto_updates, greedy: true, args: args)
|
||||||
|
|
||||||
expect(auto_updates).to be_installed
|
expect(auto_updates).to be_installed
|
||||||
expect(auto_updates_path).to be_a_directory
|
expect(auto_updates_path).to be_a_directory
|
||||||
expect(auto_updates.versions).to include("2.61")
|
expect(auto_updates.versions).to include("2.61")
|
||||||
|
|
||||||
described_class.run("auto-updates", "--greedy")
|
described_class.upgrade_casks(auto_updates, greedy: true, args: args)
|
||||||
|
|
||||||
expect(auto_updates).to be_installed
|
expect(auto_updates).to be_installed
|
||||||
expect(auto_updates_path).to be_a_directory
|
expect(auto_updates_path).to be_a_directory
|
||||||
@ -158,7 +161,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
version_latest.download_sha_path.write("fake download sha")
|
version_latest.download_sha_path.write("fake download sha")
|
||||||
expect(version_latest.outdated_download_sha?).to be(true)
|
expect(version_latest.outdated_download_sha?).to be(true)
|
||||||
|
|
||||||
described_class.run("version-latest", "--greedy")
|
described_class.upgrade_casks(version_latest, greedy: true, args: args)
|
||||||
|
|
||||||
expect(version_latest).to be_installed
|
expect(version_latest).to be_installed
|
||||||
expect(version_latest_path_1).to be_a_directory
|
expect(version_latest_path_1).to be_a_directory
|
||||||
@ -166,7 +169,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(version_latest.versions).to include("latest")
|
expect(version_latest.versions).to include("latest")
|
||||||
expect(version_latest.outdated_download_sha?).to be(false)
|
expect(version_latest.outdated_download_sha?).to be(false)
|
||||||
|
|
||||||
described_class.run("version-latest", "--greedy")
|
described_class.upgrade_casks(version_latest, greedy: true, args: args)
|
||||||
|
|
||||||
expect(version_latest).to be_installed
|
expect(version_latest).to be_installed
|
||||||
expect(version_latest_path_1).to be_a_directory
|
expect(version_latest_path_1).to be_a_directory
|
||||||
@ -205,7 +208,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(local_transmission_path).to be_a_directory
|
expect(local_transmission_path).to be_a_directory
|
||||||
expect(local_transmission.versions).to include("2.60")
|
expect(local_transmission.versions).to include("2.60")
|
||||||
|
|
||||||
described_class.run("--dry-run")
|
described_class.upgrade_casks(dry_run: true, args: args)
|
||||||
|
|
||||||
expect(local_caffeine).to be_installed
|
expect(local_caffeine).to be_installed
|
||||||
expect(local_caffeine_path).to be_a_directory
|
expect(local_caffeine_path).to be_a_directory
|
||||||
@ -229,7 +232,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(local_transmission_path).to be_a_directory
|
expect(local_transmission_path).to be_a_directory
|
||||||
expect(local_transmission.versions).to include("2.60")
|
expect(local_transmission.versions).to include("2.60")
|
||||||
|
|
||||||
described_class.run("--dry-run", "local-caffeine")
|
described_class.upgrade_casks(local_caffeine, dry_run: true, args: args)
|
||||||
|
|
||||||
expect(local_caffeine).to be_installed
|
expect(local_caffeine).to be_installed
|
||||||
expect(local_caffeine_path).to be_a_directory
|
expect(local_caffeine_path).to be_a_directory
|
||||||
@ -253,7 +256,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(auto_updates_path).to be_a_directory
|
expect(auto_updates_path).to be_a_directory
|
||||||
expect(auto_updates.versions).to include("2.57")
|
expect(auto_updates.versions).to include("2.57")
|
||||||
|
|
||||||
described_class.run("--dry-run", "local-caffeine", "auto-updates")
|
described_class.upgrade_casks(local_caffeine, auto_updates, dry_run: true, args: args)
|
||||||
|
|
||||||
expect(local_caffeine).to be_installed
|
expect(local_caffeine).to be_installed
|
||||||
expect(local_caffeine_path).to be_a_directory
|
expect(local_caffeine_path).to be_a_directory
|
||||||
@ -288,7 +291,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
version_latest.download_sha_path.write("fake download sha")
|
version_latest.download_sha_path.write("fake download sha")
|
||||||
expect(version_latest.outdated_download_sha?).to be(true)
|
expect(version_latest.outdated_download_sha?).to be(true)
|
||||||
|
|
||||||
described_class.run("--greedy", "--dry-run")
|
described_class.upgrade_casks(greedy: true, dry_run: true, args: args)
|
||||||
|
|
||||||
expect(local_caffeine).to be_installed
|
expect(local_caffeine).to be_installed
|
||||||
expect(local_caffeine_path).to be_a_directory
|
expect(local_caffeine_path).to be_a_directory
|
||||||
@ -316,7 +319,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(auto_updates_path).to be_a_directory
|
expect(auto_updates_path).to be_a_directory
|
||||||
expect(auto_updates.versions).to include("2.57")
|
expect(auto_updates.versions).to include("2.57")
|
||||||
|
|
||||||
described_class.run("--dry-run", "auto-updates", "--greedy")
|
described_class.upgrade_casks(auto_updates, dry_run: true, greedy: true, args: args)
|
||||||
|
|
||||||
expect(auto_updates).to be_installed
|
expect(auto_updates).to be_installed
|
||||||
expect(auto_updates_path).to be_a_directory
|
expect(auto_updates_path).to be_a_directory
|
||||||
@ -335,7 +338,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
version_latest.download_sha_path.write("fake download sha")
|
version_latest.download_sha_path.write("fake download sha")
|
||||||
expect(version_latest.outdated_download_sha?).to be(true)
|
expect(version_latest.outdated_download_sha?).to be(true)
|
||||||
|
|
||||||
described_class.run("--dry-run", "version-latest", "--greedy")
|
described_class.upgrade_casks(version_latest, dry_run: true, greedy: true, args: args)
|
||||||
|
|
||||||
expect(version_latest).to be_installed
|
expect(version_latest).to be_installed
|
||||||
expect(version_latest_path_1).to be_a_directory
|
expect(version_latest_path_1).to be_a_directory
|
||||||
@ -373,7 +376,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(will_fail_if_upgraded.versions).to include("1.2.2")
|
expect(will_fail_if_upgraded.versions).to include("1.2.2")
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
described_class.run("will-fail-if-upgraded")
|
described_class.upgrade_casks(will_fail_if_upgraded, args: args)
|
||||||
end.to raise_error(Cask::CaskError).and output(output_reverted).to_stderr
|
end.to raise_error(Cask::CaskError).and output(output_reverted).to_stderr
|
||||||
|
|
||||||
expect(will_fail_if_upgraded).to be_installed
|
expect(will_fail_if_upgraded).to be_installed
|
||||||
@ -391,7 +394,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(bad_checksum.versions).to include("1.2.2")
|
expect(bad_checksum.versions).to include("1.2.2")
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
described_class.run("bad-checksum")
|
described_class.upgrade_casks(bad_checksum, args: args)
|
||||||
end.to raise_error(ChecksumMismatchError).and(not_to_output(output_reverted).to_stderr)
|
end.to raise_error(ChecksumMismatchError).and(not_to_output(output_reverted).to_stderr)
|
||||||
|
|
||||||
expect(bad_checksum).to be_installed
|
expect(bad_checksum).to be_installed
|
||||||
@ -436,7 +439,7 @@ describe Cask::Cmd::Upgrade, :cask do
|
|||||||
expect(bad_checksum_2.versions).to include("1.2.2")
|
expect(bad_checksum_2.versions).to include("1.2.2")
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
described_class.run
|
described_class.upgrade_casks(args: args)
|
||||||
end.to raise_error(Cask::MultipleCaskErrors)
|
end.to raise_error(Cask::MultipleCaskErrors)
|
||||||
|
|
||||||
expect(bad_checksum).to be_installed
|
expect(bad_checksum).to be_installed
|
Loading…
x
Reference in New Issue
Block a user