diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 642e7c81638..faabf3a8d1b 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -58,7 +58,10 @@ def register_plugin(name, path, load_paths, commands, sources, hooks) 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 ca3476ea2aa..e18e960fb81 100644 --- a/spec/bundler/plugin/index_spec.rb +++ b/spec/bundler/plugin/index_spec.rb @@ -86,6 +86,17 @@ 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") }