These can return `true`, `false` or `nil` so adjust the signature to
note this and fix the call sites to ensure we don't accidentally pass
through `nil` values when we shouldn't.
While we're here, make a `TODO` to fix this bad API up in future.
Fixes https://github.com/Homebrew/brew/issues/19076
- `reinstall` and `upgrade` no longer mark as installed on request,
with or without names specified, but preserve the version from the
tab instead
- default `install_on_request` to `false` rather than `true`
- only set installed in request in a tab if it's missing rather than
false
Co-authored-by: Michael Cho <michael@michaelcho.dev>
- Previously I thought that comments were fine to discourage people from
wasting their time trying to bump things that used `undef` that Sorbet
didn't support. But RuboCop is better at this since it'll complain if
the comments are unnecessary.
- Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501.
- I've gone for a mixture of `rubocop:disable` for the files that can't
be `typed: strict` (use of undef, required before everything else, etc)
and `rubocop:todo` for everything else that should be tried to make
strictly typed. There's no functional difference between the two as
`rubocop:todo` is `rubocop:disable` with a different name.
- And I entirely disabled the cop for the docs/ directory since
`typed: strict` isn't going to gain us anything for some Markdown
linting config files.
- This means that now it's easier to track what needs to be done rather
than relying on checklists of files in our big Sorbet issue:
```shell
$ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l
268
```
- And this is confirmed working for new files:
```shell
$ git status
On branch use-rubocop-for-sorbet-strict-sigils
Untracked files:
(use "git add <file>..." to include in what will be committed)
Library/Homebrew/bad.rb
Library/Homebrew/good.rb
nothing added to commit but untracked files present (use "git add" to track)
$ brew style
Offenses:
bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true.
^^^^^^^^^^^^^
1340 files inspected, 1 offense detected
```
If you're e.g. running Homebrew over `sudo`: shelling out to `whoami`
is less effective than just telling people which user you're running
as when we run the check.
This commit fixes an error introduced in 6c964d4a78, which would
surface on certain install/reinstall/upgrade failures.
Example:
```
==> Patching
patching file default_out.txt
Hunk #2 FAILED at 11.
1 out of 2 hunks FAILED -- saving rejects to file default_out.txt.rej
Error: wrong number of arguments (given 3, expected 2)
/usr/local/Homebrew/Library/Homebrew/reinstall.rb:77:in `restore_backup'
/usr/local/Homebrew/Library/Homebrew/reinstall.rb:52:in `block in reinstall_formula'
/usr/local/Homebrew/Library/Homebrew/utils.rb:377:in `ignore_interrupts'
/usr/local/Homebrew/Library/Homebrew/reinstall.rb:52:in `rescue in reinstall_formula'
/usr/local/Homebrew/Library/Homebrew/reinstall.rb:10:in `reinstall_formula'
/usr/local/Homebrew/Library/Homebrew/cmd/reinstall.rb:71:in `block in reinstall'
/usr/local/Homebrew/Library/Homebrew/cmd/reinstall.rb:65:in `each'
/usr/local/Homebrew/Library/Homebrew/cmd/reinstall.rb:65:in `reinstall'
/usr/local/Homebrew/Library/Homebrew/brew.rb:112:in `<main>'
```
This ensures that dependencies are verified and tapped before they are
fetched. `FormulaInstaller#lock` has been moved into
`FormulaInstaller#install` to avoid locking until necessary.
While we're here, don't compute dependencies before fetching if we're
not going to use them.
Refactor the CLI::Args module so it doesn't have different paths to
check arguments depending on whether the arguments have been parsed or
not. Instead, set the values we need from the global ARGV at
first, global initialisation time where they will be thrown away when
the actual arguments are parsed.
To do this some other general refactoring was needed:
- more methods made private when possible
- e.g. `HEAD?` used consistently instead of `head` before arguments
are parsed.
- formula options are only parsed after named arguments are extracted
Apply the same changes from #6066.
Also apply the same logics from `brew upgrade` to preserve
`installed_as_dependency`/`installed_on_request` settings
when reinstalling formulae.
- We've never supported `devel` bottles so don't bother outputting their
status to `brew info`
- Don't `brew upgrade` or `brew reinstall` bottles if they were
previously built as a bottle unless there's no bottles defined at all
(rather than there was no compatible bottles). Fixes#5532.
After upgrading existing kegs, we now search and upgrade their
dependents as well. If any are detected that have broken linkage, they
are reinstalled from source.
If there are any formulae in the dependents tree that are pinned, they
are only reinstalled if they're not outdated; in all cases, a suitable
message is printed detailing the kegs that will be acted upon.