简体   繁体   中英

Local override for {gem} at /path/to/local/git/repo is using branch develop but Gemfile specifies develop

I'm running bundler v1.3.0.pre.2 and trying to get bundler to bundle a local git repository holding a gem, into a rails app.

Gemfile :

gem 'mygem', :github => 'myrepo/mygem', :branch => 'develop'

Config :

bundle config local.mygem /path/to/local/git/repo

Bundle install throws the error :

Local override for mygem at /path/to/local/git/repo is using branch develop but Gemfile specifies develop

Is this a bug ? I see that the branch names are exactly the same. What could be wrong ? Got the same error for Bundler v1.2.3 as well

You can use a local gem and even the branch you are working on like this

gem 'rspec-rails', path: '~/forks/rspec-rails', branch: 'feature-branch'

Just change github to path , Then

bundle install

Also as far as bundler config goes, although it is in the docs, I have never needed to change the local config like you did above.

With this method I have never needed to remove Gemfile.lock , it just picks up the changes to your local repo.

Although I don't recommend it, you could disable the branch checking feature used by bundler to make sure you are using the correct branch when developing

bundle config disable_local_branch_check true

If you just need to point to a branch within a local repository you're using like a gem, in gemfile:

gem 'gem-name', :path=> 'relative/path/to/directory'

Then create bundler configuration for that "gem" before bundle -ing

(Keep in mind the repository name may be different than the gem's name, although this is not the norm).

bundle config local.repository-name relative/path/to/directory


Magically, whatever branch is currently checked out locally will be active when you start a local server. You'll likely need to restart your server if you need to make changes or change branches (unless you have some type of automatic reloading feature).

One gotcha is when a configuration setting is already established (let's say via the mechanism above), and you need to use/reference a remote git gem - you don't need bundler configuration to use a remote git gem (if you have an active configuration, you'll get the local override error).

Check to make sure you don't have local settings for given gem:

bundle config local.gem-name

If you do, remove configuration for that gem:

bundle config --delete local.gem-name

Then point to remote repo and branch, in gemfile:

gem 'gem-name', :path => 'https://github.com/reponame.git', :branch => 'branch_name'

More information:

Git Gems: http://bundler.io/v1.7/git.html

"bundle config": http://bundler.io/v1.7/man/bundle-config.1.html

The branch you reference in your Gemfile needs to be the same as you have checked out in the local repository. Note that after you commit in the local repository you will need to run bundle install on your main application so that it rebuilds the Gemfile.lock to include the new revision hash and commit it. I recommend using the gem below as it automates this process for you and also aids in other scenarios. See the gem page for exact detail.

https://github.com/EPI-USE-Labs/git-bundle

Full detail of what happens:

When you use a git repository in your gemfile you can use bundle local overrides for development which will store revision hashes in your Gemfile.lock. On production these exact revision hashes will be checked out when it runs bundle install.

Gemfile: gem 'example', git: 'https://github.com/your_name/example.git', branch: :master

Bundle config shell command: bundle config local.example /path/to/local/git/repository

Gemfile.lock (auto generated): GIT remote: https://github.com/your_name/example.git revision: b9270e61abb89e1ff77fb8cfacb463e4d04388ad branch: master

GitHub问题表明,解决方法可能是删除Gemfile.lock并再次执行bundle install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM