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

Git source fails to update when default branch is renamed #5810

Open
spohlenz opened this issue Aug 3, 2022 · 3 comments
Open

Git source fails to update when default branch is renamed #5810

spohlenz opened this issue Aug 3, 2022 · 3 comments

Comments

@spohlenz
Copy link

spohlenz commented Aug 3, 2022

Describe the problem as clearly as you can

I have recently changed the default branch in a number of my gem repositories from master to main. In doing so, this seems to have broken updates from dependent projects which use a git source (with no explicit branch) in their Gemfiles.

Post steps to reproduce the problem

  1. Create a new gem (using bundle gem) and push to GitHub. I've used https://github.com/spohlenz/test_gem.
  2. Create a Gemfile in another folder referencing this gem. Run bundle install.
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'test_gem', github: 'spohlenz/test_gem'
  1. Rename the gem repo's default branch on GitHub. Then push a change to the repo.
  2. Run bundle update within the dependent project. The Gemfile.lock still references the old default branch and commit pushed in step 3 isn't reflected.

I thought I could perhaps explicitly specify a branch for the repo in the Gemfile, and then remove it. e.g.

gem 'test_gem', github: 'spohlenz/test_gem', branch: 'renamed'

Running bundle update with the explicit branch option in place does bring in the new changes, but when it is removed, a subsequent bundle update reverts it back to the original default branch.

If this isn't an easy fix within bundler itself, is there an easy way to clear the cached git checkout? I've scoured the command options and couldn't find a relevant one that worked.

If not included with the output of your command, run bundle env and paste the output below

In case it is relevant:

Environment

Bundler             2.3.19
  Platforms         ruby, x86_64-darwin-21
Ruby                2.7.5p203 (2021-11-24 revision f69aeb83146be640995753667fdd6c6f157527f5) [x86_64-darwin-21]
  Full Path         /Users/sam/.rvm/rubies/ruby-2.7.5/bin/ruby
  Config Dir        /Users/sam/.rvm/rubies/ruby-2.7.5/etc
RubyGems            3.1.6
  Gem Home          /Users/sam/.rvm/gems/ruby-2.7.5
  Gem Path          /Users/sam/.rvm/gems/ruby-2.7.5:/Users/sam/.rvm/rubies/ruby-2.7.5/lib/ruby/gems/2.7.0
  User Home         /Users/sam
  User Path         /Users/sam/.gem/ruby/2.7.0
  Bin Dir           /Users/sam/.rvm/gems/ruby-2.7.5/bin
Tools               
  Git               2.32.1 (Apple Git-133)
  RVM               1.29.12 (latest)
  rbenv             not installed
  chruby            not installed
  rubygems-bundler  (1.4.5)

Bundler Build Metadata

Built At          2022-07-27
Git SHA           4f496f93e6
Released Version  true

Bundler settings

gem.changelog
  Set for the current user (/Users/sam/.bundle/config): true
gem.ci
  Set for the current user (/Users/sam/.bundle/config): false
gem.coc
  Set for the current user (/Users/sam/.bundle/config): false
gem.linter
  Set for the current user (/Users/sam/.bundle/config): false
gem.mit
  Set for the current user (/Users/sam/.bundle/config): false
gem.test
  Set for the current user (/Users/sam/.bundle/config): false

Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'test_gem', github: 'spohlenz/test_gem'

Gemfile.lock

GIT
  remote: https://github.com/spohlenz/test_gem.git
  revision: 78543de0c3929011b347073df15bf10f394b1cf3
  specs:
    test_gem (0.1.0)

GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  x86_64-darwin-21

DEPENDENCIES
  test_gem!

BUNDLED WITH
   2.3.19
@deivid-rodriguez
Copy link
Member

deivid-rodriguez commented Aug 3, 2022

Hi @spohlenz. This sounds indeed be tricky to implement, I think we might need to add a git remote set-head origin --auto on the bare clone, but I doubt it's as simple as that.

I think the cache folder you're looking for is at /Users/sam/.rvm/gems/ruby-2.7.5/cache/bundler/git/test-gem-*. Removing that and rerunning bundle update may fix things.

@simi
Copy link
Member

simi commented Aug 3, 2022

🤔 We can also improve bundle pristine to clone again git sources from scratch.

@deivid-rodriguez
Copy link
Member

I think that's a very good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants