= DRUSH_BOOTSTRAP_DRUPAL_FULL) { if (!module_exists('git_deploy')) { drush_log(dt('git package handler needs git_deploy module enabled to work properly.'), 'warning'); } } } /** * Download a project. * * @param $request The project array with name, base and full (final) paths. * @param $release The release details array from drupal.org */ function package_handler_download_project(&$request, $release) { if (isset($release['version_extra']) && $release['version_extra'] == 'dev') { // Use the development repository, not supported yet. $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/' . $request['name'] . '.git'; $tag = $release['version']; } $request['repository'] = $repository; // Clone the repo into its appropriate target location. $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 = 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; } /** * Update a project (so far, only modules are supported). * * @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($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'; $commands[] = drush_get_option('gitpullparams'); } else { // Use a stable repository. $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($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; } /** * Post download action. * * This action take place once the project is placed in its final location. * * Here we add the project as a git submodule. */ function package_handler_post_download($project) { if (drush_get_option('gitsubmodule', FALSE)) { // Obtain the superproject path, then add as submodule. if (drush_shell_cd_and_exec(dirname($project['full_project_path']), 'git rev-parse --show-toplevel')) { $output = drush_shell_exec_output(); $superproject = $output[0]; // 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))); } } 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'])))); } } }