`gemfile:` option causes git-hooks to fail if both Psych 4.x and 3.x are installed locally
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
The failure is in the git hook script that calls Bundler.setup after loading .overcommit.yml, so start with the hook template Overcommit installs and how it sets BUNDLE_GEMFILE. Reproduce by pinning psych 3.x in a Gemfile while psych 4.x is also installed, then run the hook. Done would mean the hook loads the Gemfile's psych without the already-activated conflict; the issue has no comments or linked fix, so the approach is open and needs maintainer input.
由索引模型根据 Issue 内容生成。
描述
I'm not sure whether should I create this issue here or on the rubygems repository (to the Bundler maintainers). Let me know what you think.
A have overcommit installed with gemfile: Gemfile option on .overcommit.yml and most (all?) of my git-hooks have this script (this was removed from .git/hooks/post-checkout):
# Check if Overcommit should invoke a Bundler context for loading gems
require 'yaml'
# rubocop:disable Style/RescueModifier
if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
begin
Bundler.setup
rescue Bundler::BundlerError => e
puts "Problem loading '#{gemfile}': #{e.message}"
puts "Try running:\nbundle install --gemfile=#{gemfile}" if e.is_a?(Bundler::GemNotFound)
exit 78 # EX_CONFIG
end
end
# rubocop:enable Style/RescueModifier
However, on my system when I execute that, it fails on Bundler.setup. See:
$ cat Gemfile
source 'https://rubygems.org'
gem 'psych', '~> 3.0'
$ bundle install
Using bundler 2.2.25
Using psych 3.3.2
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
$ gem list | grep 'yaml\|bundler\|psych'
bundler (default: 2.2.25, 2.2.16)
bundler-audit (0.8.0, 0.7.0.1)
pronto-bundler_audit (0.7.0, 0.6.0)
psych (4.0.1, 3.3.2, 3.3.1, default: 3.1.0)
yaml (0.1.1, default: 0.1.0)
$ irb
[1] pry(main)> require 'yaml'
=> true
[2] pry(main)> require 'bundler'
=> true
[3] pry(main)> Bundler.setup
Gem::LoadError: You have already activated psych 4.0.1, but your Gemfile requires psych 3.3.2. Prepending `bundle exec` to your command may solve this.
from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:309:in `check_for_activated_spec!'
On a real repository with Overcommit setup:
$ git checkout .
Updated 0 paths from the index
Traceback (most recent call last):
7: from .git/hooks/post-checkout:37:in `<main>'
6: from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/bundler.rb:149:in `setup'
5: from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:24:in `setup'
4: from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:24:in `map'
3: from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/bundler/spec_set.rb:136:in `each'
2: from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/bundler/spec_set.rb:136:in `each'
1: from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:25:in `block in setup'
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:309:in `check_for_activated_spec!': You have already activated psych 4.0.1, but your Gemfile requires psych 3.3.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
I am not sure what would be the solution here. Is it possible to execute the git-hooks on a bundle exec context? Is it worth it? (as I imagine there would be performance penalty). 🤔
As a temporary solution (far from ideal), I suppressed the errors by simply uninstall Psych 4.x and YAML 0.1.1, but that's far from the ideal solution I believe.
$ gem uninstall psych:4.0.1
Successfully uninstalled psych-4.0.1
$ git checkout .
Updated 0 paths from the index
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/yaml.rb:12: warning: already initialized constant YAML
/Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/yaml-0.1.1/lib/yaml.rb:12: warning: previous definition of YAML was here
$ gem uninstall yaml:0.1.1
Successfully uninstalled yaml-0.1.1
$ git checkout .
Updated 0 paths from the index
- 主要语言
- Ruby
- 星标
- 4k
- 派生
- 288
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 18
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sds/overcommit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
sds/overcommit#909 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 78/100
sds/overcommit#847 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 半天 新手友好度 62/100
sds/overcommit#908 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 35/100
sds/overcommit#875 ·
维护者通常 1 天内回复
-
help wanted
难度 4/5 3-5 天 新手友好度 18/100
sds/overcommit#869 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
seek4science/seek#2784 ·
维护者通常 2 天内回复
-
Translation tutorial: snippet crashes on chunks export and misses simple { t } entries可能已有人在做 @Mahdi-Hasan 今天认领。 未关闭resource-documentation
难度 2/5 1-3 小时 新手友好度 76/100
TarteelAI/quranic-universal-library#1020 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
Records without the CRI logtag raise NoMethodError and are joined into the next record可能已有人在做 @nazarli-shabnam 今天认领。 未关闭bug help wanted
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 82/100
swombat/souls-house#842 ·
维护者通常 1 天内回复