diff options
author | Bundlerbot <bot@bundler.io> | 2018-11-16 10:37:20 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2018-11-16 10:37:20 +0000 |
commit | 05b552ccafb6fc6492e498edaeddd0979657c517 (patch) | |
tree | 93958bc4fe5663783d3625a8a8a2f3906b9bd6b1 | |
parent | 172ec59db53ec05a91c0d9eb72e2d715ae82f3c0 (diff) | |
parent | 19237b490b690b8f9cf922f2ac982ef684c23cee (diff) | |
download | bundler-05b552ccafb6fc6492e498edaeddd0979657c517.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>
-rw-r--r-- | lib/bundler/plugin/index.rb | 5 | ||||
-rw-r--r-- | spec/bundler/plugin/index_spec.rb | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 642e7c8163..faabf3a8d1 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") } |