@@ -39,8 +39,9 @@ def install(names, options)
3939 raise InvalidOption , "You cannot specify `--branch` and `--ref` at the same time." if options [ "branch" ] && options [ "ref" ]
4040
4141 specs = Installer . new . install ( names , options )
42+ plugins = plugins_to_save ( names , specs )
4243
43- save_plugins names , specs
44+ save_plugins ( plugins , specs )
4445 rescue PluginError
4546 specs_to_delete = specs . select { |k , _v | names . include? ( k ) && !index . commands . values . include? ( k ) }
4647 specs_to_delete . each_value { |spec | Bundler . rm_rf ( spec . full_gem_path ) }
@@ -112,10 +113,10 @@ def gemfile_install(gemfile = nil, &inline)
112113
113114 return if definition . dependencies . empty?
114115
115- plugins = definition . dependencies . map ( &:name ) . reject { |p | index . installed? p }
116116 installed_specs = Installer . new . install_definition ( definition )
117+ plugins = plugins_to_save ( definition . dependencies . map ( &:name ) , installed_specs )
117118
118- save_plugins plugins , installed_specs , builder . inferred_plugins
119+ save_plugins ( plugins , installed_specs , builder . inferred_plugins )
119120 end
120121 rescue RuntimeError => e
121122 unless e . is_a? ( GemfileError )
@@ -141,6 +142,15 @@ def root
141142 end
142143 end
143144
145+ # Return array of plugins that we need save or update the path
146+ # based if was not installed with that version yet
147+ def plugins_to_save ( plugins , installed_specs )
148+ plugins . reject do |p |
149+ installed_spec = installed_specs [ p ]
150+ installed_spec . nil? || index . version_already_installed? ( p , installed_spec . version )
151+ end
152+ end
153+
144154 def local_root
145155 Bundler . app_config_path . join ( "plugin" )
146156 end
@@ -247,7 +257,7 @@ def installed?(plugin)
247257 # @param [Array<String>] names of inferred source plugins that can be ignored
248258 def save_plugins ( plugins , specs , optional_plugins = [ ] )
249259 plugins . each do |name |
250- next if index . installed ?( name )
260+ next if index . version_already_installed ?( name , specs [ name ] . version )
251261
252262 spec = specs [ name ]
253263
0 commit comments