? drush_pm
? drush_pm_cvs
? drush_pm_svn
? drush_pm_wget
? drush_simpletest
? drush_sql
? drush_tools
? drushrc.php
? drushrc.phpe
? example.drushrc.phpe
? services
? commands/alias
? commands/site
? commands/pm/handler
? includes/table.inc
Index: drush.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/drush.php,v
retrieving revision 1.75
diff -u -p -r1.75 drush.php
--- drush.php	27 Oct 2009 23:59:37 -0000	1.75
+++ drush.php	4 Nov 2009 18:59:03 -0000
@@ -64,12 +64,14 @@ function drush_verify_cli() {
  */
 function drush_main() {
   $phases = _drush_bootstrap_phases();
-
+  $completed_phases = array();
+  
   $return = '';
   $command_found = FALSE;
 
   foreach ($phases as $phase) {
     if (drush_bootstrap($phase)) {
+      $completed_phases[$phase] = TRUE;
       $command = drush_parse_command();
       
       // Process a remote command if 'remote-host' option is set.
@@ -79,7 +81,7 @@ function drush_main() {
       }
 
       if (is_array($command)) {
-        if ($command['bootstrap'] == $phase && empty($command['bootstrap_errors'])) {
+        if (array_key_exists($command['bootstrap'], $completed_phases) && empty($command['bootstrap_errors'])) {
           drush_log(dt("Found command: !command", array('!command' => $command['command'])), 'bootstrap');
           $command_found = TRUE;
           // Dispatch the command(s).
@@ -151,14 +153,11 @@ function drush_remote_command() {
     
     // After we clear out the flags we do not want from the
     // 'options' context, we will add in the 'root' and 'uri'
-    // options from any context.  Note that these will usually
-    // come from the 'alias' context, which has a higher precedence
-    // than the 'site' context (where 'r' and 'l' from settings.php
-    // are stored).
+    // options from the 'alias' context.
     foreach (array('root', 'r', 'uri', 'l') as $key) {
-      $value = drush_get_option($key);
+      $value = drush_get_option($key, null, 'alias');
       if (isset($value)) {
-        $data[$key] = drush_get_option($key);
+        $data[$key] = $value;
       }
     }
     
Index: commands/core/rsync.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/rsync.inc,v
retrieving revision 1.1
diff -u -p -r1.1 rsync.inc
--- commands/core/rsync.inc	27 Oct 2009 16:26:36 -0000	1.1
+++ commands/core/rsync.inc	4 Nov 2009 18:59:03 -0000
@@ -236,7 +236,7 @@ function _drush_core_evaluate_path($path
   else {
     // if the path is a site alias or a local site...
     $site_alias_settings = drush_sitealias_get_record($path);
-    if (!empty($site_alias_settings) || _drush_core_is_local_machine($path)) {
+    if (!empty($site_alias_settings) || drush_is_local_host($path)) {
       $alias = $path;
       $path = '';
     }
@@ -257,7 +257,7 @@ function _drush_core_evaluate_path($path
   else {
     // Strip the machine portion of the path if the
     // alias points to the local machine.
-    if (_drush_core_is_local_machine($machine)) {
+    if (drush_is_local_host($machine)) {
       $machine = '';
     }
     else {
@@ -315,25 +315,3 @@ function _drush_core_evaluate_path($path
   return "$machine$separator$path";
 }
 
-/**
- * Make a determination whether or not the given
- * name is local or not.
- *
- * @param site
- *   The name of a site folder (or maybe something else)
- * @return
- *   True if the name is local
- */
-function _drush_core_is_local_machine($site) {
-  // To do:  the directory in 'sites' might contain
-  // a component for the port or local path, so it
-  // would be better to do a 'contains' test on all
-  // files in 'sites' to determine if 'alias' is local.
-  // This might give a false positive, though: a remote
-  // 'mysite.com' would look local if there was a local
-  // 'dev.mysite.com'.  For now, use site aliases to
-  // refer to local sites that have port or path components
-  // in the site folder.
-  return ($site == 'localhost') || ($site == '127.0.0.1') || (file_exists(drush_get_context('DRUSH_DRUPAL_ROOT') . "/sites/$site"));
-}
-
Index: commands/core/sitealias.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/sitealias.drush.inc,v
retrieving revision 1.2
diff -u -p -r1.2 sitealias.drush.inc
--- commands/core/sitealias.drush.inc	27 Oct 2009 23:59:38 -0000	1.2
+++ commands/core/sitealias.drush.inc	4 Nov 2009 18:59:03 -0000
@@ -24,12 +24,13 @@ function sitealias_drush_command() {
       'site' => 'Site specification alias to print',
     ),
     'options' => array(
-      '--full' => 'Print the full alias record for each site',
-      '--long' => 'Print the long-form site specification for each site',
-      '--short' => 'Print only the site alias name (default)',
-      '--db' => 'Include the databases structure in the full alias record',
-      '--db-url' => 'Include the short-form db-url in the full alias record',
-      '--no-db' => 'Do not include the database record in the full alias record (default)',
+      '--full' => 'Print the full alias record for each site.',
+      '--long' => 'Print the long-form site specification for each site.',
+      '--short' => 'Print only the site alias name (default).',
+      '--with-db' => 'Include the databases structure in the full alias record.',
+      '--with-db-url' => 'Include the short-form db-url in the full alias record.',
+      '--no-db' => 'Do not include the database record in the full alias record (default).',
+      '--with-optional' => 'Include optional default items.',
     ),
     'aliases' => array('sa'),
     'examples' => array(
@@ -180,13 +181,19 @@ function drush_sitealias_get_site_specif
 function _drush_sitealias_print_record($site_alias) {
   $output_db = drush_get_option('with-db');
   $output_db_url = drush_get_option('with-db-url');
-
+  $output_optional_items = drush_get_option('with-optional');
+  
   // Get the alias record for the specified site alias.
   // If the user wants database information included in
   // the record, then try to fetch that info from the
   // remote site.
   $alias_record = drush_sitealias_get_record($site_alias, isset($output_db) | isset($output_db_url));
   
+  // Include the optional items, if requested
+  if ($output_optional_items) {
+    _drush_sitealias_add_transient_defaults($alias_record);
+  }
+  
   // If the user specified --with-db-url, then leave the
   // 'db-url' entry in the alias record (unless it is not
   // set, in which case we will leave the 'databases' record instead).
Index: includes/backend.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/backend.inc,v
retrieving revision 1.19
diff -u -p -r1.19 backend.inc
--- includes/backend.inc	28 Oct 2009 11:57:56 -0000	1.19
+++ includes/backend.inc	4 Nov 2009 18:59:03 -0000
@@ -334,6 +334,10 @@ function _drush_backend_invoke($cmd, $da
  *   A text string representing a fully escaped command.
  */
 function _drush_backend_generate_command($command, $args, &$data, $method = 'GET', $drush_path = null, $hostname = null, $username = null) {
+  if (drush_is_local_host($hostname)) {
+    $hostname = null;
+  }
+  
   $drush_path = !is_null($drush_path) ? $drush_path : (is_null($hostname) ? DRUSH_COMMAND : 'drush'); // Call own drush.php file on local machines, or 'drush' on remote machines.
   $data['root'] = ($data['root']) ? $data['root'] : drush_get_context('DRUSH_DRUPAL_ROOT');
   $data['uri'] = array_key_exists('uri', $data) ? $data['uri'] : drush_get_context('DRUSH_URI');
Index: includes/environment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/environment.inc,v
retrieving revision 1.50
diff -u -p -r1.50 environment.inc
--- includes/environment.inc	30 Oct 2009 21:12:21 -0000	1.50
+++ includes/environment.inc	4 Nov 2009 18:59:03 -0000
@@ -527,7 +527,7 @@ function _drush_bootstrap_drupal_site_va
   $uri = 'http://'. $current;
 
   $drush_uri = drush_bootstrap_value('drush_uri', drush_get_option(array('l', 'uri'), $uri));
-
+  
   // Fake the necessary HTTP headers that Drupal needs:
   if ($drush_uri) {
     $drupal_base_url = parse_url($drush_uri);
@@ -555,26 +555,24 @@ function _drush_bootstrap_drupal_site_va
   $_SERVER['REQUEST_METHOD']  = NULL;
   $_SERVER['SERVER_SOFTWARE'] = NULL;
   $_SERVER['HTTP_USER_AGENT'] = NULL;
-  
+
   $site = drush_bootstrap_value('site', $_SERVER['HTTP_HOST']);
- 
-  $conf_path = drush_bootstrap_value('conf_path', conf_path());
+  
+  $conf_path = drush_bootstrap_value('conf_path', conf_path(TRUE, TRUE));
   $conf_file = "./$conf_path/settings.php";
   if (!file_exists($conf_file)) {
     return drush_bootstrap_error('DRUPAL_SITE_SETTINGS_NOT_FOUND', dt("Could not find a Drupal settings.php file at !file.",
        array('!file' => $conf_file)));
   }
-
+ 
   return TRUE;
 }
 
 /**
- * Initialize a site on the Drupal root.
- *
- * We now set various contexts that we determined and confirmed to be valid.
- * Additionaly we load an optional drushrc.php file in the site directory.
+ * Called by _drush_bootstrap_drupal_site to do the main work
+ * of the drush drupal site bootstrap.
  */
-function _drush_bootstrap_drupal_site() {
+function _drush_bootstrap_do_drupal_site() {
   $drush_uri = drush_set_context('DRUSH_URI', drush_bootstrap_value('drush_uri')); 
   $site = drush_set_context('DRUSH_DRUPAL_SITE', drush_bootstrap_value('site'));
   $conf_path = drush_set_context('DRUSH_DRUPAL_SITE_ROOT', drush_bootstrap_value('conf_path'));
@@ -585,6 +583,53 @@ function _drush_bootstrap_drupal_site() 
   drush_log(dt("Initialized Drupal site !site at !site_root", array('!site' => $site, '!site_root' => $conf_path)));
   drush_load_config('site');
 }
+ 
+/**
+ * Initialize a site on the Drupal root.
+ *
+ * We now set various contexts that we determined and confirmed to be valid.
+ * Additionally we load an optional drushrc.php file in the site directory.
+ */
+function _drush_bootstrap_drupal_site() {
+  _drush_bootstrap_do_drupal_site();
+  _drush_bootstrap_redo_drupal_site();
+}
+
+/**
+ * Re-do the drupal site bootstrap (and possibly the
+ * drupal root bootstrap) if a site alias was processed
+ * after the site bootstrap phase completed.  This will
+ * happen when processing "drush sitealias command" for
+ * a site alias defined in a drushrc.php file in the
+ * default site's drush configuration directory.
+ */
+function _drush_bootstrap_redo_drupal_site() {
+  // If drush_load_config defined a site alias that did not
+  // exist before, then sitealias check arg might now match
+  // against one of those aliases.
+  if (drush_sitealias_check_arg() === TRUE) {
+    $remote_host = drush_get_option('remote-host');
+    if (!isset($remote_host)) {         
+      // Check to see if the drupal root changed.
+      // If it has, we will set remote-host to cause
+      // this command to be executed via the backend invoke
+      // process.
+      $sitealias_drupal_root = drush_get_option(array('r', 'root'));
+      if (($sitealias_drupal_root != null) && (DRUPAL_ROOT != $sitealias_drupal_root)) {
+	drush_set_option('remote-host', 'localhost');
+      }
+      else {
+        // If we set an alias, then we need to bootstrap the
+        // drupal site once again.  It is possible to re-bootstrap
+        // the site at this point because settings.php has not
+        // been included yet.
+        drush_log(dt("Re-bootstrap drupal site."));
+        _drush_bootstrap_drupal_site_validate();
+        _drush_bootstrap_do_drupal_site();
+      }
+    }
+  }
+}
 
 /**
  * Initialize and load the Drupal configuration files.
@@ -920,3 +965,19 @@ function drush_get_themes() {
   }
 }
 
+/**
+ * Make a determination whether or not the given
+ * host is local or not.
+ *
+ * @param host
+ *   A hostname, 'localhost' or '127.0.0.1'.
+ * @return
+ *   True if the host is local.
+ */
+function drush_is_local_host($host) {
+  // @TODO: Check DNS against local interface settings?
+  // (Maybe not portable, maybe too slow?)
+  // @TODO: Allow user to specify host names in a configuration
+  // option (e.g. $options['local-hosts'] = array('myhostname1.com', 'myhostname2.com'); )
+  return ($host == 'localhost') || ($host == '127.0.0.1') || (file_exists(drush_get_context('DRUSH_DRUPAL_ROOT') . "/sites/$host"));
+}
Index: includes/sitealias.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/sitealias.inc,v
retrieving revision 1.3
diff -u -p -r1.3 sitealias.inc
--- includes/sitealias.inc	28 Oct 2009 11:57:56 -0000	1.3
+++ includes/sitealias.inc	4 Nov 2009 18:59:03 -0000
@@ -16,9 +16,7 @@ function drush_sitealias_check_arg() {
   if (_drush_sitealias_set_context_by_name($args[0])) {
     array_shift($args);
     // We only need to expand the site specification
-    // once, then we are done.  (Should we set a flag indicating
-    // that we already did this?  Otherwise 'drush alias1 alias2 command'
-    // would behave strangely.)
+    // once, then we are done.
     drush_set_arguments($args);
     return TRUE;
   }
@@ -189,7 +187,12 @@ function _drush_sitealias_add_static_def
 function _drush_sitealias_add_transient_defaults(&$alias_record) {
   if (isset($alias_record['path-aliases'])) {
     if (!array_key_exists('!drush', $alias_record['path-aliases'])) {
-      $alias_record['path-aliases']['!drush'] = dirname(DRUSH_COMMAND);
+      if (array_key_exists('!drush-script', $alias_record['path-aliases'])) {
+        $alias_record['path-aliases']['!drush'] = dirname($alias_record['path-aliases']['!drush-script']);
+      }
+      else {
+        $alias_record['path-aliases']['!drush'] = dirname(DRUSH_COMMAND);
+      }
     }
   }
 }
