Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew cleanup breaks ruby gems downloaded by bundler from git source #17230

Open
3 tasks done
stefansundin opened this issue May 6, 2024 · 2 comments
Open
3 tasks done
Labels
bug Reproducible Homebrew/brew bug help wanted We want help addressing this

Comments

@stefansundin
Copy link
Contributor

brew doctor output

Your system is ready to brew.

Verification

  • My "brew doctor output" above says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update twice and am still able to reproduce my issue.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

HOMEBREW_VERSION: 4.2.20-108-g7e0c137
ORIGIN: https://github.com/Homebrew/brew
HEAD: 7e0c137955d269befdd69f01fa989fb38c2b49b5
Last commit: 32 hours ago
Core tap HEAD: aed95828f408efc65c54031a59d715dff7dd8d52
Core tap last commit: 25 minutes ago
Core tap JSON: 06 May 01:19 UTC
Core cask tap HEAD: 54aca2bdbae5efeb6d337653fd48b4842724024f
Core cask tap last commit: 12 minutes ago
Core cask tap JSON: 06 May 01:19 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DEVELOPER: set
HOMEBREW_EDITOR: subl
HOMEBREW_MAKE_JOBS: 8
HOMEBREW_NO_ANALYTICS: set
HOMEBREW_NO_AUTO_UPDATE: set
HOMEBREW_NO_EMOJI: set
HOMEBREW_NO_INSTALL_CLEANUP: set
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 3.1.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 15.0.0 build 1500
Git: 2.45.0 => /opt/homebrew/bin/git
Curl: 8.4.0 => /usr/bin/curl
macOS: 14.4.1-arm64
CLT: 15.3.0.0.1.1708646388
Xcode: 15.1
Rosetta 2: false

What were you trying to do (and why)?

I have a ruby project with a Gemfile that sources a gem from a git source. When I run bundle update to check for gem updates, this particular gem has been having issues, seemingly randomly. Today I figured out that this issue happens after brew cleanup has been run.

What happened (include all command output)?

$ cd homebrew-bug-repro
$ ls
Gemfile
$ cat Gemfile
source "https://rubygems.org"
gem "clogger", git: "http://bogomips.org/clogger.git"
$ bundle install
Fetching http://bogomips.org/clogger.git
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/..
Bundle complete! 1 Gemfile dependency, 3 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
$ bundle update
Fetching http://bogomips.org/clogger.git
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/..
Bundle updated!
$ bundle show clogger
/opt/homebrew/lib/ruby/gems/3.3.0/bundler/gems/clogger-4ae4cf792bd7

At this point, everything is working just fine. Here's how to break it:

$ brew cleanup --dry-run
Would remove (empty directory): /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f/refs/tags
Would remove (empty directory): /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f/refs/heads
Would remove (empty directory): /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f/refs
Would remove (empty directory): /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f/objects/info
$ brew cleanup
Pruned 0 symbolic links and 4 directories from /opt/homebrew

$ bundle update
Fetching http://bogomips.org/clogger.git

Retrying `git fetch --force --quiet --no-tags --depth 1 -- http://bogomips.org/clogger.git refs/heads/master:refs/heads/master` at /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --no-tags --depth 1 -- http://bogomips.org/clogger.git refs/heads/master:refs/heads/master` in directory /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f has failed.
fatal: refusing to fetch into branch 'refs/heads/master' checked out at '/opt/homebrew'

Retrying `git fetch --force --quiet --no-tags --depth 1 -- http://bogomips.org/clogger.git refs/heads/master:refs/heads/master` at /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f due to error (3/4): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --no-tags --depth 1 -- http://bogomips.org/clogger.git refs/heads/master:refs/heads/master` in directory /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f has failed.
fatal: refusing to fetch into branch 'refs/heads/master' checked out at '/opt/homebrew'

Retrying `git fetch --force --quiet --no-tags --depth 1 -- http://bogomips.org/clogger.git refs/heads/master:refs/heads/master` at /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f due to error (4/4): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --no-tags --depth 1 -- http://bogomips.org/clogger.git refs/heads/master:refs/heads/master` in directory /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f has failed.
fatal: refusing to fetch into branch 'refs/heads/master' checked out at '/opt/homebrew'

Git error: command `git fetch --force --quiet --no-tags --depth 1 -- http://bogomips.org/clogger.git refs/heads/master:refs/heads/master` in directory /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f has failed.
fatal: refusing to fetch into branch 'refs/heads/master' checked out at '/opt/homebrew'

The fix is to manually delete the directory at /opt/homebrew/lib/ruby/gems/3.3.0/cache/bundler/git/clogger-b0c912e9759a20a9c2aa868294b5d44dfbaf537f and then run bundle update again.

I don't know the best fix for this problem, but maybe brew cleanup shouldn't mess with the ruby gems directory at all? Or maybe check that the empty directories do not belong to bare git repository?

What did you expect to happen?

I expect brew cleanup to not break bundle update.

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

Included above.
@stefansundin stefansundin added the bug Reproducible Homebrew/brew bug label May 6, 2024
@MikeMcQuaid
Copy link
Member

Or maybe check that the empty directories do not belong to bare git repository?

This seems reasonable.

That said: we should probably configure our Rubies/Bundlers to set BUNDLE_PATH: "vendor/ruby" and maybe BUNDLE_DISABLE_SHARED_GEMS: "true" by default. Installing to the Homebrew prefix should be avoided for reasons exactly like this.

@MikeMcQuaid MikeMcQuaid added the help wanted We want help addressing this label May 6, 2024
@Bo98
Copy link
Member

Bo98 commented May 6, 2024

Yep, this is a known issue seen in our own projects too. Thanks for filing an issue on this to track.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible Homebrew/brew bug help wanted We want help addressing this
Projects
None yet
Development

No branches or pull requests

3 participants