Commit 4b28bcca authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-631] Working clone and pull with Run operation

parent 74faafd7
......@@ -127,7 +127,7 @@ function git_include_admin_settings_form() {
*/
function git_include($name) {
if (!$repo = git_include_load($name)) {
throw new Exception(t('Git include repository not found: @name', array('@name' => $name)));
throw new Exception(t('Repository info not found: @name', array('@name' => $name)));
}
$dir = variable_get('git_include_dir', 'public://git_include');
......@@ -137,8 +137,19 @@ function git_include($name) {
throw new Exception(t('Error resolving directory: @dir', array('@dir' => $dir)));
}
$command = 'git clone ' . $repo->options['source_repo'] . ' ' . $realpath . '/' . $repo->name;
//$result = exec($command, $output, $return_var);
$command = 'cd ' . $realpath . '/' . $repo->name . '; git rev-parse --show-toplevel;';
$git_path = exec($command, $output, $return_var);
$repopath = $realpath . '/' . $repo->name;
if (strtolower($git_path) !== strtolower($repopath)) {
$operation = 'clone';
$command = 'git clone ' . $repo->options['source_repo'] . ' ' . $repopath;
}
else {
$operation = 'pull';
$command = 'cd ' . $repopath . '; git pull;';
}
ob_start();
passthru($command, $return_var);
......@@ -147,11 +158,11 @@ function git_include($name) {
drupal_set_message($result, 'git_include');
if ($return_var !== 0) {
if (!is_int($return_var) || $return_var !== 0) {
throw new Exception(t('Shell command returned with status @status: @command', array('@command' => $command, '@status' => $return_var)));
}
else {
drupal_set_message('Success!', 'status');
drupal_set_message(t('Git @op completed for @repo', array('@op' => $operation, '@repo' => $repo->options['label'])), 'status');
}
return $result;
......
......@@ -98,6 +98,7 @@ class git_include_export_ui extends ctools_export_ui {
*/
function run_page($js, $input, $item) {
watchdog('git_include', 'Running ' . $item->name);
try {
git_include($item->name);
$input['test_result'] = theme_status_messages(array('display' => NULL));
......@@ -107,6 +108,7 @@ class git_include_export_ui extends ctools_export_ui {
watchdog_exception('git_include', $e);
$input['test_result'] = theme_status_messages(array('display' => NULL));
}
watchdog('git_include', 'Finished running ' . $item->name);
if (!$js) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment