public function __construct(GD_Model_Project &$project) { $this->_project = $project; $this->_base_gitdir = APPLICATION_PATH . "/../gitcache/"; $this->_gitdir = $this->_base_gitdir . $this->_project->getId(); $this->_url = $this->_project->getRepositoryUrl(); $this->_repotype = $this->parseRepoType($this->_url); if ($this->_repotype == self::GIT_REPOTYPE_HTTP) { throw new GD_Exception("Repository type HTTP/HTTPS not supported yet."); } if (!file_exists($this->_base_gitdir)) { mkdir($this->_base_gitdir, 0700, true); chdir($this->_base_gitdir); } // Check out the specified branch in the project if we're a valid repo try { if ($this->checkValidRepository()) { $this->gitCheckout($project->getDeploymentBranch()); } } catch (GD_Exception $ex) { $invalid = true; } $this->_current_branch = $this->getCurrentBranch(true); }
/** * 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()); }
/** * Should return an array of mapped fields to use in the MAL_Model_MapperAbstract::Save function * @param GD_Model_Project $obj */ protected function getSaveData($obj) { $data = array('name' => $obj->getName(), 'slug' => $obj->getSlug(), 'repository_types_id' => $obj->getRepositoryTypesId(), 'repository_url' => $obj->getRepositoryUrl(), 'deployment_branch' => $obj->getDeploymentBranch(), 'ssh_keys_id' => $obj->getSSHKeysId()); return $data; }
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; }