Index: wp-includes/theme.php
--- wp-includes/theme.php
+++ wp-includes/theme.php
@@ -666,7 +666,7 @@
 	if ( is_array( $sidebars_widgets ) )
 		set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) );
 
-	$old_theme  = wp_get_theme();
+	$old_theme = wp_get_theme();
 	$new_theme = wp_get_theme( $stylesheet );
 
 	if ( func_num_args() > 1 ) {
@@ -679,9 +679,36 @@
 	update_option( 'template', $template );
 	update_option( 'stylesheet', $stylesheet );
 
-	if ( count( $wp_theme_directories ) > 1 ) {
-		update_option( 'template_root', get_raw_theme_root( $template, true ) );
-		update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
+	// Get current theme roots
+	$template_root   = get_option( 'template_root' );
+	$stylesheet_root = get_option( 'stylesheet_root' );
+
+	// Loop through themes and check for root mismatch. If we find a mismatch,
+	// only update the option if the root is not '/themes' to prevent adding
+	// useless options to the database.
+	foreach ( get_site_transient( 'theme_roots' ) as $theme => $root ) {
+
+		// Template
+		if ( ( $template == $theme ) && ( $root != $template_root ) ) {
+
+			// Don't set root to default location
+			if ( '/themes' == $root  ) {
+				delete_option( 'template_root' );
+			} else {
+				update_option( 'template_root', $root );
+			}
+		}
+
+		// Stylesheet
+		if ( ( $stylesheet == $theme ) && ( $root != $stylesheet_root ) ) {
+
+			// Don't set root to default location
+			if ( '/themes' == $root  ) {
+				delete_option( 'stylesheet_root' );
+			} else {
+				update_option( 'stylesheet_root', $root );
+			}
+		}
 	}
 
 	$new_name  = $new_theme->get('Name');
