Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gemfile: option causes git-hooks to fail if both Psych 4.x and 3.x are installed locally #759

Open
Drowze opened this issue Aug 6, 2021 · 0 comments

Comments

@Drowze
Copy link
Contributor

Drowze commented Aug 6, 2021

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
@Drowze Drowze changed the title git-hooks fail if both Psych 4.x and 3.x are installed locally gemfile: option causes git-hooks to fail if both Psych 4.x and 3.x are installed locally Aug 6, 2021
@Drowze Drowze changed the title gemfile: option causes git-hooks to fail if both Psych 4.x and 3.x are installed locally gemfile: option causes git-hooks to fail if both Psych 4.x and 3.x are installed locally Aug 6, 2021
@Drowze Drowze changed the title gemfile: option causes git-hooks to fail if both Psych 4.x and 3.x are installed locally gemfile: option causes git-hooks to fail if both Psych 4.x and 3.x are installed locally Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant