最近我创建了一个不带git仓库的新的Rails 5应用程序。自动生成的Gemfile包含一个我以前从未见过的新块:
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
它的意思是什么?每个新应用都必须使用它吗?
最近我创建了一个不带git仓库的新的Rails 5应用程序。自动生成的Gemfile包含一个我以前从未见过的新块:
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
它的意思是什么?每个新应用都必须使用它吗?
git_source
添加了一个源,你可以使用它来从git存储库下载gem,而不是从rubygems.org
下载软件包。git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
会使您在声明时这样做:
gem 'foo_bar', :github => 'foo/bar'
https://github.com/foo/bar.git
下载gem包。
由于修复这个问题将是一个破坏性的改变,因为它会使现有的Gemfile.lock失效,所以在Bundler 2.x中修复了该问题。此时应该安全地删除这个解决方法。
Bundler :github 指令将从git://github.com/#{repo_name}.git
(源代码) 获取资源,该资源使用不安全的http
协议。
这个问题将在未来的Bundler版本中修复,但是可以在Gemfile文件的顶部添加以下代码片段来确保在Bundler 1中使用https
。
如果您不想将此代码添加到您的gemfile但仍然希望安全地从github访问gem,则可以使用以下方法:
gem 'foo_bar', git: 'https://github.com/foo/bar.git
bundle config github.https true
。 - Stefan