From 9b678c365be1d0e347b2b6a14d32a496e7161c7d Mon Sep 17 00:00:00 2001 From: Bob Lail Date: Mon, 10 Jan 2022 10:05:44 -0600 Subject: [PATCH 1/2] Add flag `--overwrite` to `brew install` to govern the keg-linking step Allows you to avoid the `Keg::ConflictError` recommending that you invoke `brew link --overwrite` in scenarios when you know that that's how you'd proceed anyway. --- Library/Homebrew/cmd/install.rb | 6 ++++++ Library/Homebrew/formula_installer.rb | 8 +++++--- Library/Homebrew/install.rb | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 940e6a082c174..56a1b0ed6f946 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -22,6 +22,7 @@ module Homebrew sig { returns(CLI::Parser) } def install_args + # rubocop:disable Metrics/BlockLength Homebrew::CLI::Parser.new do description <<~EOS Install a or . Additional options specific to a may be @@ -112,6 +113,9 @@ def install_args [:switch, "-g", "--git", { description: "Create a Git repository, useful for creating patches to the software.", }], + [:switch, "--overwrite", { + description: "Delete files that already exist in the prefix while linking.", + }], ].each do |*args, **options| send(*args, **options) conflicts "--cask", args.last @@ -132,6 +136,7 @@ def install_args named_args [:formula, :cask], min: 1 end + # rubocop:enable Metrics/BlockLength end def install @@ -226,6 +231,7 @@ def install interactive: args.interactive?, keep_tmp: args.keep_tmp?, force: args.force?, + overwrite: args.overwrite?, debug: args.debug?, quiet: args.quiet?, verbose: args.verbose?, diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 0a51b1fbb78b7..45163ad2d2d0b 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -38,7 +38,7 @@ class FormulaInstaller attr_predicate :installed_as_dependency?, :installed_on_request? attr_predicate :show_summary_heading?, :show_header? - attr_predicate :force_bottle?, :ignore_deps?, :only_deps?, :interactive?, :git?, :force?, :keep_tmp? + attr_predicate :force_bottle?, :ignore_deps?, :only_deps?, :interactive?, :git?, :force?, :overwrite?, :keep_tmp? attr_predicate :verbose?, :debug?, :quiet? # TODO: Remove when removed from `test-bot`. @@ -64,6 +64,7 @@ def initialize( cc: nil, options: Options.new, force: false, + overwrite: false, debug: false, quiet: false, verbose: false @@ -71,6 +72,7 @@ def initialize( @formula = formula @env = env @force = force + @overwrite = overwrite @keep_tmp = keep_tmp @link_keg = !formula.keg_only? || link_keg @show_header = show_header @@ -951,7 +953,7 @@ def link(keg) unless link_keg begin - keg.optlink(verbose: verbose?) + keg.optlink(verbose: verbose?, overwrite: overwrite?) rescue Keg::LinkError => e ofail "Failed to create #{formula.opt_prefix}" puts "Things that depend on #{formula.full_name} will probably not build." @@ -982,7 +984,7 @@ def link(keg) backup_dir = HOMEBREW_CACHE/"Backup" begin - keg.link(verbose: verbose?) + keg.link(verbose: verbose?, overwrite: overwrite?) rescue Keg::ConflictError => e conflict_file = e.dst if formula.link_overwrite?(conflict_file) && !link_overwrite_backup.key?(conflict_file) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 24b02c78e92bd..e93121518e734 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -268,6 +268,7 @@ def install_formulae( interactive: false, keep_tmp: false, force: false, + overwrite: false, debug: false, quiet: false, verbose: false @@ -291,6 +292,7 @@ def install_formulae( interactive: interactive, keep_tmp: keep_tmp, force: force, + overwrite: overwrite, debug: debug, quiet: quiet, verbose: verbose, From 26ea79e1e67886411c922d70efb69c9d1e967f06 Mon Sep 17 00:00:00 2001 From: Bob Lail Date: Tue, 11 Jan 2022 08:34:51 -0600 Subject: [PATCH 2/2] Increase Metrics/BlockLength limit instead of disabling the cop for the block in `install_args` --- Library/Homebrew/.rubocop.yml | 2 +- Library/Homebrew/cmd/install.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 9f8b3cad11d7f..8e9dde07fd81d 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -16,7 +16,7 @@ Lint/NestedMethodDefinition: Metrics/AbcSize: Max: 280 Metrics/BlockLength: - Max: 103 + Max: 106 Exclude: # TODO: extract more of the bottling logic - "dev-cmd/bottle.rb" diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 56a1b0ed6f946..ae56fc16d64ed 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -22,7 +22,6 @@ module Homebrew sig { returns(CLI::Parser) } def install_args - # rubocop:disable Metrics/BlockLength Homebrew::CLI::Parser.new do description <<~EOS Install a or . Additional options specific to a may be @@ -136,7 +135,6 @@ def install_args named_args [:formula, :cask], min: 1 end - # rubocop:enable Metrics/BlockLength end def install