commit 3d235ecab7ebea868004106940e9587ffdc3bc45
Author: Antoine Beaupre <anarcat@koumbit.org>
Date:   Tue Apr 13 01:12:36 2010 -0400

    #769264 - make a restricted mode that will not load site-specific modules

diff --git a/includes/command.inc b/includes/command.inc
index 84d6c56..9844058 100644
--- a/includes/command.inc
+++ b/includes/command.inc
@@ -468,7 +468,9 @@ function _drush_find_commandfiles($phase) {
     case DRUSH_BOOTSTRAP_DRUPAL_SITE:
       // Add all module paths, even disabled modules. Prefer speed over accuracy.
       $searchpath[] = 'sites/all/modules';
-      $searchpath[] = conf_path() . '/modules';
+      if (!drush_get_option(array('R', 'restricted'))) {
+        $searchpath[] = conf_path() . '/modules';
+      }
       // Too early for variable_get('install_profile', 'default'); Just use default.
       $searchpath[] = "profiles/default/modules";
       break;
@@ -476,8 +478,12 @@ function _drush_find_commandfiles($phase) {
       // Add enabled module paths. Since we are bootstrapped,
       // we can use the Drupal API.
       foreach (module_list() as $module) {
-        $filename = drupal_get_filename('module', $module);
-        $searchpath[] = dirname($filename);
+        $dirname = dirname(drupal_get_filename('module', $module));
+        // in restricted mode, add modules and themes only if they are
+        // our whitelist of directories (core themes and modules + sites/all)
+        if (!drush_get_option(array('R', 'restricted')) || preg_match("/^(themes|modules|sites\/all)/", $dirname)) {
+          $searchpath[] = $dirname;
+        }
       }
       break;
   }
diff --git a/includes/drush.inc b/includes/drush.inc
index f9af2e5..35a3161 100644
--- a/includes/drush.inc
+++ b/includes/drush.inc
@@ -349,6 +349,7 @@ function drush_get_option_help() {
   $options['-p, --pipe']               = dt("Emit a compact representation of the command for scripting.");
   $options['--nocolor']                = dt("Suppress color highlighting on log messages.");
   $options['-h, --help']               = dt("This help system.");
+  $options['-R, --restricted']         = dt("Do not load site-specific modules and drush extensions.");
   $options['--php']                    = dt("The absolute path to your PHP intepreter, if not 'php' in the path.");
   return $options;
 }
