class DirStack {
protected $dirs;
+ /**
+ * @param array $dirs
+ */
function __construct($dirs = array()) {
$this->dirs = $dirs;
}
+ /**
+ * @param $dir
+ *
+ * @throws Exception
+ */
function push($dir) {
$this->dirs[] = getcwd();
if (!chdir($dir)) {
protected $data;
+ /**
+ * @return mixed
+ */
public function getNumber() {
return $this->data->number;
}
}
}
+/**
+ * Class Givi
+ */
class Givi {
/**
*/
protected $dirStack;
+ /**
+ *
+ */
function __construct() {
$this->dirStack = new DirStack();
$this->repos = array(
);
}
+ /**
+ * @param $args
+ *
+ * @throws Exception
+ */
function main($args) {
if (!$this->parseOptions($args)) {
printf("Error parsing arguments\n");
echo "local branches.\n";
}
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ */
function doCheckoutAll($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <branch>\n");
return TRUE;
}
+ /**
+ * @return bool
+ */
function doStatusAll() {
foreach ($this->repos as $repo => $relPath) {
$this->run($repo, $relPath, 'git', 'status');
return TRUE;
}
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ */
function doBegin($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <base-branch>\n");
return TRUE;
}
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ * @throws Exception
+ */
function doResume($baseBranch = NULL) {
if (!$baseBranch) {
return $this->returnError("Missing <base-branch>\n");
return TRUE;
}
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ */
function doReview($baseBranch = NULL) {
- if (! $this->doCheckoutAll($baseBranch)) {
+ if (!$this->doCheckoutAll($baseBranch)) {
return FALSE;
}
$pullRequest = PullRequest::get($prUrl, $this->repos);
if ($pullRequest) {
$pullRequests[] = $pullRequest;
- } else {
+ }
+ else {
return $this->returnError("Invalid pull-request URL: $prUrl");
}
}
}
*/
+ /**
+ * @param $newBranchRepo
+ * @param $newBranchNames
+ *
+ * @return bool
+ */
function doPush($newBranchRepo, $newBranchNames) {
if (!$newBranchRepo) {
return $this->returnError("Missing <remote>\n");
return $this->returnError("Missing <branch>[:<branch>]\n");
}
if (FALSE !== strpos($newBranchNames, ':')) {
- list ($newBranchFromName,$newBranchToName) = explode(':', $newBranchNames);
+ list ($newBranchFromName, $newBranchToName) = explode(':', $newBranchNames);
foreach ($this->repos as $repo => $relPath) {
$filteredFromName = $this->filterBranchName($repo, $newBranchFromName);
$filteredToName = $this->filterBranchName($repo, $newBranchToName);
$this->run($repo, $relPath, 'git', 'push', $newBranchRepo, $filteredFromName . ':' . $filteredToName);
}
- } else {
+ }
+ else {
foreach ($this->repos as $repo => $relPath) {
$filteredName = $this->filterBranchName($repo, $newBranchNames);
$this->run($repo, $relPath, 'git', 'push', $newBranchRepo, $filteredName);
printf("\n\n\nRUN [%s]: %s\n", $repoName, $command);
if ($this->dryRun) {
$r = NULL;
- } else {
+ }
+ else {
$r = system($command);
}
return $branches;
}
+ /**
+ * @param $repoName
+ * @param $branchName
+ *
+ * @return string
+ */
function filterBranchName($repoName, $branchName) {
if ($branchName == '') {
return '';
return $repos;
}
+ /**
+ * @param $message
+ *
+ * @return bool
+ */
function returnError($message) {
echo "\nERROR: ", $message, "\n\n";
$this->doHelp();
}
}
+/**
+ * Class HttpClient
+ */
class HttpClient {
+ /**
+ * @param $url
+ * @param $file
+ *
+ * @return bool
+ */
static function download($url, $file) {
// PHP native client is unreliable PITA for HTTPS
if (exec("which wget")) {
self::run('wget', '-q', '-O', $file, $url);
- } elseif (exec("which curl")) {
+ }
+ elseif (exec("which curl")) {
self::run('curl', '-o', $file, $url);
}
return TRUE;
}
+ /**
+ * @param $url
+ *
+ * @return mixed
+ */
static function getJson($url) {
$file = tempnam(sys_get_temp_dir(), 'givi-json-');
HttpClient::download($url, $file);