From 2b0f16757ac855c1fc603adb1cc8577cf15be3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sun, 25 Oct 2015 18:31:50 +0100 Subject: [PATCH] Only rehash if `bundle install` actually created new executables This avoids running `rbenv rehash` after installing libraries that don't have executables, or after a no-op `bundle install` that didn't install anything. --- rbenv.d/exec/gem-rehash/rubygems_plugin.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb index 8d1df09..0f718b1 100644 --- a/rbenv.d/exec/gem-rehash/rubygems_plugin.rb +++ b/rbenv.d/exec/gem-rehash/rubygems_plugin.rb @@ -15,14 +15,20 @@ if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) class << self alias install_without_rbenv_rehash install def install(root, definition, options = {}) - result = install_without_rbenv_rehash(root, definition, options) begin - if result && Gem.default_path.include?(Bundler.bundle_path.to_s) - `rbenv rehash` + if Gem.default_path.include?(Bundler.bundle_path.to_s) + bin_dir = Gem.bindir(Bundler.bundle_path.to_s) + bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2 end rescue warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})" end + + result = install_without_rbenv_rehash(root, definition, options) + + if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before + `rbenv rehash` + end result end end