| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: gb.module,v 1.1 2009/04/30 13:26:16 gordon Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Provide a git browsing API which allows other modules to add the ability |
* Provide a git browsing API which allows other modules to add the ability |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
|
* Implementation of hook_menu(). |
| 11 |
|
*/ |
| 12 |
|
function gb_menu() { |
| 13 |
|
$items = array(); |
| 14 |
|
|
| 15 |
|
$items['admin/settings/git'] = array( |
| 16 |
|
'title' => 'Git Browser', |
| 17 |
|
'page callback' => 'drupal_get_form', |
| 18 |
|
'page arguments' => array('gb_settings'), |
| 19 |
|
'access arguments' => array('administer site configuration'), |
| 20 |
|
'description' => 'Configuration settings for Git Brownser', |
| 21 |
|
); |
| 22 |
|
|
| 23 |
|
return $items; |
| 24 |
|
} |
| 25 |
|
|
| 26 |
|
function gb_settings() { |
| 27 |
|
$form = array(); |
| 28 |
|
|
| 29 |
|
$form['git_cmd'] = array( |
| 30 |
|
'#type' => 'textfield', |
| 31 |
|
'#title' => t('Path to git'), |
| 32 |
|
'#default_value' => variable_get('git_cmd', '/usr/bin/git') |
| 33 |
|
); |
| 34 |
|
|
| 35 |
|
$version = gb_git(NULL, '--version'); |
| 36 |
|
$form['git_version'] = array( |
| 37 |
|
'#type' => 'item', |
| 38 |
|
'#title' => t('Git version'), |
| 39 |
|
'#value' => implode("<br />\n", $version), |
| 40 |
|
); |
| 41 |
|
return system_settings_form($form); |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
/** |
| 45 |
* Build menu links |
* Build menu links |
| 46 |
*/ |
*/ |
| 47 |
function gb_build_git_menus($params = array()) { |
function gb_build_git_menus($params = array()) { |
| 243 |
* Run the Git command |
* Run the Git command |
| 244 |
*/ |
*/ |
| 245 |
function gb_git($repos, $command) { |
function gb_git($repos, $command) { |
| 246 |
$git_cmd = variable_get('git_cmd', '/usr/local/bin/git'); |
$cmd = variable_get('git_cmd', '/usr/bin/git'); |
| 247 |
$cmd = $git_cmd .' --git-dir='. realpath($repos) .' '. $command; |
|
| 248 |
|
if ($repos) { |
| 249 |
|
$cmd .= ' --git-dir='. realpath($repos); |
| 250 |
|
} |
| 251 |
|
$cmd .= ' '. $command; |
| 252 |
|
|
| 253 |
exec($cmd, $output, $ret); |
exec($cmd, $output, $ret); |
| 254 |
//dpm($output); |
//dpm($output); |
| 255 |
|
|
| 256 |
if ($ret) { |
if ($ret) { |
| 257 |
dpm($ret); |
drupal_set_message(t('Problem running git "%cmd"', array('%cmd' => $cmd)), 'error'); |
|
dpm($cmd); |
|
| 258 |
} |
} |
| 259 |
|
|
| 260 |
return $output; |
return $output; |