Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "update-report: default HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED to on." #12933

Merged
merged 2 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 33 additions & 12 deletions Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ def report(preinstall: false)

if paths.any? { |p| tap.cask_file?(p) }
case status
when "A"
# Have a dedicated report array for new casks.
@report[:AC] << tap.formula_file_to_name(src)
when "D"
# Have a dedicated report array for deleted casks.
@report[:DC] << tap.formula_file_to_name(src)
Expand Down Expand Up @@ -410,14 +413,12 @@ def report(preinstall: false)
renamed_formulae << [old_full_name, new_full_name]
end

if renamed_formulae.present?
unless renamed_formulae.empty?
@report[:A] -= renamed_formulae.map(&:last)
@report[:D] -= renamed_formulae.map(&:first)
@report[:R] = renamed_formulae.to_a
end

# Only needed additions for calculating deletions correctly based on renames.
@report.delete(:A)

@report
end

Expand Down Expand Up @@ -568,18 +569,18 @@ def add(reporter, preinstall: false)
delegate empty?: :@hash

def dump(updated_formula_report: true)
if ENV["HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED"]
opoo "HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED can be unset, it is now the default!"
end

# Key Legend: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R)

dump_formula_report :A, "New Formulae"
if updated_formula_report
dump_formula_report :M, "Updated Formulae"
else
updated = select_formula(:M).count
ohai "Updated Formulae", "Updated #{updated} #{"formula".pluralize(updated)}." if updated.positive?
end
dump_formula_report :R, "Renamed Formulae"
dump_formula_report :D, "Deleted Formulae"
dump_formula_report :AC, "New Casks"
if updated_formula_report
dump_formula_report :MC, "Updated Casks"
else
Expand All @@ -592,13 +593,33 @@ def dump(updated_formula_report: true)
private

def dump_formula_report(key, title)
formulae = select_formula(key).sort.map do |name, _new_name|
# TODO: 3.4.0: odisabled the old functionality and make this default
only_installed = Homebrew::EnvConfig.update_report_only_installed?

formulae = select_formula(key).sort.map do |name, new_name|
# Format list items of renamed formulae
case key
when :R
name = pretty_installed(name) if installed?(name)
new_name = pretty_installed(new_name) if installed?(new_name)
"#{name} -> #{new_name}" unless only_installed
when :A
name if !installed?(name) && !only_installed
when :AC
name.split("/").last if !cask_installed?(name) && !only_installed
when :MC, :DC
name = name.split("/").last
pretty_installed(name) if cask_installed?(name)
when :M, :D
pretty_installed(name) if installed?(name)
if cask_installed?(name)
pretty_installed(name)
elsif !only_installed
name
end
else
if installed?(name)
pretty_installed(name)
elsif !only_installed
name
end
end
end.compact

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ module EnvConfig
default_text: "macOS: `/private/tmp`, Linux: `/tmp`.",
default: HOMEBREW_DEFAULT_TEMP,
},
HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED: {
description: "If set, `brew update` only lists updates to installed software.",
boolean: true,
},
HOMEBREW_UPDATE_TO_TAG: {
description: "If set, always use the latest stable tag (even if developer commands " \
"have been run).",
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,8 @@ module Homebrew::EnvConfig

def self.temp(); end

def self.update_report_only_installed?(); end

def self.update_to_tag?(); end

def self.verbose?(); end
Expand Down
12 changes: 12 additions & 0 deletions Library/Homebrew/test/cmd/update-report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ def perform_update(fixture_name = "")
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
Expand All @@ -72,14 +74,17 @@ def perform_update(fixture_name = "")
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
Expand All @@ -96,25 +101,32 @@ def perform_update(fixture_name = "")
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
Expand Down