How to deal with forked gems and bundle

775 views Asked by At

I've forked a gem and it is hosted on Github.

Then, in Gemfile this is what I've got:

gem 'mongoid-scroll', git: 'https://github.com/bgvo/mongoid-scroll.git'

Whenever I make changes to the gem using Pry gem-opem command, changes are saved under the following directory:

/Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/ruby/2.1.0/bundler/gems/

Some things confuse me:

1) In this directory there are two mongoid-scroll gems (mongoid-scroll-7e23e72653c6 and mongoid-scroll-23bc60ce76bd) instead of just one. I thought that the gems inside this directory were the gems used when running bundler. How does bundler determine that this is the one to use an not the other one?

2) If I try to push changes to the Github repo:

Borjas-MacBook-Pro:mongoid-scroll-7e23e72653c6 borjagvo$ git push
Counting objects: 10, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 1.00 KiB | 0 bytes/s, done.
Total 10 (delta 6), reused 0 (delta 0)
To /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/ruby/2.1.0/cache/bundler/git/mongoid-scroll-f814a84d6332ef5d28cf5db04da93b434e01f07b
   d8f9f91..696bdce  master -> master

I see that Github repo is not where changes are uploaded to. Executing git config --get remote.origin.url to see origin:

Borjas-MacBook-Pro:mongoid-scroll-7e23e72653c6 borjagvo$ git remote show origin
* remote origin
  Fetch URL: /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/ruby/2.1.0/cache/bundler/git/mongoid-scroll-    f814a84d6332ef5d28cf5db04da93b434e01f07b
  Push  URL: /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/ruby/2.1.0/cache/bundler/git/mongoid-scroll-    f814a84d6332ef5d28cf5db04da93b434e01f07b
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

What is a good way to upload changes to forked repo in Github from bundler used gem (remember that I'm using Pry command gem-open).

Thanks.

1

There are 1 answers

4
rmagnum2002 On BEST ANSWER

Gemfile.lock should know what gem to load, when you do bundle update or installing a new gem, Gemfile.lock will be updated too with new gems, paths, etc.. and also the revision hash.

The hash at the end of the Fetch/Push URL that you see when you run git remote show origin must be the same as the revision from Gemfile.lock.

For example in my case with active-admin gem in Gemfile.lock I have:

GIT
  remote: git://github.com/gregbell/active_admin.git
  revision: b7e8c7dde2c26a47e5db0dd1efc163405afadd9d
  specs:
    activeadmin (1.0.0.pre)
    ...

even if I have 2 active-admin gems, there is only one with revision: b7e8c7dde2c26a47e5db0dd1efc163405afadd9d

However, working with forks, this what I do:

I usually fork it, pull the froked gem on my computer, update the Gemfile of my app to use the gem from local-storage with path parameter, and I can update the gem without pushing it to github everytime I do a small change just to test it.

When I make it work as I needed, I push it to github and change the path in Gemfile of my app, run bundle again to update the path Gemfile.lock and I am all set. At least here you are not confused what gem the app is loading.