summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2018-11-16 10:37:20 +0000
committerColby Swandale <me@colby.fyi>2019-03-24 02:11:58 +1100
commit1d2853fb93068ad6dd9b5bc1776c19cb46af7f72 (patch)
treee935be2e8930fd8fbb23a887ae847750945be884
parent8f2548bbb50e1efa2f622727665e2038a1856cb3 (diff)
downloadbundler-1d2853fb93068ad6dd9b5bc1776c19cb46af7f72.tar.gz
Merge #6775
6775: [Plugin::Index] Only register each plugin once for a given hook r=colby-swandale a=segiddins ### What was the end-user problem that led to this PR? The problem was running `plugin install` twice for a plugin withs hooks would cause that hook to be registered twice. Closes #6771. ### What was your diagnosis of the problem? My diagnosis was a plugin's hooks should only be run once per event. ### What is your fix for the problem, implemented in this PR? My fix is to `uniq` the list of plugins registered for each event. Co-authored-by: Samuel Giddins <segiddins@segiddins.me> Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com> Co-authored-by: Colby Swandale <me@colby.fyi> (cherry picked from commit 05b552ccafb6fc6492e498edaeddd0979657c517)
-rw-r--r--lib/bundler/plugin/index.rb5
-rw-r--r--spec/bundler/plugin/index_spec.rb11
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb
index f09587dfda..cac3b81d51 100644
--- a/lib/bundler/plugin/index.rb
+++ b/lib/bundler/plugin/index.rb
@@ -58,7 +58,10 @@ module Bundler
raise SourceConflict.new(name, common) unless common.empty?
sources.each {|k| @sources[k] = name }
- hooks.each {|e| (@hooks[e] ||= []) << name }
+ hooks.each do |event|
+ event_hooks = (@hooks[event] ||= []) << name
+ event_hooks.uniq!
+ end
@plugin_paths[name] = path
@load_paths[name] = load_paths
diff --git a/spec/bundler/plugin/index_spec.rb b/spec/bundler/plugin/index_spec.rb
index ca3476ea2a..e18e960fb8 100644
--- a/spec/bundler/plugin/index_spec.rb
+++ b/spec/bundler/plugin/index_spec.rb
@@ -86,6 +86,17 @@ RSpec.describe Bundler::Plugin::Index do
expect(new_index.hook_plugins("after-bar")).to eq([plugin_name])
end
+ it "only registers a gem once for an event" do
+ path = lib_path(plugin_name)
+ index.register_plugin(plugin_name,
+ path.to_s,
+ [path.join("lib").to_s],
+ commands,
+ sources,
+ hooks + hooks)
+ expect(index.hook_plugins("after-bar")).to eq([plugin_name])
+ end
+
context "that are not registered", :focused do
let(:file) { double("index-file") }