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..3dd6353 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; } } diff --git a/hosting_git.drush.inc b/hosting_git.drush.inc index 9b662eb..e38642a 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']; } diff --git a/hosting_git.install b/hosting_git.install index e5bad27..1b46cc9 100644 --- a/hosting_git.install +++ b/hosting_git.install @@ -26,6 +26,13 @@ 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' => '', + ), 'git_ref' => array( 'description' => 'The current git branch or tag.', 'type' => 'varchar', @@ -39,3 +46,16 @@ function hosting_git_schema() { return $schema; } + +/** + * Add repo_platform_path field. + */ +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' => '', + )); +} diff --git a/hosting_git.module b/hosting_git.module index 665d6d0..79a1356 100644 --- a/hosting_git.module +++ b/hosting_git.module @@ -78,6 +78,16 @@ function hosting_git_form_alter(&$form, &$form_state, $form_id) { '#description' => t('The full URL that you would pass to git clone. Example: git@github.com:username/project.git or https://github.com/username/project.git. Note that this repository must be accessible by the Aegir user.'), '#default_value' => isset($node->git['repo_url']) ? $node->git['repo_url'] : '', ); + $form['git']['repo_path'] = array( + '#type' => 'textfield', + '#title' => 'Repository path', + '#description' => t('Defaults to the Publish Path if left blank. If Drupal is not in the root of your repository, enter the absolute path to clone the repository to, and edit the Publish Path to point to the correct subfolder. For example, if your Drupal code is in docroot, set Repository path to /var/aegir/platforms/NAME and Publish path to /var/aegir/platforms/NAME/docroot'), + '#default_value' => isset($node->git['repo_path']) ? $node->git['repo_path'] : '', + '#element_validate' => array( + 'hosting_git_repo_path_validate' + ), + '#access' => $node_type == 'platform', + ); $form['git']['git_ref'] = array( '#type' => 'textfield', @@ -93,6 +103,11 @@ 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', @@ -112,6 +127,36 @@ function hosting_git_form_alter(&$form, &$form_state, $form_id) { } /** + * Form element validator for the Repo Path. Checks that the repo path contains the platform path. + * + * @param $element + * @param $form_state + * @param $form + */ +function hosting_git_repo_path_validate($element, &$form_state, $form) { + + // Don't do anything unless we have a repo URL. + if (empty($form_state['values']['git']['repo_url'])) { + return; + } + + // If repo path is empty, set value to publish path. + if (empty($element['#value'])) { + form_set_value($element, $form_state['values']['publish_path'], $form_state); + } + else { + // Get the full publish path. This is how hosting_platform_form_validate() does it. + $publish_path = variable_get('hosting_platform_base_path', '/var/aegir/platforms/') . $form_state['values']['publish_path']; + $repo_path = $form_state['values']['git']['repo_path']; + + // Check that the repo_path contains the publish path. + if (strpos($repo_path, $publish_path) !== 0) { + form_error($element, t('The Repository Path must contain the Publish Path. Edit the Publish Path or Repository Path and try again.')); + } + } +} + +/** * Validation callback for platform node form. */ function hosting_git_node_form_validate($form, &$form_state) { @@ -140,6 +185,7 @@ 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'], 'git_ref' => $node->git['git_ref'], )) ->execute(); @@ -160,6 +206,7 @@ function hosting_git_node_load($nodes, $types) { } $node->git['repo_url'] = $result->repo_url; + $node->git['repo_path'] = $result->repo_path; $node->git['git_ref'] = $result->git_ref; } else { @@ -181,6 +228,10 @@ 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['git_ref'])) { $node->git['git_ref'] = 'master'; } @@ -209,6 +260,16 @@ function hosting_git_node_view($node) { '#weight' => 100, '#markup' => check_plain($node->git['repo_url']), ); + + // If repo path is different than publish path, show it. + if ($node->git['repo_path'] != $node->publish_path) { + $node->content['info']['repo_path'] = array( + '#type' => 'item', + '#title' => t('Git Repository Path'), + '#weight' => 100, + '#markup' => check_plain($node->git['repo_path']), + ); + } $ref = $node->git['git_ref'] ? $node->git['git_ref'] : t('Pending Verification'); $node->content['info']['git_ref'] = array( '#type' => 'item',