When running brew commands and interpreting the output, e.g. running
`brew livecheck --json`, it's necessary to stop other programs Homebrew
happens to execute from writing logging output to stdout. Most programs
don't do this, but `bundle install` does seem to.
To reproduce the issue you can run:
```shell
git -C "$(brew --prefix)" clean -ffdx Library/Homebrew/vendor
stdout=$(HOMEBREW_FORCE_VENDOR_RUBY=1 brew livecheck --newer-only --json --cask $(brew --repo homebrew/cask)/Casks/grid.rb)
echo "^^^ was stderr, >>> is stdout: $stdout"
```
If you run it without this change it will print a bunch of output like
this to the stdout before printing out the livecheck JSON output:
```text
Using bundler 1.17.3
Fetching byebug 11.1.3
Fetching coderay 1.1.3
Installing byebug 11.1.3 with native extensions
Installing coderay 1.1.3
Fetching colorize 0.8.1
Installing colorize 0.8.1
[
# Contents of the JSON block.
]
```
With this change the stdout from `bundle install` will be redirected to
brew's stderr, meaning only the JSON goes to stdout, and the rest goes
to stderr.
We're using essentially the same logic to setup Git for committing in
multiple places but the way we're doing so is inconsistent. Moved to
using two shared utility methods and use them consistently.
This provides a more consistent version for `rubocop` than relying on
`Homebrew.install_gem_setup_path!` (and we really want `brew style` to
provide consistent output).