+
+ return TRUE;
+ }
+
+ /**
+ * @param null $baseBranch
+ *
+ * @return bool
+ */
+ public function doReview($baseBranch = NULL) {
+ if (!$this->doCheckoutAll($baseBranch)) {
+ return FALSE;
+ }
+
+ $args = func_get_args();
+ array_shift($args); // $baseBranch
+
+ $pullRequests = array();
+ foreach ($args as $prUrl) {
+ $pullRequest = PullRequest::get($prUrl, $this->repos);
+ if ($pullRequest) {
+ $pullRequests[] = $pullRequest;
+ }
+ else {
+ return $this->returnError("Invalid pull-request URL: $prUrl");
+ }
+ }
+
+ foreach ($pullRequests as $pullRequest) {
+ $repo = $pullRequest->repo;
+ $branchName = 'pull-request-' . $pullRequest->getNumber();
+ if ($this->hasLocalBranch($repo, $branchName)) {
+ $this->run($repo, $this->repos[$repo], 'git', 'branch', '-D', $branchName);
+ }
+ $this->run($repo, $this->repos[$repo], 'git', 'checkout', '-b', $branchName); ## based on whatever was chosen by doCheckoutAll()
+ $this->run($repo, $this->repos[$repo], 'git', 'pull', $pullRequest->getRequestorRepoUrl(), $pullRequest->getRequestorBranch());
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * @param $newBranchRepo
+ * @param $newBranchNames
+ *
+ * @return bool
+ */
+ public function doPush($newBranchRepo, $newBranchNames) {
+ if (!$newBranchRepo) {
+ return $this->returnError("Missing <remote>\n");
+ }
+ if (!$newBranchNames) {
+ return $this->returnError("Missing <branch>[:<branch>]\n");
+ }
+ if (FALSE !== strpos($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 {
+ foreach ($this->repos as $repo => $relPath) {
+ $filteredName = $this->filterBranchName($repo, $newBranchNames);
+ $this->run($repo, $relPath, 'git', 'push', $newBranchRepo, $filteredName);
+ }
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * Determine if a branch exists locally
+ *
+ * @param string $repo
+ * @param string $name branch name
+ * @return bool
+ */
+ public function hasLocalBranch($repo, $name) {
+ $path = $this->repos[$repo] . '/.git/refs/heads/' . $name;
+ return file_exists($path);