diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2018-11-05 22:52:18 -0800 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2018-11-05 22:52:18 -0800 |
commit | a0a599ad3bd74e5fe51906d5cb5fd4405258976c (patch) | |
tree | 6b5f880cd7b4c5e239cabdfd948e708719d4256e | |
parent | 8197732a3dd9df3071cf61ba4644ea826160fe05 (diff) | |
download | bundler-a0a599ad3bd74e5fe51906d5cb5fd4405258976c.tar.gz |
[Plugin::Index] Only register each plugin once for a given hook
-rw-r--r-- | lib/bundler/plugin/index.rb | 5 | ||||
-rw-r--r-- | spec/bundler/plugin/index_spec.rb | 6 |
2 files changed, 10 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..4969e0cd55 100644 --- a/spec/bundler/plugin/index_spec.rb +++ b/spec/bundler/plugin/index_spec.rb @@ -86,6 +86,12 @@ 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) + expect(index.hook_plugins("after-bar")).to eq([plugin_name]) + end + context "that are not registered", :focused do let(:file) { double("index-file") } |