简体   繁体   English

捆绑器何时更新宝石指向git repo的宝石?

[英]When do bundler update the gem incase of gems pointed to git repo?

I am trying to move the common functionality of 3 Rails application into a gem. 我试图将3 Rails应用程序的常用功能移动到gem中。 I have created the gem, tested it locally and is going to move to a private repository. 我创建了gem,在本地测试它,并将移动到私有存储库。

So, now I am concerned about how to deal with case if I have change in the code inside the gem. 所以,现在我担心如果我在gem中的代码有变化,如何处理大小写。 Do I need to change the version of the gem, if I want to update the gem while bundle update mygem , or will Bundler detect the change from the commit hash of the git repo while doing bundle update mygem ? 我是否需要更改gem的版本,如果我想在bundle update mygembundle update mygem ,或者Bundler会在执行bundle update mygem检测git repo的提交哈希值的变化?

Since your Gemfile will be referencing your gem in the private git repository, then in order for your application to pick up any new changes in your gem, you need to do bundle update gemname . 由于您的Gemfile将在私有git存储库中引用您的gem,因此为了让您的应用程序获取gem中的任何新更改,您需要执行bundle update gemname Pure and simple. 纯粹而简单。 If you do not do that, bundle will not pick up the changes. 如果您不这样做,bundle将不会接收更改。

Bundler uses the version of your gem that is locked inside your Gemfile.lock file in order to start/use it in your application. Bundler使用锁定在Gemfile.lock文件中的gem版本,以便在您的应用程序中启动/使用它。 The version info inside your Gemfile.lock is updated only if you do bundle update . 只有Gemfile.lock bundle update才会更新Gemfile.lock的版本信息。 Otherwise it is locked (aka Gemfile.lock ) and whatever version is locked is being used. 否则它被锁定 (也就是Gemfile.lock )并且正在使用任何被锁定的版本。

BTW, referencing a gem in a private git repository can have many options ( :branch , :tag etc) but this is irrelevant. BTW,引用私有git存储库中的gem可以有很多选项( :branch:tag等),但这是无关紧要的。 Lock is going to take place not matter what. 锁定将发生在什么地方。

I hope that this one explains how bundler works. 我希望这个解释捆绑器如何工作。

You do not need to change the version inside the gem every time you make a change to it. 每次对其进行更改时,都无需更改gem内的版本。 When using git gems, Gemfile.lock locks to a commit hash rather than the version number. 使用git gems时, Gemfile.lock锁定提交哈希而不是版本号。 You don't need to specify a version at all. 您根本不需要指定版本。

When you run bundle update mygem and mygem is a git gem, it will update the locked commit hash to the latest available on the branch you have specified (or on master if you have not specified a branch). 当你运行bundle update mygem并且mygem是一个git gem时,它会将锁定的提交哈希更新为你指定的分支上的最新可用(如果你没有指定分支,则更新为master )。

Good question, I think when you run bundle update my_gem the task check only your version installed vs. version on the gem's branch, without checking the hash of the master gem branch. 好问题,我认为当你运行bundle update my_gem ,任务只检查你安装的版本与gem分支上的版本,而不检查master gem分支的哈希值。

I think so, because all the time I have run the bundle update the "update process" for a gem runs only when a new version (greater than my local version) is detected. 我是这么认为的,因为我一直运行bundle update ,只有在检测到新版本(大于我的本地版本)时才会运行gem的“更新过程”。

Hereafter some references: 以下一些参考文献:

EDIT 编辑

I see that you can check the remote hash declaring explicitly in the Gemfile: 我看到你可以在Gemfile中检查显式声明的远程哈希:

# Specify that a git repository should use a particular ref, branch, or tag
:git => 'git://github.com/rails/rails.git', :ref => '4aded' 
:git => 'git://github.com/rails/rails.git', :branch => '2-3-stable' 
:git => 'git://github.com/rails/rails.git', :tag => 'v2.3.5'

But for "autochecking" if the gem version is a newer than your local, I think that the better way to do this is to specify a version. 但是对于“自动修复”,如果宝石版本比你的本地版本更新,我认为更好的方法是指定一个版本。

EDIT 2 编辑2

Maybe specifying a :branch of the git gem repo is the solution you are looking for. 也许指定一个:branch git gem repo的:branch是你正在寻找的解决方案。

:git => 'git://github.com/rails/rails.git', :branch => 'my_current_master_branch' 

I did not realize that since I own the gem, I could just update the gem and check it out for myself. 我没有意识到,因为我拥有宝石,我可以更新宝石并自己检查一下。 I just tried it out and here are my findings: 我刚试了一下,这是我的发现:

The gem updates only when we run bundle update gemname in case of any gems whether it is from a git repo or from rubygems.org. 只有当我们在任何宝石的情况下运行bundle update gemname时,gem才会bundle update gemname ,无论是来自git repo还是来自rubygems.org。 If there is no details of the gem given in the Gemfile.lock (or if the Gemfile.lock does not exist), it will get the latest of the gem and writes the details of the gem inside the Gemfile.lock. 如果没有Gemfile.lock给出的gem的详细信息(或者如果Gemfile.lock不存在),它将获取最新的gem并在Gemfile.lock中写入gem的详细信息。

For the case of gems from git repo, when we run bundle update gemname , it updates to the latest commit hash of the relevant branch of the gem (in my case, it was master), and it writes the commit hash to the Gemfile.lock . 对于来自git repo的gem的情况,当我们运行bundle update gemname ,它会更新到gem的相关分支的最新提交哈希(在我的例子中,它是master),并且它将提交哈希写入Gemfile.lock In my case, it looks something like this (Note the revision block): 在我的例子中,它看起来像这样(注意revision块):

GIT
  remote: git@myprivaterepo.com:mygem.git
  revision: 5311ed765d5724cd20dfbcb87aa66b6f6fcbee7d
  specs:
    mygem (0.0.1)

For the case of gems from rubygems when we run bundle update gemname , it updates if a new version is available and the Gemfile.lock looks like this: 对于我们运行bundle update gemname时来自rubygems的gem的情况,如果新版本可用并且Gemfile.lock看起来像这样,它会更新:

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (3.2.13)

So, to answer my own question, when I do bundle update mygem , for a gem from a git repo, it will get updated to the latest commit hash in the Git repo (even if the version of the gem is not changed). 所以,为了回答我自己的问题,当我对git repo中的gem进行bundle update mygem ,它会更新到Git bundle update mygem中的最新提交哈希值(即使gem的版本未更改)。 So, I do not need to change the version of the gem, I just need to push to the git repo and do bundle update mygem in the real project that uses mygem . 所以,我不需要更改gem的版本,我只需要推送到git repo并在使用mygem的真实项目中bundle update mygem mygem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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