Exemple #1
0
 /**
  * This will push the branch to the specified alias/branch, and add to the loaded branches
  * 
  * @param Sadekbaroudi\Gitorade\Branches\BranchLocal $branchLocal branch object to push
  * @throws GitException
  */
 public function push(BranchLocal $branchLocal)
 {
     if (!$branchLocal->hasRemote()) {
         throw new GitException(__METHOD__ . ": The BranchLocal object must have a remote branch!");
     }
     $this->getGit()->clearOutput();
     $this->getGit()->push($branchLocal->getRemote()->getAlias(), $branchLocal->getRemote()->getBranch());
     $pushOutput = $this->getGit()->getOutput();
     if (!empty($pushOutput)) {
         throw new GitException("Could not push to " . $branchLocal->getRemote()->getAlias() . ". Output: " . PHP_EOL . $pushResults);
     } else {
         // TODO: log this
         $pushed = "remotes/" . $branchLocal->getRemote()->getAlias() . "/" . $branchLocal->getRemote()->getBranch();
         $this->getBm()->add($pushed);
         $logMe = "Successfully pushed {$pushed}!";
         echo $logMe . PHP_EOL;
     }
 }
Exemple #2
0
 /**
  * This will checkout a new branch based on $source with branch name of $new
  * 
  * @param Sadekbaroudi\Gitorade\Branches\Branch $source can be Sadekbaroudi\Gitorade\Branches\BranchLocal or Sadekbaroudi\Gitorade\Branches\BranchRemote
  * @param Sadekbaroudi\Gitorade\Branches\BranchLocal $new the new local branch based on $source
  * @throws OperationStateException If any of the commands fail in the process
  */
 public function checkoutNewBranch($source, $new)
 {
     $beforeMergeBranch = $this->currentBranch();
     $this->stash();
     // TODO: PHP 5.4 supports "new Foo()->method()->method()"
     //       http://docs.php.net/manual/en/migration54.new-features.php
     $os = new OperationState();
     $os->setExecute(array($this->getGit(), 'checkout'), array($source->fullBranchString()));
     $os->addExecute(array($this->getGit(), 'checkoutNewBranch'), array($new->getBranch()));
     $os->setUndo(array($this->getGit(), 'reset'), array(array('hard' => true)));
     $os->addUndo(array($this->getGit(), 'checkout'), array($beforeMergeBranch));
     $os->addUndo(array($this->getGit(), 'branch'), array($new->getBranch(), array('D' => true)));
     $this->getOsm()->add($os);
     try {
         echo "checking out {$source}" . PHP_EOL;
         echo "checking out new local branch {$new}" . PHP_EOL;
         $this->getOsm()->execute($os);
     } catch (OperationStateException $e) {
         $this->getOsm()->undoAll();
         throw $e;
     }
 }