public function process() { global $sys_allow_restricted_users; $parameters = $this->getParametersAsArray(); $project = null; if (!empty($parameters[0])) { $project = $this->getProject($parameters[0]); } else { $this->error('Missing argument project id'); return false; } $repositoryName = ''; if (!empty($parameters[1])) { $repositoryName = $parameters[1]; } else { $this->error('Missing argument repository name'); return false; } $userId = 0; if (!empty($parameters[2])) { $userId = $parameters[2]; } else { $this->error('Missing argument user id'); return false; } try { $repository = new GitRepository(); $repository->setBackend(Backend::instance('Git', 'GitBackend')); $repository->setDescription('-- Default description --'); //default access is private when restricted users are allowed if ($sys_allow_restricted_users == 1) { $repository->setAccess(GitRepository::PRIVATE_ACCESS); } else { $repository->setAccess(GitRepository::PUBLIC_ACCESS); } $user = null; if (!empty($userId)) { $user = UserManager::instance()->getUserById($userId); } if (!empty($user)) { $repository->setCreator($user); } $repository->setProject($project); $repository->setName($repositoryName); $repository->create(); $this->done(); } catch (GitDaoException $e) { $this->error($e->getMessage()); return false; } catch (GitDriverException $e) { $this->error($e->getMessage()); return false; } catch (GitBackendException $e) { $this->error($e->getMessage()); return false; } catch (Exception $e) { $this->error($e->getMessage()); return false; } }
/** * @param string $cloneUrl * @param string $directory * @param array $options * @param array $arguments * @return GitRepository */ public function cloneRepository($cloneUrl, $directory = null, array $options = [], array $arguments = []) { if ($directory === null) { $pathinfo = pathinfo($cloneUrl); $directory = getcwd() . DIRECTORY_SEPARATOR . $pathinfo['filename']; } $gitRepository = new GitRepository($this, $directory); $gitRepository->create($cloneUrl, $options, $arguments); return $gitRepository; }
public function createReference($projectId, $repositoryName) { // Uncomment the following line only for debug prupose if you ever need to // create a gitshell repo (good luck, luke, may the force be with you). //$this->createGitshellReference($projectId, $repositoryName); $c = $this->getController(); $projectId = intval($projectId); $repository = new GitRepository(); $repository->setBackend(new Git_Backend_Gitolite(new Git_GitoliteDriver())); if ($repository->isNameValid($repositoryName) === false) { $c->addError($this->getText('actions_input_format_error', array($repository->getBackend()->getAllowedCharsInNamePattern(), GitDao::REPO_NAME_MAX_LENGTH))); $c->redirect('/plugins/git/?action=index&group_id=' . $projectId); return false; } $project = ProjectManager::instance()->getProject($projectId); $repository->setDescription('-- Default description --'); $repository->setCreator(UserManager::instance()->getCurrentUser()); $repository->setProject($project); $repository->setName($repositoryName); if (!$this->factory->isRepositoryExistingByName($project, $repositoryName)) { $repository->create(); } else { $c->addError($this->getText('actions_create_repo_exists', array($repositoryName))); } $c->redirect('/plugins/git/?action=index&group_id=' . $projectId); return; }