Homebrew / install

📥 Homebrew (un)installer
https://brew.sh
BSD 2-Clause "Simplified" License
2.15k stars 1.02k forks source link

Brew update on clean M2 MacOS .pkg install prints "fatal: cannot force update the branch 'master' checked out at '/opt/homebrew'" #847

Closed johnmcdowell closed 4 months ago

johnmcdowell commented 4 months ago

brew gist-logs <formula> link OR brew config AND brew doctor output

john@Johns-Air homebrew % brew config
HOMEBREW_VERSION: 4.2.20
ORIGIN: https://github.com/Homebrew/brew
HEAD: c2ed3327c605c3e738359c9807b8f4cd6fec09eb
Last commit: 4 days ago
Core tap JSON: 02 May 18:56 UTC
Core cask tap JSON: 02 May 18:56 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 3.1.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: octa-core 64-bit arm_blizzard_avalanche
Clang: 15.0.0 build 1500
Git: 2.39.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 8.4.0 => /usr/bin/curl
macOS: 14.4.1-arm64
CLT: 15.3.0.0.1.1708646388
Xcode: N/A
Rosetta 2: false
john@Johns-Air homebrew % brew doctor
Your system is ready to brew.

Verification

What were you trying to do (and why)?

Perform an initial brew update after .pkg installation on Apple Silicon without seeing a fatal error in the output

What happened (include all command output)?

Used GUI .pkg installer of latest homebrew from Releases -> Assets

Ran brew update:

john@Johns-Air ~ % brew update
==> Updating Homebrew...
fatal: cannot force update the branch 'master' checked out at '/opt/homebrew'
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:d783cbeb6e6ef0d71c0b442317b54554370decd6fac66bf2d4938c07a63f67be
######################################################################### 100.0%
==> Pouring portable-ruby-3.1.4.arm64_big_sur.bottle.tar.gz
==> Homebrew collects anonymous analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics have been recorded yet (nor will be during this `brew` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
espeak-ng                  task@2                     traefik@2
[...]

What did you expect to happen?

Not see any fatal errors on first invocation of brew update

Step-by-step reproduction instructions (by running brew commands)

Observe:

john@Johns-Air ~ % brew update
==> Updating Homebrew...
fatal: cannot force update the branch 'master' checked out at '/opt/homebrew'
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-[...]

Note that brew update DOES fix the problem and subsequent brew updates do not have this fatal error.

However, it seems unacceptable that a clean install of brew via the .pkg should reproducibly produce a fatal error when clean installed. This is an ugly look for what should be considered a first class package manager. There is no way to submit an issue to homebrew-core with issues that only occur on the first brew update, but we should not require users to have to ignore errors marked fatal.

I think EITHER there should be code in brew update to handle whatever was handled without showing a fatal error OR the pkg installer should not install the state that brew update generates a fatal error. (I'm not sure which.)

I did not run these commands before running brew update, but perhaps it's useful or interesting that after the first brew update after install prints:

==> Updating Homebrew...
fatal: cannot force update the branch 'master' checked out at '/opt/homebrew'

Then I see a different branch here:

john@Johns-Air ~ % cd /opt/homebrew
john@Johns-Air homebrew % git status
On branch stable
nothing to commit, working tree clean
dkav commented 4 months ago

I am experiencing this issue in an existing install. It has occurred a couple of times. I haven't been able to isolate the pattern yet.

dkav commented 4 months ago

I can repeat the error consistently with following:

brew developer on 
brew update
git reset --hard 3d31594e39
brew developer off 
brew update

Obviously this is just a test scenario, so I am not exactly sure what pattern is causing the issue for me in more normal usage.

brew update --debug output with error attached: brew_update_debug.txt

dkav commented 4 months ago

Issue also referenced in discussion - Error message "fatal: cannot force update the branch 'master' checked out at '/opt/homebrew'" when installing Homebrew #5113

johnmcdowell commented 4 months ago

Issue also referenced in discussion - Error message "fatal: cannot force update the branch 'master' checked out at '/opt/homebrew'" when installing Homebrew #5113

This other thread also refers to the error only directly after install on Apple Silicon macs, which is where I saw the issue also.

It's interesting that you also have seen it in a case not right after install-- maybe there are multiple ways to hit the state with the fatal error.

Perhaps it'd be helpful if someone doing a fresh install of homebrew on Apple Silicon ran their first brew update with --debug. (I'm hesitant to try to fully uninstall on my work machine with other packages installed.)