Esempio n. 1
0
 /**
  * Implement this by setting $obj values (e.g. $obj->setId($row->Id) from a DB row
  * @param GD_Model_Project $obj
  * @param Zend_Db_Table_Row_Abstract $row
  */
 protected function populateObjectFromRow(&$obj, Zend_Db_Table_Row_Abstract $row)
 {
     $obj->setId($row->id)->setName($row->name)->setSlug($row->slug)->setRepositoryTypesId($row->repository_types_id)->setRepositoryUrl($row->repository_url)->setDeploymentBranch($row->deployment_branch)->setSSHKeysId($row->ssh_keys_id);
     $pk_map = new GD_Model_SSHKeysMapper();
     $public_key = new GD_Model_SSHKey();
     $pk_map->populateObjectFromRow($public_key, $row->findParentRow('GD_Model_DbTable_SSHKeys'));
     $obj->setSSHKey($public_key);
 }
Esempio n. 2
0
 /**
  * Probe the repository to determine what branch we are currently on
  *
  * @param bool $silent Do not throw exceptions if something goes wrong
  * @throws GD_Exception
  * @return string|false Branch name or false if failed
  */
 public function getCurrentBranch($silent = false)
 {
     $this->runShell('git status');
     if ($this->_last_errno == 0) {
         if ($this->_last_output[0] == "# Not currently on any branch.") {
             if (!$silent) {
                 throw new GD_Exception("Git repository for {$this->_project->getName()} was not on a branch.", self::GIT_STATUS_ERROR_NOT_ON_BRANCH);
             } else {
                 return false;
             }
         } else {
             if (preg_match("/# On branch ([a-zA-Z0-9-.]*)/", $this->_last_output[0], $matches)) {
                 return $matches[1];
             } else {
                 if (!$silent) {
                     throw new GD_Exception("Unhandled error in getCurrentBranch", self::GIT_STATUS_ERROR_UNKNOWN);
                 } else {
                     return false;
                 }
             }
         }
     } else {
         if (!$silent) {
             throw new GD_Exception("Git status did not work.", self::GIT_STATUS_ERROR_UNKNOWN);
         } else {
             return false;
         }
     }
 }
Esempio n. 3
0
 public function isValid($value)
 {
     $this->_setValue($value);
     $git = GD_Git::FromProject($this->_project);
     try {
         if ($git->checkValidRepository()) {
             if ($git->gitCheckout($value)) {
                 return true;
             }
         }
         $this->_error(self::INVALID);
         return false;
     } catch (GD_Exception $ex) {
         GD_Debug::Log("Repository for {$this->_project->getName()} was not valid [{$ex->getStringCode()}]", GD_Debug::DEBUG_BASIC);
         $this->_error(self::NO_REPO);
         return false;
     }
 }
Esempio n. 4
0
 /**
  * Generate a new GD_Git instance based on a GD_Model_Project object
  *
  * @param GD_Model_Project $project
  * @return GD_Git
  */
 public static function FromProject(GD_Model_Project $project)
 {
     return new GD_Git($project->getId(), $project->getRepositoryUrl(), $project->getDeploymentBranch(), $project->getSSHKey()->getPrivateKey());
 }
 public function saveProject(GD_Model_ProjectsMapper $projects, GD_Model_Project $project, $new_project = false, $errored = false)
 {
     $repo_before = $project->getRepositoryUrl();
     $branch_before = $project->getDeploymentBranch();
     $project->setName($this->_request->getParam('name', false));
     $project->setRepositoryUrl($this->_request->getParam('repositoryUrl', false));
     $project->setDeploymentBranch($this->_request->getParam('deploymentBranch', false));
     $project->setRepositoryTypesId(1);
     $project->setSSHKeysId(1);
     $repo_after = $project->getRepositoryUrl();
     $branch_after = $project->getDeploymentBranch();
     // Save the project
     $projects->save($project);
     $git = new GD_Git($project);
     $branch_changed = false;
     // If repo URL changed, delete and re-clone
     if ($repo_before != $repo_after || $new_project || $errored) {
         // Delete any existing repo
         $git->deleteRepository();
         // Clone repository from source
         $result = $git->gitClone();
         if ($result !== true) {
             return $result;
         }
         // Checkout the appropriate branch
         if (!$git->gitCheckout($branch_after)) {
             return "Branch '{$branch_after}' does not exist.";
         }
         $branch_changed = true;
     }
     if ($branch_before != $branch_after && !$branch_changed) {
         // If not already checked out, or branch has changed, do a checkout
         $git->gitCheckout($branch_after);
     }
     return true;
 }