Merge pull request #4601 from reitermarkus/double-dash

Use `--` to separate download name and version.
This commit is contained in:
Markus Reiter 2018-08-05 20:53:17 +02:00 committed by GitHub
commit 892f359d77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 180 additions and 123 deletions

View File

@ -62,6 +62,11 @@ module Homebrew
updated = true updated = true
end end
initial_version = Version.new(system_command!("git",
args: ["describe", "--tags", "--abbrev=0", initial_revision],
chdir: HOMEBREW_REPOSITORY,
print_stderr: false).stdout)
updated_taps = [] updated_taps = []
Tap.each do |tap| Tap.each do |tap|
next unless tap.git? next unless tap.git?
@ -85,6 +90,7 @@ module Homebrew
end end
migrate_legacy_cache_if_necessary migrate_legacy_cache_if_necessary
migrate_cache_entries_to_double_dashes(initial_version)
migrate_legacy_keg_symlinks_if_necessary migrate_legacy_keg_symlinks_if_necessary
if !updated if !updated
@ -183,6 +189,31 @@ module Homebrew
end end
end end
def migrate_cache_entries_to_double_dashes(initial_version)
return if initial_version > "1.7.1"
HOMEBREW_CACHE.children.each do |child|
next unless child.file?
next unless /^(?<prefix>[^\.]+[^\-])\-(?<suffix>[^\-].*)/ =~ child.basename.to_s
target = HOMEBREW_CACHE/"#{prefix}--#{suffix}"
if target.exist?
begin
FileUtils.rm_rf child
rescue Errno::EACCES
opoo "Could not remove #{child}, please do so manually."
end
else
begin
FileUtils.mv child, target
rescue Errno::EACCES
opoo "Could not move #{child} to #{target}, please do so manually."
end
end
end
end
def migrate_legacy_repository_if_necessary def migrate_legacy_repository_if_necessary
return unless HOMEBREW_PREFIX.to_s == "/usr/local" return unless HOMEBREW_PREFIX.to_s == "/usr/local"
return unless HOMEBREW_REPOSITORY.to_s == "/usr/local" return unless HOMEBREW_REPOSITORY.to_s == "/usr/local"

View File

@ -181,7 +181,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
def initialize(url, name, version, **meta) def initialize(url, name, version, **meta)
super super
@cached_location = @cache/"#{name}-#{version}#{ext}" @cached_location = @cache/"#{name}--#{version}#{ext}"
@temporary_path = Pathname.new("#{cached_location}.incomplete") @temporary_path = Pathname.new("#{cached_location}.incomplete")
end end

View File

@ -2,10 +2,10 @@ describe "brew fetch", :integration_test do
it "downloads the Formula's URL" do it "downloads the Formula's URL" do
setup_test_formula "testball" setup_test_formula "testball"
expect(HOMEBREW_CACHE/"testball-0.1.tbz").not_to exist expect(HOMEBREW_CACHE/"testball--0.1.tbz").not_to exist
expect { brew "fetch", "testball" }.to be_a_success expect { brew "fetch", "testball" }.to be_a_success
expect(HOMEBREW_CACHE/"testball-0.1.tbz").to exist expect(HOMEBREW_CACHE/"testball--0.1.tbz").to exist
end end
end end

View File

@ -0,0 +1,129 @@
require "cmd/update-report"
require "formula_versions"
require "yaml"
describe Reporter do
def perform_update(fixture_name = "")
allow(Formulary).to receive(:factory).and_return(double(pkg_version: "1.0"))
allow(FormulaVersions).to receive(:new).and_return(double(formula_at_revision: "2.0"))
diff = YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")[fixture_name]
allow(subject).to receive(:diff).and_return(diff || "")
hub.add(subject) if subject.updated?
end
subject { reporter_class.new(tap) }
let(:reporter_class) do
Class.new(described_class) do
def initialize(tap)
@tap = tap
ENV["HOMEBREW_UPDATE_BEFORE#{tap.repo_var}"] = "12345678"
ENV["HOMEBREW_UPDATE_AFTER#{tap.repo_var}"] = "abcdef00"
super(tap)
end
end
end
let(:tap) { CoreTap.new }
let(:hub) { ReporterHub.new }
specify "without revision variable" do
ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" }
expect {
described_class.new(tap)
}.to raise_error(Reporter::ReporterRevisionUnsetError)
end
specify "without any changes" do
perform_update
expect(hub).to be_empty
end
specify "without Formula changes" do
perform_update("update_git_diff_output_without_formulae_changes")
expect(hub.select_formula(:M)).to be_empty
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
end
specify "with Formula changes" do
perform_update("update_git_diff_output_with_formulae_changes")
expect(hub.select_formula(:M)).to eq(%w[xar yajl])
expect(hub.select_formula(:A)).to eq(%w[antiword bash-completion ddrescue dict lua])
end
specify "with removed Formulae" do
perform_update("update_git_diff_output_with_removed_formulae")
expect(hub.select_formula(:D)).to eq(%w[libgsasl])
end
specify "with changed file type" do
perform_update("update_git_diff_output_with_changed_filetype")
expect(hub.select_formula(:M)).to eq(%w[elixir])
expect(hub.select_formula(:A)).to eq(%w[libbson])
expect(hub.select_formula(:D)).to eq(%w[libgsasl])
end
specify "with renamed Formula" do
allow(tap).to receive(:formula_renames).and_return("cv" => "progress")
perform_update("update_git_diff_output_with_formula_rename")
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
expect(hub.select_formula(:R)).to eq([["cv", "progress"]])
end
context "when updating a Tap other than the core Tap" do
let(:tap) { Tap.new("foo", "bar") }
before do
(tap.path/"Formula").mkpath
end
after do
tap.path.parent.rmtree
end
specify "with restructured Tap" do
perform_update("update_git_diff_output_with_restructured_tap")
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
expect(hub.select_formula(:R)).to be_empty
end
specify "with renamed Formula and restructured Tap" do
allow(tap).to receive(:formula_renames).and_return("xchat" => "xchat2")
perform_update("update_git_diff_output_with_formula_rename_and_restructuring")
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
expect(hub.select_formula(:R)).to eq([%w[foo/bar/xchat foo/bar/xchat2]])
end
specify "with simulated 'homebrew/php' restructuring" do
perform_update("update_git_diff_simulate_homebrew_php_restructuring")
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
expect(hub.select_formula(:R)).to be_empty
end
specify "with Formula changes" do
perform_update("update_git_diff_output_with_tap_formulae_changes")
expect(hub.select_formula(:A)).to eq(%w[foo/bar/lua])
expect(hub.select_formula(:M)).to eq(%w[foo/bar/git])
expect(hub.select_formula(:D)).to be_empty
end
end
end

View File

@ -1,129 +1,26 @@
require "cmd/update-report" require "cmd/update-report"
require "formula_versions"
require "yaml"
describe Reporter do describe "brew update-report" do
def perform_update(fixture_name = "") describe "::migrate_cache_entries_to_double_dashes" do
allow(Formulary).to receive(:factory).and_return(double(pkg_version: "1.0")) let(:legacy_cache_file) { HOMEBREW_CACHE/"foo-1.2.3.tar.gz" }
allow(FormulaVersions).to receive(:new).and_return(double(formula_at_revision: "2.0")) let(:renamed_cache_file) { HOMEBREW_CACHE/"foo--1.2.3.tar.gz" }
diff = YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")[fixture_name] before(:each) do
allow(subject).to receive(:diff).and_return(diff || "") FileUtils.touch legacy_cache_file
hub.add(subject) if subject.updated?
end end
subject { reporter_class.new(tap) } it "moves old files to use double dashes when upgrading from <= 1.7.1" do
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.1"))
let(:reporter_class) do expect(legacy_cache_file).not_to exist
Class.new(described_class) do expect(renamed_cache_file).to exist
def initialize(tap)
@tap = tap
ENV["HOMEBREW_UPDATE_BEFORE#{tap.repo_var}"] = "12345678"
ENV["HOMEBREW_UPDATE_AFTER#{tap.repo_var}"] = "abcdef00"
super(tap)
end
end
end end
let(:tap) { CoreTap.new } it "does not move files if upgrading from > 1.7.1" do
let(:hub) { ReporterHub.new } Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.2"))
specify "without revision variable" do expect(legacy_cache_file).to exist
ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" } expect(renamed_cache_file).not_to exist
expect {
described_class.new(tap)
}.to raise_error(Reporter::ReporterRevisionUnsetError)
end
specify "without any changes" do
perform_update
expect(hub).to be_empty
end
specify "without Formula changes" do
perform_update("update_git_diff_output_without_formulae_changes")
expect(hub.select_formula(:M)).to be_empty
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
end
specify "with Formula changes" do
perform_update("update_git_diff_output_with_formulae_changes")
expect(hub.select_formula(:M)).to eq(%w[xar yajl])
expect(hub.select_formula(:A)).to eq(%w[antiword bash-completion ddrescue dict lua])
end
specify "with removed Formulae" do
perform_update("update_git_diff_output_with_removed_formulae")
expect(hub.select_formula(:D)).to eq(%w[libgsasl])
end
specify "with changed file type" do
perform_update("update_git_diff_output_with_changed_filetype")
expect(hub.select_formula(:M)).to eq(%w[elixir])
expect(hub.select_formula(:A)).to eq(%w[libbson])
expect(hub.select_formula(:D)).to eq(%w[libgsasl])
end
specify "with renamed Formula" do
allow(tap).to receive(:formula_renames).and_return("cv" => "progress")
perform_update("update_git_diff_output_with_formula_rename")
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
expect(hub.select_formula(:R)).to eq([["cv", "progress"]])
end
context "when updating a Tap other than the core Tap" do
let(:tap) { Tap.new("foo", "bar") }
before do
(tap.path/"Formula").mkpath
end
after do
tap.path.parent.rmtree
end
specify "with restructured Tap" do
perform_update("update_git_diff_output_with_restructured_tap")
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
expect(hub.select_formula(:R)).to be_empty
end
specify "with renamed Formula and restructured Tap" do
allow(tap).to receive(:formula_renames).and_return("xchat" => "xchat2")
perform_update("update_git_diff_output_with_formula_rename_and_restructuring")
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
expect(hub.select_formula(:R)).to eq([%w[foo/bar/xchat foo/bar/xchat2]])
end
specify "with simulated 'homebrew/php' restructuring" do
perform_update("update_git_diff_simulate_homebrew_php_restructuring")
expect(hub.select_formula(:A)).to be_empty
expect(hub.select_formula(:D)).to be_empty
expect(hub.select_formula(:R)).to be_empty
end
specify "with Formula changes" do
perform_update("update_git_diff_output_with_tap_formulae_changes")
expect(hub.select_formula(:A)).to eq(%w[foo/bar/lua])
expect(hub.select_formula(:M)).to eq(%w[foo/bar/git])
expect(hub.select_formula(:D)).to be_empty
end end
end end
end end

View File

@ -238,13 +238,13 @@ describe CurlDownloadStrategy do
subject { described_class.new(url, name, version, **specs).cached_location } subject { described_class.new(url, name, version, **specs).cached_location }
context "when URL ends with file" do context "when URL ends with file" do
it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") } it { is_expected.to eq(HOMEBREW_CACHE/"foo--.tar.gz") }
end end
context "when URL file is in middle" do context "when URL file is in middle" do
let(:url) { "http://example.com/foo.tar.gz/from/this/mirror" } let(:url) { "http://example.com/foo.tar.gz/from/this/mirror" }
it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") } it { is_expected.to eq(HOMEBREW_CACHE/"foo--.tar.gz") }
end end
end end
end end