/**
* @param array $dirs
*/
- function __construct($dirs = array()) {
+ public function __construct($dirs = array()) {
$this->dirs = $dirs;
}
*
* @throws Exception
*/
- function push($dir) {
+ public function push($dir) {
$this->dirs[] = getcwd();
if (!chdir($dir)) {
throw new Exception("Failed to chdir($dir)");
}
}
- function pop() {
+ public function pop() {
$oldDir = array_pop($this->dirs);
chdir($oldDir);
}
+
}
/**
public function getRequestorRepoUrl() {
return $this->data->head->repo->git_url;
}
+
}
/**
/**
*
*/
- function __construct() {
+ public function __construct() {
$this->dirStack = new DirStack();
$this->repos = array(
'core' => '.',
*
* @throws Exception
*/
- function main($args) {
+ public function main($args) {
if (!$this->parseOptions($args)) {
printf("Error parsing arguments\n");
$this->doHelp();
case 'checkout':
call_user_func_array(array($this, 'doCheckoutAll'), $this->arguments);
break;
+
case 'fetch':
call_user_func_array(array($this, 'doFetchAll'), $this->arguments);
break;
+
case 'status':
call_user_func_array(array($this, 'doStatusAll'), $this->arguments);
break;
+
case 'begin':
call_user_func_array(array($this, 'doBegin'), $this->arguments);
break;
+
case 'resume':
call_user_func_array(array($this, 'doResume'), $this->arguments);
break;
+
case 'review':
call_user_func_array(array($this, 'doReview'), $this->arguments);
break;
+
//case 'merge-forward':
// call_user_func_array(array($this, 'doMergeForward'), $this->arguments);
// break;
+
case 'push':
call_user_func_array(array($this, 'doPush'), $this->arguments);
break;
+
case 'help':
case '':
$this->doHelp();
break;
+
default:
return $this->returnError("unrecognized action: {$this->action}\n");
}
* @param $args
* @return bool
*/
- function parseOptions($args) {
+ public function parseOptions($args) {
$this->branches = array();
$this->arguments = array();
return TRUE;
}
- function doHelp() {
+ public function doHelp() {
$program = basename($this->program);
echo "Givi - Coordinate git checkouts across CiviCRM repositories\n";
echo "Scenario:\n";
*
* @return bool
*/
- function doCheckoutAll($baseBranch = NULL) {
+ public function doCheckoutAll($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <branch>\n");
}
/**
* @return bool
*/
- function doStatusAll() {
+ public function doStatusAll() {
foreach ($this->repos as $repo => $relPath) {
$this->run($repo, $relPath, 'git', 'status');
}
*
* @return bool
*/
- function doBegin($baseBranch = NULL) {
+ public function doBegin($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <base-branch>\n");
}
* @return bool
* @throws Exception
*/
- function doResume($baseBranch = NULL) {
+ public function doResume($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <base-branch>\n");
}
*
* @return bool
*/
- function doReview($baseBranch = NULL) {
+ public function doReview($baseBranch = NULL) {
if (!$this->doCheckoutAll($baseBranch)) {
return FALSE;
}
return TRUE;
}
- /*
-
- If we want merge-forward changes to be subject to PR process, then this
- should useful. Currently using a simpler process based on
- toosl/scripts/merge-forward
-
- function doMergeForward($maintBranch, $devBranch) {
- if (!$maintBranch) {
- return $this->returnError("Missing <maintenace-base-branch>\n");
- }
- if (!$devBranch) {
- return $this->returnError("Missing <development-base-branch>\n");
- }
- list ($maintBranchRepo, $maintBranchName) = $this->parseBranchRepo($maintBranch);
- list ($devBranchRepo, $devBranchName) = $this->parseBranchRepo($devBranch);
-
- $newBranchRepo = $devBranchRepo;
- $newBranchName = $maintBranchName . '-' . $devBranchName . '-' . date('Y-m-d-H-i-s');
-
- if ($this->fetch) {
- $this->doFetchAll();
- }
-
- foreach ($this->repos as $repo => $relPath) {
- $filteredMaintBranch = $this->filterBranchName($repo, $maintBranch);
- $filteredDevBranch = $this->filterBranchName($repo, $devBranch);
- $filteredNewBranchName = $this->filterBranchName($repo, $newBranchName);
-
- $this->run($repo, $relPath, 'git', 'checkout', '-b', $filteredNewBranchName, $filteredDevBranch);
- $this->run($repo, $relPath, 'git', 'merge', $filteredMaintBranch);
- }
- }
- */
-
/**
* @param $newBranchRepo
* @param $newBranchNames
*
* @return bool
*/
- function doPush($newBranchRepo, $newBranchNames) {
+ public function doPush($newBranchRepo, $newBranchNames) {
if (!$newBranchRepo) {
return $this->returnError("Missing <remote>\n");
}
* @param string $name branch name
* @return bool
*/
- function hasLocalBranch($repo, $name) {
+ public function hasLocalBranch($repo, $name) {
$path = $this->repos[$repo] . '/.git/refs/heads/' . $name;
return file_exists($path);
}
* @throws Exception
* @return array
*/
- function parseBranchRepo($ref, $defaultRemote = 'origin') {
+ public function parseBranchRepo($ref, $defaultRemote = 'origin') {
$parts = explode('/', $ref);
if (count($parts) == 1) {
return array($defaultRemote, $parts[1]);
*
* @return string
*/
- function run($repoName, $runDir, $command) {
+ public function run($repoName, $runDir, $command) {
$this->dirStack->push($runDir);
$args = func_get_args();
return $r;
}
- function doFetchAll() {
+ public function doFetchAll() {
foreach ($this->repos as $repo => $relPath) {
$this->run($repo, $relPath, 'git', 'fetch', '--all');
}
*
* @return array ($repoName => $gitRef)
*/
- function resolveBranches($default, $overrides) {
+ public function resolveBranches($default, $overrides) {
$branches = $overrides;
foreach ($this->repos as $repo => $relPath) {
if (!isset($branches[$repo])) {
*
* @return string
*/
- function filterBranchName($repoName, $branchName) {
+ public function filterBranchName($repoName, $branchName) {
if ($branchName == '') {
return '';
}
* @throws Exception
* @return array ($repoName => $repoDir)
*/
- function filterRepos($filter, $repos) {
+ public function filterRepos($filter, $repos) {
if ($filter == 'all') {
return $repos;
}
*
* @return bool
*/
- function returnError($message) {
+ public function returnError($message) {
echo "\nERROR: ", $message, "\n\n";
$this->doHelp();
return FALSE;
}
+
}
/**
*
* @return bool
*/
- static function download($url, $file) {
+ public static function download($url, $file) {
// PHP native client is unreliable PITA for HTTPS
if (exec("which wget")) {
self::run('wget', '-q', '-O', $file, $url);
*
* @return mixed
*/
- static function getJson($url) {
+ public static function getJson($url) {
$file = tempnam(sys_get_temp_dir(), 'givi-json-');
HttpClient::download($url, $file);
$data = json_decode(file_get_contents($file));
* @internal param string $runDir
* @return string
*/
- static function run($command) {
+ public static function run($command) {
$args = func_get_args();
array_shift($args);
foreach ($args as $arg) {
return $r;
}
+
}
$givi = new Givi();