diff --git a/drush/Provision/Service/git.php b/drush/Provision/Service/git.php index ac66866..aaf310d 100644 --- a/drush/Provision/Service/git.php +++ b/drush/Provision/Service/git.php @@ -10,6 +10,7 @@ class Provision_Service_git extends Provision_Service { static function subscribe_platform($context) { $context->setProperty('repo_url'); + $context->setProperty('repo_path'); $context->setProperty('deploy_from_git'); $context->setProperty('git_ref'); } diff --git a/drush/provision_git.drush.inc b/drush/provision_git.drush.inc index 8803b23..303fe8f 100644 --- a/drush/provision_git.drush.inc +++ b/drush/provision_git.drush.inc @@ -273,7 +273,7 @@ function drush_provision_git_clone($git_url = '', $path = '', $git_ref = '') { break; case 'platform': default: - $path = d()->root; + $path = d()->repo_path; break; } } @@ -383,6 +383,19 @@ function drush_provision_git_post_provision_verify() { } /** + * Implements drush_hook_post_COMMAND() for provision-delete command. + * + * If repo path is different from root, delete it. + */ +function drush_provision_git_post_provision_delete() { + // If platform has a repo path that is not the root, it must be deleted as well. + if (d()->type =='platform' && d()->repo_path != d()->root) { + drush_log('Deleting repo path at ' . d()->repo_path, 'ok'); + _provision_recursive_delete(d()->repo_path); + } +} + +/** * Update the drush context with the git_url and current git_ref. */ function _provision_git_update_git_meta_data() { diff --git a/hosting_git.drush.inc b/hosting_git.drush.inc index 9b662eb..e552e15 100644 --- a/hosting_git.drush.inc +++ b/hosting_git.drush.inc @@ -60,6 +60,7 @@ function hosting_git_hosting_platform_context_options(&$task) { // If we're actually provisioning from Git, populate real data. if (!empty($task->ref->git['repo_url'])) { $task->context_options['repo_url'] = $task->ref->git['repo_url']; + $task->context_options['repo_path'] = $task->ref->git['repo_path']; $task->context_options['deploy_from_git'] = TRUE; $task->context_options['git_ref'] = $task->ref->git['git_ref']; } @@ -79,6 +80,7 @@ function hosting_git_drush_context_import($context, &$node) { if (in_array($context->type, array('site', 'platform')) && $context->deploy_from_git) { $node->git['repo_url'] = $context->repo_url; $node->git['git_ref'] = $context->git_ref; + $node->git['repo_path'] = $context->repo_path; } } @@ -96,4 +98,8 @@ function hosting_git_post_hosting_verify_task($task, $data) { if (isset($context['git_ref'])) { $node->git['git_ref'] = $context['git_ref']; } + + if (isset($context['repo_path'])) { + $node->git['repo_path'] = $context['repo_path']; + } } diff --git a/hosting_git.install b/hosting_git.install index e5bad27..116ce4d 100644 --- a/hosting_git.install +++ b/hosting_git.install @@ -26,6 +26,20 @@ function hosting_git_schema() { 'not null' => TRUE, 'default' => '', ), + 'repo_path' => array( + 'description' => 'The absolute path to clone the repository to.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + 'default' => '', + ), + 'repo_docroot' => array( + 'description' => 'The (relative) path within a git repository where sites will be hosted.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + 'default' => '', + ), 'git_ref' => array( 'description' => 'The current git branch or tag.', 'type' => 'varchar', @@ -39,3 +53,23 @@ function hosting_git_schema() { return $schema; } + +/** + * Add repo_path and repo_docroot fields. + */ +function hosting_git_update_7301 () { + db_add_field('hosting_git', 'repo_path', array( + 'description' => 'The absolute path to clone the repository to.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + 'default' => '', + )); + db_add_field('hosting_git', 'repo_docroot', array( + 'description' => 'The (relative) path within a git repository where sites will be hosted.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + 'default' => '', + )); +} diff --git a/hosting_git.module b/hosting_git.module index 665d6d0..33d245a 100644 --- a/hosting_git.module +++ b/hosting_git.module @@ -79,6 +79,14 @@ function hosting_git_form_alter(&$form, &$form_state, $form_id) { '#default_value' => isset($node->git['repo_url']) ? $node->git['repo_url'] : '', ); + $form['git']['repo_docroot'] = array( + '#type' => 'textfield', + '#title' => 'Repository docroot', + '#description' => t('If Drupal is not in the root of your repository, enter the relative path within the repository that points to the correct subfolder.'), + '#default_value' => isset($node->git['repo_docroot']) ? $node->git['repo_docroot'] : '', + '#access' => $node_type == 'platform', + ); + $form['git']['git_ref'] = array( '#type' => 'textfield', '#title' => 'Branch or tag name', @@ -93,12 +101,28 @@ function hosting_git_form_alter(&$form, &$form_state, $form_id) { '#title' => t('Repo URL'), '#markup' => $node->git['repo_url'], ); + $form['git']['repo_path_display'] = array( + '#type' => 'item', + '#title' => t('Repo Path'), + '#markup' => $node->git['repo_path'], + ); $form['git']['git_ref_display'] = array( '#type' => 'item', '#title' => 'Branch or tag name', '#markup' => isset($node->git['git_ref']) ? $node->git['git_ref'] : 'master', '#description' => 'Use a checkout task to change this value.', ); + + // Don't lose values + $form['git']['repo_url'] = array( + '#type' => 'value', + '#default_value' => isset($node->git['repo_url']) ? $node->git['repo_url'] : '', + ); + // Don't lose values + $form['git']['repo_path'] = array( + '#type' => 'value', + '#default_value' => isset($node->git['repo_path']) ? $node->git['repo_path'] : '', + ); } // Default collapse one fieldset based on the current node. @@ -121,6 +145,16 @@ function hosting_git_node_form_validate($form, &$form_state) { } /** + * Implements hook_node_submit(). + */ +function hosting_git_node_submit($node, $form, &$form_state) { + if (!empty($form_state['values']['git']['repo_docroot'])) { + $form_state['values']['git']['repo_path'] = $node->git['repo_path'] = $node->publish_path; + $form_state['values']['publish_path'] = $node->publish_path = $node->git['repo_path'] . '/' . $node->git['repo_docroot']; + } +} + +/** * Implements hook_node_insert(). */ function hosting_git_node_insert($node) { @@ -132,7 +166,7 @@ function hosting_git_node_insert($node) { */ function hosting_git_node_update($node) { if ($node->type == 'platform' || $node->type == 'site') { - if (empty($node->git['repo_url']) || empty($node->git['git_ref'])) { + if (empty($node->git['repo_url']) || empty($node->git['git_ref'] || empty($node->git['git_docroot']))) { _hosting_git_node_load_defaults($node); } @@ -140,6 +174,8 @@ function hosting_git_node_update($node) { ->key(array('nid' => $node->nid)) ->fields(array( 'repo_url' => $node->git['repo_url'], + 'repo_path' => $node->git['repo_path'], + 'repo_docroot' => $node->git['repo_docroot'], 'git_ref' => $node->git['git_ref'], )) ->execute(); @@ -161,6 +197,13 @@ function hosting_git_node_load($nodes, $types) { $node->git['repo_url'] = $result->repo_url; $node->git['git_ref'] = $result->git_ref; + $node->git['repo_path'] = $result->repo_path; + $node->git['repo_docroot'] = $result->repo_docroot; + + // If platform repo path is empty, then load the publish_path in it's place. + if ( $node->type == 'platform' && empty($node->git['repo_path'])) { + $node->git['repo_path'] = $node->publish_path; + } } else { _hosting_git_node_load_defaults($node); @@ -181,6 +224,14 @@ function _hosting_git_node_load_defaults(&$node) { $node->git['repo_url'] = ''; } + if (!isset($node->git['repo_path'])) { + $node->git['repo_path'] = ''; + } + + if (!isset($node->git['repo_docroot'])) { + $node->git['repo_docroot'] = ''; + } + if (!isset($node->git['git_ref'])) { $node->git['git_ref'] = 'master'; } @@ -209,6 +260,21 @@ function hosting_git_node_view($node) { '#weight' => 100, '#markup' => check_plain($node->git['repo_url']), ); + $node->content['info']['repo_path'] = array( + '#type' => 'item', + '#title' => t('Git repository path'), + '#weight' => 100, + '#markup' => check_plain($node->git['repo_path']), + ); + if (!empty($node->git['repo_docroot'])) { + $node->content['info']['repo_docroot'] = array( + '#type' => 'item', + '#title' => t('Repository docroot'), + '#weight' => 100, + '#markup' => check_plain($node->git['repo_docroot']), + ); + } + $ref = $node->git['git_ref'] ? $node->git['git_ref'] : t('Pending Verification'); $node->content['info']['git_ref'] = array( '#type' => 'item',