Merge pull request #18420 from ctaintor/improve_adopt_cask
Improve cask --adopt to only care about the installed version if auto…
This commit is contained in:
commit
3e6929e849
@ -31,7 +31,7 @@ module Cask
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall: false,
|
def move(adopt: false, auto_updates: false, force: false, verbose: false, predecessor: nil, reinstall: false,
|
||||||
command: nil, **options)
|
command: nil, **options)
|
||||||
unless source.exist?
|
unless source.exist?
|
||||||
raise CaskError, "It seems the #{self.class.english_name} source '#{source}' is not there."
|
raise CaskError, "It seems the #{self.class.english_name} source '#{source}' is not there."
|
||||||
@ -51,38 +51,40 @@ module Cask
|
|||||||
if adopt
|
if adopt
|
||||||
ohai "Adopting existing #{self.class.english_name} at '#{target}'"
|
ohai "Adopting existing #{self.class.english_name} at '#{target}'"
|
||||||
|
|
||||||
source_plist = Pathname("#{source}/Contents/Info.plist")
|
unless auto_updates
|
||||||
target_plist = Pathname("#{target}/Contents/Info.plist")
|
source_plist = Pathname("#{source}/Contents/Info.plist")
|
||||||
same = if source_plist.size? &&
|
target_plist = Pathname("#{target}/Contents/Info.plist")
|
||||||
(source_bundle_version = Homebrew::BundleVersion.from_info_plist(source_plist)) &&
|
same = if source_plist.size? &&
|
||||||
target_plist.size? &&
|
(source_bundle_version = Homebrew::BundleVersion.from_info_plist(source_plist)) &&
|
||||||
(target_bundle_version = Homebrew::BundleVersion.from_info_plist(target_plist))
|
target_plist.size? &&
|
||||||
if source_bundle_version.short_version == target_bundle_version.short_version
|
(target_bundle_version = Homebrew::BundleVersion.from_info_plist(target_plist))
|
||||||
if source_bundle_version.version == target_bundle_version.version
|
if source_bundle_version.short_version == target_bundle_version.short_version
|
||||||
true
|
if source_bundle_version.version == target_bundle_version.version
|
||||||
|
true
|
||||||
|
else
|
||||||
|
onoe "The bundle version of #{source} is #{source_bundle_version.version} but " \
|
||||||
|
"is #{target_bundle_version.version} for #{target}!"
|
||||||
|
false
|
||||||
|
end
|
||||||
else
|
else
|
||||||
onoe "The bundle version of #{source} is #{source_bundle_version.version} but " \
|
onoe "The bundle short version of #{source} is #{source_bundle_version.short_version} but " \
|
||||||
"is #{target_bundle_version.version} for #{target}!"
|
"is #{target_bundle_version.short_version} for #{target}!"
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
onoe "The bundle short version of #{source} is #{source_bundle_version.short_version} but " \
|
command.run(
|
||||||
"is #{target_bundle_version.short_version} for #{target}!"
|
"/usr/bin/diff",
|
||||||
false
|
args: ["--recursive", "--brief", source, target],
|
||||||
|
verbose:,
|
||||||
|
print_stdout: verbose,
|
||||||
|
).success?
|
||||||
end
|
end
|
||||||
else
|
|
||||||
command.run(
|
|
||||||
"/usr/bin/diff",
|
|
||||||
args: ["--recursive", "--brief", source, target],
|
|
||||||
verbose:,
|
|
||||||
print_stdout: verbose,
|
|
||||||
).success?
|
|
||||||
end
|
|
||||||
|
|
||||||
unless same
|
unless same
|
||||||
raise CaskError,
|
raise CaskError,
|
||||||
"It seems the existing #{self.class.english_name} is different from " \
|
"It seems the existing #{self.class.english_name} is different from " \
|
||||||
"the one being installed."
|
"the one being installed."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove the source as we don't need to move it to the target location
|
# Remove the source as we don't need to move it to the target location
|
||||||
|
|||||||
@ -253,7 +253,8 @@ on_request: true)
|
|||||||
next if artifact.is_a?(Artifact::Binary) && !binaries?
|
next if artifact.is_a?(Artifact::Binary) && !binaries?
|
||||||
|
|
||||||
artifact.install_phase(
|
artifact.install_phase(
|
||||||
command: @command, verbose: verbose?, adopt: adopt?, force: force?, predecessor:,
|
command: @command, verbose: verbose?, adopt: adopt?, auto_updates: @cask.auto_updates,
|
||||||
|
force: force?, predecessor:
|
||||||
)
|
)
|
||||||
already_installed_artifacts.unshift(artifact)
|
already_installed_artifacts.unshift(artifact)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,12 +5,13 @@ RSpec.describe Cask::Artifact::App, :cask do
|
|||||||
let(:command) { NeverSudoSystemCommand }
|
let(:command) { NeverSudoSystemCommand }
|
||||||
let(:adopt) { false }
|
let(:adopt) { false }
|
||||||
let(:force) { false }
|
let(:force) { false }
|
||||||
|
let(:auto_updates) { false }
|
||||||
let(:app) { cask.artifacts.find { |a| a.is_a?(described_class) } }
|
let(:app) { cask.artifacts.find { |a| a.is_a?(described_class) } }
|
||||||
|
|
||||||
let(:source_path) { cask.staged_path.join("Caffeine.app") }
|
let(:source_path) { cask.staged_path.join("Caffeine.app") }
|
||||||
let(:target_path) { cask.config.appdir.join("Caffeine.app") }
|
let(:target_path) { cask.config.appdir.join("Caffeine.app") }
|
||||||
|
|
||||||
let(:install_phase) { app.install_phase(command:, adopt:, force:) }
|
let(:install_phase) { app.install_phase(command:, adopt:, force:, auto_updates:) }
|
||||||
let(:uninstall_phase) { app.uninstall_phase(command:, force:) }
|
let(:uninstall_phase) { app.uninstall_phase(command:, force:) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@ -83,24 +84,55 @@ RSpec.describe Cask::Artifact::App, :cask do
|
|||||||
let(:adopt) { true }
|
let(:adopt) { true }
|
||||||
|
|
||||||
describe "when the target compares different from the source" do
|
describe "when the target compares different from the source" do
|
||||||
it "avoids clobbering the existing app" do
|
describe "when the cask does not auto_updates" do
|
||||||
stdout = <<~EOS
|
it "avoids clobbering the existing app if brew manages updates" do
|
||||||
==> Adopting existing App at '#{target_path}'
|
stdout = <<~EOS
|
||||||
EOS
|
==> Adopting existing App at '#{target_path}'
|
||||||
|
EOS
|
||||||
|
|
||||||
expect { install_phase }
|
expect { install_phase }
|
||||||
.to output(stdout).to_stdout
|
.to output(stdout).to_stdout
|
||||||
.and raise_error(
|
.and raise_error(
|
||||||
Cask::CaskError,
|
Cask::CaskError,
|
||||||
"It seems the existing App is different from the one being installed.",
|
"It seems the existing App is different from the one being installed.",
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(source_path).to be_a_directory
|
expect(source_path).to be_a_directory
|
||||||
expect(target_path).to be_a_directory
|
expect(target_path).to be_a_directory
|
||||||
expect(File.identical?(source_path, target_path)).to be false
|
expect(File.identical?(source_path, target_path)).to be false
|
||||||
|
|
||||||
contents_path = target_path.join("Contents/Info.plist")
|
contents_path = target_path.join("Contents/Info.plist")
|
||||||
expect(contents_path).not_to exist
|
expect(contents_path).not_to exist
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "when the cask auto_updates" do
|
||||||
|
before do
|
||||||
|
target_path.delete
|
||||||
|
FileUtils.cp_r source_path, target_path
|
||||||
|
File.write(target_path.join("Contents/Info.plist"), "different")
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:auto_updates) { true }
|
||||||
|
|
||||||
|
it "adopts the existing app" do
|
||||||
|
stdout = <<~EOS
|
||||||
|
==> Adopting existing App at '#{target_path}'
|
||||||
|
EOS
|
||||||
|
|
||||||
|
stderr = ""
|
||||||
|
|
||||||
|
expect { install_phase }
|
||||||
|
.to output(stdout).to_stdout
|
||||||
|
.and output(stderr).to_stderr
|
||||||
|
|
||||||
|
expect(source_path).to be_a_symlink
|
||||||
|
expect(target_path).to be_a_directory
|
||||||
|
|
||||||
|
contents_path = target_path.join("Contents/Info.plist")
|
||||||
|
expect(contents_path).to exist
|
||||||
|
expect(File.read(contents_path)).to eq("different")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user