? drush-999480.patch
? parche.txt
? includes/table.inc
Index: commands/pm/pm.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/pm/pm.drush.inc,v
retrieving revision 1.172
diff -u -r1.172 pm.drush.inc
--- commands/pm/pm.drush.inc	15 Dec 2010 16:38:21 -0000	1.172
+++ commands/pm/pm.drush.inc	18 Dec 2010 13:38:15 -0000
@@ -2161,7 +2161,7 @@
 /**
  * Implementation of hook_drush_pm_download_destination_alter().
  *
- * Built-in download-destination-alter hook.  This particular version of
+ * Built-in download-destination-alter hook. This particular version of
  * the hook will move modules that contain only drush commands to
  * /usr/share/drush/commands if it exists, or $HOME/.drush if the
  * site-wide location does not exist.
@@ -2192,6 +2192,39 @@
 }
 
 /**
+ * Implementation of hook_drush_pm_post_download().
+ *
+ * Built-in post-download hook. This particular version of the hook is to
+ * implement the special case for --gitsubmodule when the specified
+ * package-handler is git_drupalorg.
+ */
+function pm_drush_pm_post_download(&$project, $release) {
+  if ((drush_get_option('package-handler') == 'git_drupalorg') && (drush_get_option('gitsubmodule', FALSE))) {
+    // Obtain the superproject path.
+    if (drush_shell_cd_and_exec(dirname($project['full_project_path']), 'git rev-parse --git-dir')) {
+      $output = drush_shell_exec_output();
+      if (isset($output[0])) {
+        $superproject = dirname($output[0]);
+      }
+      else {
+        return drush_set_error('DRUSH_PM_GIT_SUBMODULE_PROBLEMS', dt('Unable to create !project as a git submodule: !dir is not in a Git repository.', array('!project' => $project['name'], '!dir' => dirname($project['full_project_path']))));
+      }
+    }
+
+    // Add the downloaded project as a submodule of its git superproject.
+    $command = array();
+    $command[] = 'git submodule add';
+    $command[] = drush_get_option('gitsubmoduleaddparams');
+    $command[] = $project['repository'];
+    // We need the submodule relative path.
+    $command[] = substr($project['full_project_path'], strlen($superproject) + 1);
+    if (!drush_shell_cd_and_exec($superproject, implode(' ', $command))) {
+      return drush_set_error('DRUSH_PM_GIT_CHECKOUT_PROBLEMS', dt('Unable to add !name as a git submodule of !super.', array('!name' => $project['name'], '!super' => $superproject)));
+    }
+  }
+}
+
+/**
  * Update the locked status of all of the candidate projects
  * to be updated.
  *
Index: commands/pm/package_handler/cvs.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/pm/package_handler/cvs.inc,v
retrieving revision 1.23
diff -u -r1.23 cvs.inc
--- commands/pm/package_handler/cvs.inc	8 Dec 2010 08:07:42 -0000	1.23
+++ commands/pm/package_handler/cvs.inc	18 Dec 2010 13:38:15 -0000
@@ -31,7 +31,7 @@
  * @param $project The project array with name, base and full (final) paths.
  * @param $release The release details array from drupal.org
  */
-function package_handler_install_project($project, $release) {
+function package_handler_install_project(&$project, $release) {
   // Check it out.
   drush_pm_cvs($project, $release);
 
@@ -53,7 +53,7 @@
  * @param $project The project array with name, base and full (final) paths.
  * @param $release The release details array from drupal.org
  */
-function package_handler_update_project($project, $release) {
+function package_handler_update_project(&$project, $release) {
   drush_log('Updating project ' . $project['name'] . ' ...');
 
   // Check out a fresh copy, or update an existing one.
@@ -74,7 +74,7 @@
  * @param $project The project array with name, base and full (final) paths.
  * @param $release The release details array from drupal.org
  */
-function drush_pm_cvs($project, $release) {
+function drush_pm_cvs(&$project, $release) {
   // Build the cvs command to execute.
   $command = array('cvs');
 
Index: commands/pm/package_handler/git_drupalorg.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/pm/package_handler/git_drupalorg.inc,v
retrieving revision 1.7
diff -u -r1.7 git_drupalorg.inc
--- commands/pm/package_handler/git_drupalorg.inc	18 Dec 2010 11:27:56 -0000	1.7
+++ commands/pm/package_handler/git_drupalorg.inc	18 Dec 2010 13:38:15 -0000
@@ -28,87 +28,42 @@
 /**
  * Install a project.
  *
- * @param $project The project array with name, base and full (final) paths.
+ * @param $request The project array with name, base and full (final) paths.
  * @param $release The release details array from drupal.org
  */
-function package_handler_install_project($project, $release) {
-  drush_log(dt('Downloading project !name ...', array('!name' => $project['name'])));
+function package_handler_install_project(&$request, $release) {
+  drush_log(dt('Downloading project !name ...', array('!name' => $request['name'])));
 
   if (isset($release['version_extra']) && $release['version_extra'] == 'dev') {
     // Use the development repository, not supported yet.
-    $repository = 'git://git.drupal.org/project/' . $project['name'] . '.git';
+    $repository = 'git://git.drupal.org/project/' . $request['name'] . '.git';
     // Strip -dev off the end.
     $tag = substr($release['version'], 0, -4);
   }
   else {
     // Use a stable repository.
-    $repository = 'git://git.drupal.org/project-stable/' . $project['name'] . '.git';
+    $repository = 'git://git.drupal.org/project-stable/' . $request['name'] . '.git';
     $tag = $release['version'];
   }
+  $request['repository'] = $repository;
 
-  // Determine if we're going to init using submodules or not, as our logic
-  // branches as a result.
-  $submodule = drush_get_option('gitsubmodule', FALSE);
-  $function = 'package_handler_install_project_gitdo_' . ($submodule ? 'submodule' : 'normal');
-  return $function($project, $repository, $tag);
-}
-
-/**
- * Clone a repo and checkout the appropiate branch.
- */
-function package_handler_install_project_gitdo_normal($project, $repository, $tag) {
   // Clone the repo into its appropriate target location.
-  $command = 'git clone ' . drush_get_option('gitcloneparams') . ' ' . $repository . ' ' . $project['full_project_path'];
-  if (!drush_shell_exec($command)) {
-    return drush_set_error('DRUSH_PM_GIT_CHECKOUT_PROBLEMS', dt('Unable to clone project !name from git.drupal.org.', array('!name' => $project['name'])));
+  $command = array();
+  $command[] = 'git clone';
+  $command[] = drush_get_option('gitcloneparams');
+  $command[] = $repository;
+  $command[] = $request['full_project_path'];
+  if (!drush_shell_exec(implode(' ', $command))) {
+    return drush_set_error('DRUSH_PM_GIT_CHECKOUT_PROBLEMS', dt('Unable to clone project !name from git.drupal.org.', array('!name' => $request['name'])));
   }
 
   // Check out the appropriate branch.
-  $command = 'git checkout ' . drush_get_option('gitcheckoutparams') . ' ' . $tag;
-  if (!drush_shell_cd_and_exec($project['full_project_path'], $command)) {
-    return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to retrieve ' . $project['name'] . ' from git.drupal.org.');
-  }
-
-  return TRUE;
-}
-
-/**
- * Add a git submodule and checkout the appropiate branch.
- */
-function package_handler_install_project_gitdo_submodule($project, $repository, $tag) {
-  // Verify that we are in a Git repository.
-  if (drush_shell_cd_and_exec($project['base_project_path'], 'git rev-parse --git-dir')) {
-    $output = drush_shell_exec_output();
-    if (isset($output[0])) {
-      $git_dir = $output[0];
-    }
-  }
-  if (!isset($git_dir)) {
-    return drush_set_error('DRUSH_PM_GIT_CHECKOUT_PROBLEMS', dt('Unable to create !project as a git submodule: !dir is not in a Git repository.', array('!project' => $project['name'], '!dir' => $project['base_project_path'])));
-  }
-
-  // Resolve the project's path to its true location: git submodule doesn't
-  // like symbolic links.
-  // In case the path already exist we shouldn't remove it.
-  if (file_exists($project['full_project_path'])) {
-    $full_project_path = realpath($project['full_project_path']);
-  }
-  else {
-    drush_mkdir($project['full_project_path']);
-    $full_project_path = realpath($project['full_project_path']);
-    drush_delete_dir($full_project_path);
-  }
-
-  // Add the submodule; this clones it into place and registers it in the
-  // superproject.
-  $command = 'git submodule add ' . drush_get_option('gitsubmoduleaddparams') . ' ' . $repository . ' ' . $full_project_path;
-  if (!drush_shell_cd_and_exec(dirname($git_dir), $command)) {
-    return drush_set_error('DRUSH_PM_GIT_CHECKOUT_PROBLEMS', dt('Unable to add git submodule !name from git.drupal.org.', array('!name' => $project['name'])));
-  }
-
-  $command = 'git checkout ' . drush_get_option('gitcheckoutparams') . ' ' . $tag;
-  if (!drush_shell_cd_and_exec($project['full_project_path'], $command)) {
-    return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', dt('Unable to checkout !tag tag for project !name from git.drupal.org.', array('!tag' => $tag, '!name' => $project['name'])));
+  $command = array();
+  $command[] = 'git checkout';
+  $command[] = drush_get_option('gitcheckoutparams');
+  $command[] = $tag;
+  if (!drush_shell_cd_and_exec($request['full_project_path'], implode(' ', $command))) {
+    return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to retrieve ' . $request['name'] . ' from git.drupal.org.');
   }
 
   return TRUE;
@@ -117,25 +72,30 @@
 /**
  * Update a project (so far, only modules are supported).
  *
- * @param $project The project array with name, base and full (final) paths.
+ * @param $request The project array with name, base and full (final) paths.
  * @param $release The release details array from drupal.org
  */
-function package_handler_update_project($project, $release) {
-  drush_log('Updating project ' . $project['name'] . ' ...');
+function package_handler_update_project($request, $release) {
+  drush_log('Updating project ' . $request['name'] . ' ...');
 
   $commands = array();
   if ($release['version_extra'] == 'dev') {
     // Update the branch of the development repository.
-    $commands[] = 'git pull ' . drush_get_option('gitpullparams') . ' ';
+    $commands[] = 'git pull';
+    $commands[] = drush_get_option('gitpullparams');
   }
   else {
     // Use a stable repository.
-    $commands[] = 'git fetch ' . drush_get_option('gitfetchparams');
-    $commands[] = 'git checkout ' . drush_get_option('gitcheckoutparams') . ' ' . $release['version'];
+    $commands[] = 'git fetch';
+    $commands[] = drush_get_option('gitfetchparams');
+    $commands[] = ';';
+    $commands[] = 'git checkout';
+    $commands[] = drush_get_option('gitcheckoutparams');
+    $commands[] = $release['version'];
   }
 
-  if (!drush_shell_cd_and_exec($project['full_project_path'], implode(' ; ', $commands))) {
-    return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to update ' . $project['name'] . ' from git.drupal.org.');
+  if (!drush_shell_cd_and_exec($request['full_project_path'], implode(' ', $commands))) {
+    return drush_set_error('DRUSH_PM_UNABLE_CHECKOUT', 'Unable to update ' . $request['name'] . ' from git.drupal.org.');
   }
 
   return TRUE;
