| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | require "formula_versions" | 
					
						
							|  |  |  | require "migrator" | 
					
						
							|  |  |  | require "formulary" | 
					
						
							|  |  |  | require "descriptions" | 
					
						
							| 
									
										
										
										
											2016-06-01 08:46:33 +01:00
										 |  |  | require "cleanup" | 
					
						
							| 
									
										
										
										
											2018-10-13 08:22:51 -07:00
										 |  |  | require "description_cache_store" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2021-01-12 16:27:25 -05:00
										 |  |  | require "settings" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-01 13:33:42 -04:00
										 |  |  |   def update_preinstall_header(args:) | 
					
						
							| 
									
										
										
										
											2018-03-07 16:14:55 +00:00
										 |  |  |     @update_preinstall_header ||= begin | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       ohai_stdout_or_stderr "Auto-updated Homebrew!" if args.preinstall? | 
					
						
							| 
									
										
										
										
											2016-04-11 09:31:50 +01:00
										 |  |  |       true | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:45 +00:00
										 |  |  |   def update_report_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:45 +00:00
										 |  |  |         The Ruby implementation of `brew update`. Never called manually. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       switch "--preinstall", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Run in 'auto-update' mode (faster, less output)." | 
					
						
							| 
									
										
										
										
											2020-07-27 03:59:52 +02:00
										 |  |  |       switch "-f", "--force", | 
					
						
							|  |  |  |              description: "Treat installed and updated formulae as if they are from "\ | 
					
						
							|  |  |  |                           "the same taps and migrate them anyway." | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:45 +00:00
										 |  |  |       hide_from_man_page! | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   def update_report | 
					
						
							| 
									
										
										
										
											2020-07-25 21:33:48 +02:00
										 |  |  |     args = update_report_args.parse | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  |     if !Utils::Analytics.messages_displayed? && | 
					
						
							|  |  |  |        !Utils::Analytics.disabled? && | 
					
						
							|  |  |  |        !Utils::Analytics.no_message_output? | 
					
						
							| 
									
										
										
										
											2016-04-25 18:05:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  |       ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1" | 
					
						
							|  |  |  |       # Use the shell's audible bell. | 
					
						
							|  |  |  |       print "\a" | 
					
						
							| 
									
										
										
										
											2018-08-14 13:19:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  |       # Use an extra newline and bold to avoid this being missed. | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       ohai_stdout_or_stderr "Homebrew has enabled anonymous aggregate formula and cask analytics." | 
					
						
							|  |  |  |       puts_stdout_or_stderr <<~EOS | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  |         #{Tty.bold}Read the analytics documentation (and how to opt-out) here: | 
					
						
							|  |  |  |           #{Formatter.url("https://docs.brew.sh/Analytics")}#{Tty.reset} | 
					
						
							| 
									
										
										
										
											2021-01-26 15:21:24 -05:00
										 |  |  |         No analytics have been recorded yet (nor will be during this `brew` run). | 
					
						
							| 
									
										
										
										
											2019-11-22 09:08:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Consider the messages possibly missed if not a TTY. | 
					
						
							|  |  |  |       Utils::Analytics.messages_displayed! if $stdout.tty? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 16:27:25 -05:00
										 |  |  |     if Settings.read("donationmessage") != "true" && !args.quiet? | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       ohai_stdout_or_stderr "Homebrew is run entirely by unpaid volunteers. Please consider donating:" | 
					
						
							|  |  |  |       puts_stdout_or_stderr "  #{Formatter.url("https://github.com/Homebrew/brew#donations")}\n" | 
					
						
							| 
									
										
										
										
											2018-08-14 13:19:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 16:27:25 -05:00
										 |  |  |       # Consider the message possibly missed if not a TTY. | 
					
						
							|  |  |  |       Settings.write "donationmessage", true if $stdout.tty? | 
					
						
							| 
									
										
										
										
											2016-04-25 18:05:30 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-26 17:39:49 +08:00
										 |  |  |     install_core_tap_if_necessary | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-06 14:55:37 +08:00
										 |  |  |     updated = false | 
					
						
							| 
									
										
										
										
											2020-12-23 12:06:28 -05:00
										 |  |  |     new_repository_version = nil | 
					
						
							| 
									
										
										
										
											2016-02-25 16:41:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-06 14:55:37 +08:00
										 |  |  |     initial_revision = ENV["HOMEBREW_UPDATE_BEFORE"].to_s | 
					
						
							|  |  |  |     current_revision = ENV["HOMEBREW_UPDATE_AFTER"].to_s | 
					
						
							| 
									
										
										
										
											2019-02-19 13:11:32 +00:00
										 |  |  |     odie "update-report should not be called directly!" if initial_revision.empty? || current_revision.empty? | 
					
						
							| 
									
										
										
										
											2016-02-25 16:41:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-06 14:55:37 +08:00
										 |  |  |     if initial_revision != current_revision | 
					
						
							| 
									
										
										
										
											2020-08-01 13:33:42 -04:00
										 |  |  |       update_preinstall_header args: args | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       puts_stdout_or_stderr \ | 
					
						
							|  |  |  |         "Updated Homebrew from #{shorten_revision(initial_revision)} to #{shorten_revision(current_revision)}." | 
					
						
							| 
									
										
										
										
											2016-03-06 14:55:37 +08:00
										 |  |  |       updated = true | 
					
						
							| 
									
										
										
										
											2020-12-23 12:06:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 16:27:25 -05:00
										 |  |  |       old_tag = Settings.read "latesttag" | 
					
						
							| 
									
										
										
										
											2020-12-25 14:08:11 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       new_tag = Utils.popen_read( | 
					
						
							| 
									
										
										
										
											2021-01-01 17:54:59 +09:00
										 |  |  |         "git", "-C", HOMEBREW_REPOSITORY, "tag", "--list", "--sort=-version:refname", "*.*" | 
					
						
							| 
									
										
										
										
											2020-12-25 14:08:11 -05:00
										 |  |  |       ).lines.first.chomp | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if new_tag != old_tag | 
					
						
							| 
									
										
										
										
											2021-01-12 16:27:25 -05:00
										 |  |  |         Settings.write "latesttag", new_tag | 
					
						
							| 
									
										
										
										
											2020-12-25 14:08:11 -05:00
										 |  |  |         new_repository_version = new_tag | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 23:50:37 +00:00
										 |  |  |     Homebrew.failed = true if ENV["HOMEBREW_UPDATE_FAILED"] | 
					
						
							|  |  |  |     return if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hub = ReporterHub.new | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     updated_taps = [] | 
					
						
							|  |  |  |     Tap.each do |tap| | 
					
						
							| 
									
										
										
										
											2016-01-20 19:42:55 +08:00
										 |  |  |       next unless tap.git? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 16:41:34 +08:00
										 |  |  |       begin | 
					
						
							|  |  |  |         reporter = Reporter.new(tap) | 
					
						
							|  |  |  |       rescue Reporter::ReporterRevisionUnsetError => e | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |         onoe "#{e.message}\n#{e.backtrace.join "\n"}" if Homebrew::EnvConfig.developer? | 
					
						
							| 
									
										
										
										
											2016-02-25 16:41:34 +08:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       if reporter.updated? | 
					
						
							|  |  |  |         updated_taps << tap.name | 
					
						
							| 
									
										
										
										
											2020-07-26 09:45:18 +02:00
										 |  |  |         hub.add(reporter, preinstall: args.preinstall?) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-03-06 14:55:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     unless updated_taps.empty? | 
					
						
							| 
									
										
										
										
											2020-08-01 13:33:42 -04:00
										 |  |  |       update_preinstall_header args: args | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       puts_stdout_or_stderr \ | 
					
						
							|  |  |  |         "Updated #{updated_taps.count} #{"tap".pluralize(updated_taps.count)} (#{updated_taps.to_sentence})." | 
					
						
							| 
									
										
										
										
											2016-03-06 14:55:37 +08:00
										 |  |  |       updated = true | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-01-26 09:03:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-09 20:09:16 +11:00
										 |  |  |     if updated | 
					
						
							| 
									
										
										
										
											2016-09-03 19:36:34 +01:00
										 |  |  |       if hub.empty? | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |         puts_stdout_or_stderr "No changes to formulae." unless args.quiet? | 
					
						
							| 
									
										
										
										
											2016-09-03 19:36:34 +01:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2021-03-12 19:38:08 -08:00
										 |  |  |         hub.dump(updated_formula_report: !args.preinstall?) unless args.quiet? | 
					
						
							| 
									
										
										
										
											2016-09-03 19:36:34 +01:00
										 |  |  |         hub.reporters.each(&:migrate_tap_migration) | 
					
						
							| 
									
										
										
										
											2020-08-02 04:46:32 +02:00
										 |  |  |         hub.reporters.each { |r| r.migrate_formula_rename(force: args.force?, verbose: args.verbose?) } | 
					
						
							| 
									
										
										
										
											2018-10-13 08:22:51 -07:00
										 |  |  |         CacheStoreDatabase.use(:descriptions) do |db| | 
					
						
							|  |  |  |           DescriptionCacheStore.new(db) | 
					
						
							|  |  |  |                                .update_from_report!(hub) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-02-09 20:23:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:38:08 -08:00
										 |  |  |         if !args.preinstall? && !args.quiet? | 
					
						
							| 
									
										
										
										
											2021-02-09 20:23:16 +00:00
										 |  |  |           outdated_formulae = Formula.installed.count(&:outdated?) | 
					
						
							|  |  |  |           outdated_casks = Cask::Caskroom.casks.count(&:outdated?) | 
					
						
							| 
									
										
										
										
											2021-02-18 22:48:55 -05:00
										 |  |  |           update_pronoun = if (outdated_formulae + outdated_casks) == 1
 | 
					
						
							|  |  |  |             "it" | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             "them" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2021-02-09 20:23:16 +00:00
										 |  |  |           msg = "" | 
					
						
							|  |  |  |           if outdated_formulae.positive? | 
					
						
							|  |  |  |             msg += "#{Tty.bold}#{outdated_formulae}#{Tty.reset} outdated #{"formula".pluralize(outdated_formulae)}" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           if outdated_casks.positive? | 
					
						
							|  |  |  |             msg += " and " if msg.present? | 
					
						
							|  |  |  |             msg += "#{Tty.bold}#{outdated_casks}#{Tty.reset} outdated #{"cask".pluralize(outdated_casks)}" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           if msg.present? | 
					
						
							|  |  |  |             puts_stdout_or_stderr | 
					
						
							|  |  |  |             puts_stdout_or_stderr <<~EOS | 
					
						
							|  |  |  |               You have #{msg} installed. | 
					
						
							| 
									
										
										
										
											2021-02-18 22:48:55 -05:00
										 |  |  |               You can update #{update_pronoun} with #{Tty.bold}brew upgrade#{Tty.reset}. | 
					
						
							| 
									
										
										
										
											2021-02-09 20:23:16 +00:00
										 |  |  |             EOS | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-03 19:36:34 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-02-09 20:23:16 +00:00
										 |  |  |       puts_stdout_or_stderr if args.preinstall? | 
					
						
							| 
									
										
										
										
											2020-11-10 00:13:15 +11:00
										 |  |  |     elsif !args.preinstall? && !ENV["HOMEBREW_UPDATE_FAILED"] | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       puts_stdout_or_stderr "Already up-to-date." unless args.quiet? | 
					
						
							| 
									
										
										
										
											2016-01-26 09:03:28 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 18:03:40 -04:00
										 |  |  |     Commands.rebuild_commands_completion_list | 
					
						
							| 
									
										
										
										
											2016-09-30 18:22:53 -05:00
										 |  |  |     link_completions_manpages_and_docs | 
					
						
							|  |  |  |     Tap.each(&:link_completions_and_manpages) | 
					
						
							| 
									
										
										
										
											2020-12-23 12:06:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-28 01:51:40 -05:00
										 |  |  |     failed_fetch_dirs = ENV["HOMEBREW_FAILED_FETCH_DIRS"]&.split("\n") | 
					
						
							|  |  |  |     if failed_fetch_dirs.present? | 
					
						
							|  |  |  |       failed_fetch_taps = failed_fetch_dirs.map { |dir| Tap.from_path(dir) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       ofail <<~EOS | 
					
						
							|  |  |  |         Some taps failed to update! | 
					
						
							| 
									
										
										
										
											2021-01-28 01:51:40 -05:00
										 |  |  |         The following taps can not read their remote branches: | 
					
						
							|  |  |  |           #{failed_fetch_taps.join("\n  ")} | 
					
						
							| 
									
										
										
										
											2021-01-28 09:10:07 -05:00
										 |  |  |         This is happening because the remote branch was renamed or deleted. | 
					
						
							| 
									
										
										
										
											2021-01-28 01:51:40 -05:00
										 |  |  |         Reset taps to point to the correct remote branches by running `brew tap --repair` | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 12:06:28 -05:00
										 |  |  |     return if new_repository_version.blank? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-09 20:23:16 +00:00
										 |  |  |     puts_stdout_or_stderr | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |     ohai_stdout_or_stderr "Homebrew was updated to version #{new_repository_version}" | 
					
						
							| 
									
										
										
										
											2020-12-24 19:05:23 -05:00
										 |  |  |     if new_repository_version.split(".").last == "0" | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       puts_stdout_or_stderr <<~EOS | 
					
						
							| 
									
										
										
										
											2020-12-24 19:05:23 -05:00
										 |  |  |         More detailed release notes are available on the Homebrew Blog: | 
					
						
							| 
									
										
										
										
											2020-12-28 10:56:07 -05:00
										 |  |  |           #{Formatter.url("https://brew.sh/blog/#{new_repository_version}")} | 
					
						
							| 
									
										
										
										
											2020-12-24 19:05:23 -05:00
										 |  |  |       EOS | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       puts_stdout_or_stderr <<~EOS | 
					
						
							| 
									
										
										
										
											2020-12-24 19:05:23 -05:00
										 |  |  |         The changelog can be found at: | 
					
						
							|  |  |  |           #{Formatter.url("https://github.com/Homebrew/brew/releases/tag/#{new_repository_version}")} | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def shorten_revision(revision) | 
					
						
							| 
									
										
										
										
											2016-02-25 16:41:34 +08:00
										 |  |  |     Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--short", revision).chomp | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-02-26 17:39:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def install_core_tap_if_necessary | 
					
						
							| 
									
										
										
										
											2016-10-02 17:16:35 +01:00
										 |  |  |     return if ENV["HOMEBREW_UPDATE_TEST"] | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-26 17:39:49 +08:00
										 |  |  |     core_tap = CoreTap.instance | 
					
						
							|  |  |  |     return if core_tap.installed? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 12:09:52 +01:00
										 |  |  |     CoreTap.ensure_installed! | 
					
						
							| 
									
										
										
										
											2016-02-26 17:39:49 +08:00
										 |  |  |     revision = core_tap.git_head | 
					
						
							|  |  |  |     ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision | 
					
						
							|  |  |  |     ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-06-01 08:46:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 18:22:53 -05:00
										 |  |  |   def link_completions_manpages_and_docs(repository = HOMEBREW_REPOSITORY) | 
					
						
							| 
									
										
										
										
											2016-09-06 09:04:51 +01:00
										 |  |  |     command = "brew update" | 
					
						
							| 
									
										
										
										
											2021-01-11 12:24:48 -05:00
										 |  |  |     Utils::Link.link_completions(repository, command) | 
					
						
							| 
									
										
										
										
											2016-09-30 18:22:53 -05:00
										 |  |  |     Utils::Link.link_manpages(repository, command) | 
					
						
							|  |  |  |     Utils::Link.link_docs(repository, command) | 
					
						
							| 
									
										
										
										
											2016-09-20 08:03:06 +01:00
										 |  |  |   rescue => e | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     ofail <<~EOS | 
					
						
							| 
									
										
										
										
											2016-09-20 08:03:06 +01:00
										 |  |  |       Failed to link all completions, docs and manpages: | 
					
						
							|  |  |  |         #{e} | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2016-08-22 11:07:15 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Reporter | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |   class ReporterRevisionUnsetError < RuntimeError | 
					
						
							|  |  |  |     def initialize(var_name) | 
					
						
							|  |  |  |       super "#{var_name} is unset!" | 
					
						
							| 
									
										
										
										
											2016-01-20 19:41:42 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |   attr_reader :tap, :initial_revision, :current_revision | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def initialize(tap) | 
					
						
							|  |  |  |     @tap = tap | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-25 16:21:37 +02:00
										 |  |  |     initial_revision_var = "HOMEBREW_UPDATE_BEFORE#{tap.repo_var}" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     @initial_revision = ENV[initial_revision_var].to_s | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |     raise ReporterRevisionUnsetError, initial_revision_var if @initial_revision.empty? | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-25 16:21:37 +02:00
										 |  |  |     current_revision_var = "HOMEBREW_UPDATE_AFTER#{tap.repo_var}" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     @current_revision = ENV[current_revision_var].to_s | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |     raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty? | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 09:45:18 +02:00
										 |  |  |   def report(preinstall: false) | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |     return @report if @report | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @report = Hash.new { |h, k| h[k] = [] } | 
					
						
							|  |  |  |     return @report unless updated? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     diff.each_line do |line| | 
					
						
							|  |  |  |       status, *paths = line.split | 
					
						
							|  |  |  |       src = Pathname.new paths.first | 
					
						
							|  |  |  |       dst = Pathname.new paths.last | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       next unless dst.extname == ".rb" | 
					
						
							| 
									
										
										
										
											2016-08-05 16:00:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if paths.any? { |p| tap.cask_file?(p) } | 
					
						
							| 
									
										
										
										
											2020-07-13 22:48:53 +10:00
										 |  |  |         case status | 
					
						
							| 
									
										
										
										
											2020-08-19 13:44:08 +08:00
										 |  |  |         when "A" | 
					
						
							|  |  |  |           # Have a dedicated report array for new casks. | 
					
						
							|  |  |  |           @report[:AC] << tap.formula_file_to_name(src) | 
					
						
							| 
									
										
										
										
											2020-07-13 22:48:53 +10:00
										 |  |  |         when "D" | 
					
						
							| 
									
										
										
										
											2016-08-05 16:00:33 +01:00
										 |  |  |           # Have a dedicated report array for deleted casks. | 
					
						
							|  |  |  |           @report[:DC] << tap.formula_file_to_name(src) | 
					
						
							| 
									
										
										
										
											2020-07-13 22:48:53 +10:00
										 |  |  |         when "M" | 
					
						
							| 
									
										
										
										
											2020-03-02 17:08:24 -05:00
										 |  |  |           # Report updated casks | 
					
						
							|  |  |  |           @report[:MC] << tap.formula_file_to_name(src) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-08-05 16:00:33 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       next unless paths.any? { |p| tap.formula_file?(p) } | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       case status | 
					
						
							|  |  |  |       when "A", "D" | 
					
						
							| 
									
										
										
										
											2017-03-20 15:28:24 +02:00
										 |  |  |         full_name = tap.formula_file_to_name(src) | 
					
						
							|  |  |  |         name = full_name.split("/").last | 
					
						
							|  |  |  |         new_tap = tap.tap_migrations[name] | 
					
						
							|  |  |  |         @report[status.to_sym] << full_name unless new_tap | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       when "M" | 
					
						
							| 
									
										
										
										
											2020-07-20 00:21:51 +10:00
										 |  |  |         name = tap.formula_file_to_name(src) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Skip reporting updated formulae to speed up automatic updates. | 
					
						
							| 
									
										
										
										
											2020-07-26 09:45:18 +02:00
										 |  |  |         if preinstall | 
					
						
							| 
									
										
										
										
											2020-07-20 00:21:51 +10:00
										 |  |  |           @report[:M] << name | 
					
						
							|  |  |  |           next | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |         begin | 
					
						
							|  |  |  |           formula = Formulary.factory(tap.path/src) | 
					
						
							|  |  |  |           new_version = formula.pkg_version | 
					
						
							|  |  |  |           old_version = FormulaVersions.new(formula).formula_at_revision(@initial_revision, &:pkg_version) | 
					
						
							|  |  |  |           next if new_version == old_version | 
					
						
							| 
									
										
										
										
											2019-07-17 09:27:02 +01:00
										 |  |  |         rescue FormulaUnavailableError | 
					
						
							|  |  |  |           # Don't care if the formula isn't available right now. | 
					
						
							|  |  |  |           nil | 
					
						
							| 
									
										
										
										
											2017-10-07 00:31:28 +02:00
										 |  |  |         rescue Exception => e # rubocop:disable Lint/RescueException | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |           onoe "#{e.message}\n#{e.backtrace.join "\n"}" if Homebrew::EnvConfig.developer? | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-07-20 00:21:51 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |         @report[:M] << name | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       when /^R\d{0,3}/ | 
					
						
							| 
									
										
										
										
											2016-07-16 01:18:30 -04:00
										 |  |  |         src_full_name = tap.formula_file_to_name(src) | 
					
						
							|  |  |  |         dst_full_name = tap.formula_file_to_name(dst) | 
					
						
							|  |  |  |         # Don't report formulae that are moved within a tap but not renamed | 
					
						
							|  |  |  |         next if src_full_name == dst_full_name | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 01:18:30 -04:00
										 |  |  |         @report[:D] << src_full_name | 
					
						
							|  |  |  |         @report[:A] << dst_full_name | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 17:24:52 +00:00
										 |  |  |     renamed_formulae = Set.new | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |     @report[:D].each do |old_full_name| | 
					
						
							|  |  |  |       old_name = old_full_name.split("/").last | 
					
						
							|  |  |  |       new_name = tap.formula_renames[old_name] | 
					
						
							|  |  |  |       next unless new_name | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |       new_full_name = if tap.core_tap? | 
					
						
							|  |  |  |         new_name | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |         "#{tap}/#{new_name}" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       renamed_formulae << [old_full_name, new_full_name] if @report[:A].include? new_full_name | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 17:24:52 +00:00
										 |  |  |     @report[:A].each do |new_full_name| | 
					
						
							|  |  |  |       new_name = new_full_name.split("/").last | 
					
						
							|  |  |  |       old_name = tap.formula_renames.key(new_name) | 
					
						
							|  |  |  |       next unless old_name | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |       old_full_name = if tap.core_tap? | 
					
						
							|  |  |  |         old_name | 
					
						
							| 
									
										
										
										
											2017-01-02 17:24:52 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:06 +00:00
										 |  |  |         "#{tap}/#{old_name}" | 
					
						
							| 
									
										
										
										
											2017-01-02 17:24:52 +00:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       renamed_formulae << [old_full_name, new_full_name] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |     unless renamed_formulae.empty? | 
					
						
							|  |  |  |       @report[:A] -= renamed_formulae.map(&:last) | 
					
						
							|  |  |  |       @report[:D] -= renamed_formulae.map(&:first) | 
					
						
							| 
									
										
										
										
											2017-01-02 17:24:52 +00:00
										 |  |  |       @report[:R] = renamed_formulae.to_a | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |     @report | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def updated? | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |     initial_revision != current_revision | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |   def migrate_tap_migration | 
					
						
							| 
									
										
										
										
											2016-08-05 16:00:33 +01:00
										 |  |  |     (report[:D] + report[:DC]).each do |full_name| | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       name = full_name.split("/").last | 
					
						
							| 
									
										
										
										
											2016-07-26 00:15:21 +03:00
										 |  |  |       new_tap_name = tap.tap_migrations[name] | 
					
						
							|  |  |  |       next if new_tap_name.nil? # skip if not in tap_migrations list. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-18 13:18:46 -08:00
										 |  |  |       new_tap_user, new_tap_repo, new_tap_new_name = new_tap_name.split("/") | 
					
						
							|  |  |  |       new_name = if new_tap_new_name | 
					
						
							|  |  |  |         new_full_name = new_tap_new_name | 
					
						
							|  |  |  |         new_tap_name = "#{new_tap_user}/#{new_tap_repo}" | 
					
						
							|  |  |  |         new_tap_new_name | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         new_full_name = "#{new_tap_name}/#{name}" | 
					
						
							|  |  |  |         name | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-05 17:17:03 -05:00
										 |  |  |       # This means it is a cask | 
					
						
							| 
									
										
										
										
											2016-08-05 16:00:33 +01:00
										 |  |  |       if report[:DC].include? full_name | 
					
						
							| 
									
										
										
										
											2016-12-18 13:18:46 -08:00
										 |  |  |         next unless (HOMEBREW_PREFIX/"Caskroom"/new_name).exist? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-26 00:15:21 +03:00
										 |  |  |         new_tap = Tap.fetch(new_tap_name) | 
					
						
							|  |  |  |         new_tap.install unless new_tap.installed? | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |         ohai_stdout_or_stderr "#{name} has been moved to Homebrew.", <<~EOS | 
					
						
							| 
									
										
										
										
											2021-01-26 15:21:24 -05:00
										 |  |  |           To uninstall the cask, run: | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |             brew uninstall --cask --force #{name} | 
					
						
							| 
									
										
										
										
											2016-07-26 00:15:21 +03:00
										 |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2016-12-18 13:18:46 -08:00
										 |  |  |         next if (HOMEBREW_CELLAR/new_name.split("/").last).directory? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |         ohai_stdout_or_stderr "Installing #{new_name}..." | 
					
						
							| 
									
										
										
										
											2016-07-26 00:15:21 +03:00
										 |  |  |         system HOMEBREW_BREW_FILE, "install", new_full_name | 
					
						
							|  |  |  |         begin | 
					
						
							|  |  |  |           unless Formulary.factory(new_full_name).keg_only? | 
					
						
							| 
									
										
										
										
											2016-08-02 11:48:11 +01:00
										 |  |  |             system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite" | 
					
						
							| 
									
										
										
										
											2016-07-26 00:15:21 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-10-07 00:31:28 +02:00
										 |  |  |         rescue Exception => e # rubocop:disable Lint/RescueException | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |           onoe "#{e.message}\n#{e.backtrace.join "\n"}" if Homebrew::EnvConfig.developer? | 
					
						
							| 
									
										
										
										
											2016-07-26 00:15:21 +03:00
										 |  |  |         end | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       next unless (dir = HOMEBREW_CELLAR/name).exist? # skip if formula is not installed. | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       tabs = dir.subdirs.map { |d| Tab.for_keg(Keg.new(d)) } | 
					
						
							|  |  |  |       next unless tabs.first.tap == tap # skip if installed formula is not from this tap. | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       new_tap = Tap.fetch(new_tap_name) | 
					
						
							| 
									
										
										
										
											2016-06-22 16:36:17 +04:00
										 |  |  |       # For formulae migrated to cask: Auto-install cask or provide install instructions. | 
					
						
							| 
									
										
										
										
											2018-05-25 18:03:16 +02:00
										 |  |  |       if new_tap_name.start_with?("homebrew/cask") | 
					
						
							| 
									
										
										
										
											2016-11-05 15:37:28 -04:00
										 |  |  |         if new_tap.installed? && (HOMEBREW_PREFIX/"Caskroom").directory? | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |           ohai_stdout_or_stderr "#{name} has been moved to Homebrew Cask." | 
					
						
							|  |  |  |           ohai_stdout_or_stderr "brew unlink #{name}" | 
					
						
							| 
									
										
										
										
											2017-02-17 12:34:24 -05:00
										 |  |  |           system HOMEBREW_BREW_FILE, "unlink", name | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |           ohai_stdout_or_stderr "brew cleanup" | 
					
						
							| 
									
										
										
										
											2019-01-02 13:21:34 +00:00
										 |  |  |           system HOMEBREW_BREW_FILE, "cleanup" | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |           ohai_stdout_or_stderr "brew install --cask #{new_name}" | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |           system HOMEBREW_BREW_FILE, "install", "--cask", new_name | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |           ohai <<~EOS | 
					
						
							| 
									
										
										
										
											2018-09-03 20:12:29 +01:00
										 |  |  |             #{name} has been moved to Homebrew Cask. | 
					
						
							| 
									
										
										
										
											2017-02-17 12:34:24 -05:00
										 |  |  |             The existing keg has been unlinked. | 
					
						
							|  |  |  |             Please uninstall the formula when convenient by running: | 
					
						
							|  |  |  |               brew uninstall --force #{name} | 
					
						
							|  |  |  |           EOS | 
					
						
							| 
									
										
										
										
											2016-06-22 16:36:17 +04:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |           ohai_stdout_or_stderr "#{name} has been moved to Homebrew Cask.", <<~EOS | 
					
						
							| 
									
										
										
										
											2021-01-26 15:21:24 -05:00
										 |  |  |             To uninstall the formula and install the cask, run: | 
					
						
							| 
									
										
										
										
											2016-06-22 16:36:17 +04:00
										 |  |  |               brew uninstall --force #{name} | 
					
						
							| 
									
										
										
										
											2018-05-25 18:03:16 +02:00
										 |  |  |               brew tap #{new_tap_name} | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |               brew install --cask #{new_name} | 
					
						
							| 
									
										
										
										
											2016-06-22 16:36:17 +04:00
										 |  |  |           EOS | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         new_tap.install unless new_tap.installed? | 
					
						
							|  |  |  |         # update tap for each Tab | 
					
						
							|  |  |  |         tabs.each { |tab| tab.tap = new_tap } | 
					
						
							|  |  |  |         tabs.each(&:write) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-02 04:46:32 +02:00
										 |  |  |   def migrate_formula_rename(force:, verbose:) | 
					
						
							| 
									
										
										
										
											2017-03-29 11:22:59 +01:00
										 |  |  |     Formula.installed.each do |formula| | 
					
						
							|  |  |  |       next unless Migrator.needs_migration?(formula) | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-29 11:22:59 +01:00
										 |  |  |       oldname = formula.oldname | 
					
						
							|  |  |  |       oldname_rack = HOMEBREW_CELLAR/oldname | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if oldname_rack.subdirs.empty? | 
					
						
							|  |  |  |         oldname_rack.rmdir_if_possible | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       new_name = tap.formula_renames[oldname] | 
					
						
							| 
									
										
										
										
											2017-03-20 18:10:28 +02:00
										 |  |  |       next unless new_name | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       new_full_name = "#{tap}/#{new_name}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       begin | 
					
						
							|  |  |  |         f = Formulary.factory(new_full_name) | 
					
						
							| 
									
										
										
										
											2017-10-07 00:31:28 +02:00
										 |  |  |       rescue Exception => e # rubocop:disable Lint/RescueException | 
					
						
							| 
									
										
										
										
											2020-04-05 15:44:50 +01:00
										 |  |  |         onoe "#{e.message}\n#{e.backtrace.join "\n"}" if Homebrew::EnvConfig.developer? | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-02 14:32:31 +02:00
										 |  |  |       Migrator.migrate_if_needed(f, force: force) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   def diff | 
					
						
							|  |  |  |     Utils.popen_read( | 
					
						
							| 
									
										
										
										
											2016-02-25 15:34:11 +08:00
										 |  |  |       "git", "-C", tap.path, "diff-tree", "-r", "--name-status", "--diff-filter=AMDR", | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |       "-M85%", initial_revision, current_revision | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  | class ReporterHub | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 07:30:28 +02:00
										 |  |  |   extend Forwardable | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  |   attr_reader :reporters | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { void } | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   def initialize | 
					
						
							|  |  |  |     @hash = {} | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  |     @reporters = [] | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  |   def select_formula(key) | 
					
						
							|  |  |  |     @hash.fetch(key, []) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 09:45:18 +02:00
										 |  |  |   def add(reporter, preinstall: false) | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  |     @reporters << reporter | 
					
						
							| 
									
										
										
										
											2020-07-26 09:45:18 +02:00
										 |  |  |     report = reporter.report(preinstall: preinstall).delete_if { |_k, v| v.empty? } | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  |     @hash.update(report) { |_key, oldval, newval| oldval.concat(newval) } | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-13 05:04:35 +01:00
										 |  |  |   delegate empty?: :@hash | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 00:21:51 +10:00
										 |  |  |   def dump(updated_formula_report: true) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     # Key Legend: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dump_formula_report :A, "New Formulae" | 
					
						
							| 
									
										
										
										
											2020-07-20 00:21:51 +10:00
										 |  |  |     if updated_formula_report | 
					
						
							|  |  |  |       dump_formula_report :M, "Updated Formulae" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       updated = select_formula(:M).count | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       if updated.positive? | 
					
						
							|  |  |  |         ohai_stdout_or_stderr "Updated Formulae", | 
					
						
							|  |  |  |                               "Updated #{updated} #{"formula".pluralize(updated)}." | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-20 00:21:51 +10:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     dump_formula_report :R, "Renamed Formulae" | 
					
						
							|  |  |  |     dump_formula_report :D, "Deleted Formulae" | 
					
						
							| 
									
										
										
										
											2020-08-19 13:44:08 +08:00
										 |  |  |     dump_formula_report :AC, "New Casks" | 
					
						
							| 
									
										
										
										
											2020-12-14 19:49:35 -05:00
										 |  |  |     if updated_formula_report | 
					
						
							|  |  |  |       dump_formula_report :MC, "Updated Casks" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       updated = select_formula(:MC).count | 
					
						
							| 
									
										
										
										
											2021-02-03 13:31:24 +00:00
										 |  |  |       if updated.positive? | 
					
						
							|  |  |  |         ohai_stdout_or_stderr "Updated Casks", | 
					
						
							|  |  |  |                               "Updated #{updated} #{"cask".pluralize(updated)}." | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-12-14 19:49:35 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-03-03 10:03:46 -05:00
										 |  |  |     dump_formula_report :DC, "Deleted Casks" | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  |   private | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def dump_formula_report(key, title) | 
					
						
							| 
									
										
										
										
											2020-09-11 11:59:47 +01:00
										 |  |  |     only_installed = Homebrew::EnvConfig.update_report_only_installed? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  |     formulae = select_formula(key).sort.map do |name, new_name| | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |       # Format list items of renamed formulae | 
					
						
							| 
									
										
										
										
											2017-04-04 15:15:42 +01:00
										 |  |  |       case key | 
					
						
							|  |  |  |       when :R | 
					
						
							| 
									
										
										
										
											2016-02-25 15:43:02 +08:00
										 |  |  |         name = pretty_installed(name) if installed?(name) | 
					
						
							|  |  |  |         new_name = pretty_installed(new_name) if installed?(new_name) | 
					
						
							| 
									
										
										
										
											2020-09-11 11:59:47 +01:00
										 |  |  |         "#{name} -> #{new_name}" unless only_installed | 
					
						
							| 
									
										
										
										
											2017-04-04 15:15:42 +01:00
										 |  |  |       when :A | 
					
						
							| 
									
										
										
										
											2020-09-11 11:59:47 +01:00
										 |  |  |         name if !installed?(name) && !only_installed | 
					
						
							| 
									
										
										
										
											2020-08-19 13:44:08 +08:00
										 |  |  |       when :AC | 
					
						
							| 
									
										
										
										
											2020-09-11 11:59:47 +01:00
										 |  |  |         name.split("/").last if !cask_installed?(name) && !only_installed | 
					
						
							| 
									
										
										
										
											2020-03-05 11:14:37 -05:00
										 |  |  |       when :MC, :DC | 
					
						
							|  |  |  |         name = name.split("/").last | 
					
						
							| 
									
										
										
										
											2020-09-11 11:59:47 +01:00
										 |  |  |         if cask_installed?(name) | 
					
						
							|  |  |  |           pretty_installed(name) | 
					
						
							|  |  |  |         elsif !only_installed | 
					
						
							|  |  |  |           name | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2020-09-11 11:59:47 +01:00
										 |  |  |         if installed?(name) | 
					
						
							|  |  |  |           pretty_installed(name) | 
					
						
							|  |  |  |         elsif !only_installed | 
					
						
							|  |  |  |           name | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-04-04 15:15:42 +01:00
										 |  |  |     end.compact | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-23 22:02:23 +02:00
										 |  |  |     return if formulae.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-23 22:02:23 +02:00
										 |  |  |     # Dump formula list. | 
					
						
							| 
									
										
										
										
											2020-07-06 15:30:57 -04:00
										 |  |  |     ohai title, Formatter.columns(formulae.sort) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def installed?(formula) | 
					
						
							|  |  |  |     (HOMEBREW_CELLAR/formula.split("/").last).directory? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-03-05 11:14:37 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def cask_installed?(cask) | 
					
						
							|  |  |  |     (Cask::Caskroom.path/cask).directory? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | end |