Merge pull request #12691 from boblail/lail/add-overwrite-flag-to-brew-install

Add flag `--overwrite` to `brew install` to govern the keg-linking step
This commit is contained in:
Mike McQuaid 2022-01-13 10:35:52 +00:00 committed by GitHub
commit f11a752d32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 4 deletions

View File

@ -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"

View File

@ -112,6 +112,9 @@ module Homebrew
[: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
@ -226,6 +229,7 @@ module Homebrew
interactive: args.interactive?,
keep_tmp: args.keep_tmp?,
force: args.force?,
overwrite: args.overwrite?,
debug: args.debug?,
quiet: args.quiet?,
verbose: args.verbose?,

View File

@ -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 @@ class FormulaInstaller
cc: nil,
options: Options.new,
force: false,
overwrite: false,
debug: false,
quiet: false,
verbose: false
@ -71,6 +72,7 @@ class FormulaInstaller
@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 @@ class FormulaInstaller
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 @@ class FormulaInstaller
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)

View File

@ -268,6 +268,7 @@ module Homebrew
interactive: false,
keep_tmp: false,
force: false,
overwrite: false,
debug: false,
quiet: false,
verbose: false
@ -291,6 +292,7 @@ module Homebrew
interactive: interactive,
keep_tmp: keep_tmp,
force: force,
overwrite: overwrite,
debug: debug,
quiet: quiet,
verbose: verbose,