@@ -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 ) }
@@ -113,10 +114,10 @@ def gemfile_install(gemfile = nil, &inline)
113114
114115 return if definition . dependencies . empty?
115116
116- plugins = definition . dependencies . map ( &:name ) . reject { |p | index . installed? p }
117117 installed_specs = Installer . new . install_definition ( definition )
118+ plugins = plugins_to_save ( definition . dependencies . map ( &:name ) , installed_specs )
118119
119- save_plugins plugins , installed_specs , builder . inferred_plugins
120+ save_plugins ( plugins , installed_specs , builder . inferred_plugins )
120121 end
121122 rescue RuntimeError => e
122123 unless e . is_a? ( GemfileError )
@@ -142,6 +143,15 @@ def root
142143 end
143144 end
144145
146+ # Return array of plugins that we need save or update the path
147+ # based if was not installed with that version yet
148+ def plugins_to_save ( plugins , installed_specs )
149+ plugins . reject do |p |
150+ installed_spec = installed_specs [ p ]
151+ installed_spec . nil? || index . version_already_installed? ( p , installed_spec . version )
152+ end
153+ end
154+
145155 def local_root
146156 Bundler . app_config_path . join ( "plugin" )
147157 end
@@ -253,7 +263,7 @@ def loaded?(plugin)
253263 # @param [Array<String>] names of inferred source plugins that can be ignored
254264 def save_plugins ( plugins , specs , optional_plugins = [ ] )
255265 plugins . each do |name |
256- next if index . installed ?( name )
266+ next if index . version_already_installed ?( name , specs [ name ] . version )
257267
258268 spec = specs [ name ]
259269
0 commit comments