Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Library/Homebrew/test/upgrade_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@
"==> Not upgrading dependent: installed runtime dependencies satisfy bottle metadata\n",
).to_stdout
end

it "keeps the requested order within keg-only and non-keg-only formulae" do
names = %w[a b c d e f g h i j]
formulae = names.map do |name|
formula(name) do
T.bind(self, T.class_of(Formula))
url "https://brew.sh/#{name}-1.0"
keg_only "to test keg only formulae ordered first without further order mutation" if %w[c h].include?(name)
end
end
download_queue = instance_double(Homebrew::DownloadQueue, fetch: nil, shutdown: nil)

allow(Migrator).to receive(:migrate_if_needed)
allow(Homebrew::DownloadQueue).to receive(:new).and_return(download_queue)
allow(described_class).to receive(:create_formula_installer) do |formula|
instance_double(FormulaInstaller, determine_bottle_tab_attributes: nil, fetch_bottle_tab: nil, formula:)
end

installers = described_class.formula_installers(formulae, flags: [])
expect(installers.map { |installer| installer.formula.name }).to eq(%w[c h a b d e f g i j])
end
end

describe "::dependent_formula_installers" do
Expand Down
10 changes: 1 addition & 9 deletions Library/Homebrew/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,7 @@ def formula_installers(

# Sort keg-only before non-keg-only formulae to avoid any needless conflicts
# with outdated, non-keg-only versions of formulae being upgraded.
formulae_to_install.sort! do |a, b|
if !a.keg_only? && b.keg_only?
1
elsif a.keg_only? && !b.keg_only?
-1
else
0
end
end
formulae_to_install.replace(formulae_to_install.partition(&:keg_only?).flatten(1))

dependency_graph = Utils::TopologicalHash.graph_package_dependencies(formulae_to_install)
sorted = dependency_graph.tsort_with_cycles do |cycles|
Expand Down
Loading