示例#1
0
function userRepoPath($username, $namespace)
{
    $path = unixPathJoin(array('u', $username, $namespace));
    if (strpos($path, '..') !== false) {
        throw new MalformedPathException();
    }
    return $path;
}
 /**
  * Obtain the tree of git repositories for a user
  *
  * @param Array $repositories Array of raw representation of repositories, indexed by repository id (the person that made the choice of the format must be executed)
  * @param PFUser  $user         The user who traverse the forest (yet another foolish expression)
  *
  * @result Array
  */
 public function getTree(array $repositories, PFUser $user)
 {
     $tree = array();
     foreach ($repositories as $repoId => $row) {
         $path = explode('/', unixPathJoin(array($row['repository_namespace'], $row['repository_name'])));
         $repo = $this->getRepository($row);
         if ($repo->userCanRead($user)) {
             $this->insertInTree($tree, $repo, $path);
         }
     }
     return $tree;
 }
 public function repoFullName(GitRepository $repo, $unix_name)
 {
     require_once GIT_BASE_DIR . '/PathJoinUtil.php';
     return unixPathJoin(array($unix_name, $repo->getFullName()));
 }
示例#4
0
 public function fork($repo, $old_ns, $new_ns)
 {
     $source = unixPathJoin(array($this->getRepositoriesPath(), $old_ns, $repo)) . '.git';
     $target = unixPathJoin(array($this->getRepositoriesPath(), $new_ns, $repo)) . '.git';
     if (!is_dir($target)) {
         $asGroupGitolite = 'sg - gitolite -c ';
         $cmd = 'umask 0007; ' . $asGroupGitolite . ' "git clone --bare ' . $source . ' ' . $target . '"';
         $clone_result = $this->gitCmd($cmd);
         $copyHooks = 'cd ' . $this->getRepositoriesPath() . '; ';
         $copyHooks .= $asGroupGitolite . ' "cp -f ' . $source . '/hooks/* ' . $target . '/hooks/"';
         $this->gitCmd($copyHooks);
         $saveNamespace = 'cd ' . $this->getRepositoriesPath() . '; ';
         $saveNamespace .= $asGroupGitolite . ' "echo -n ' . $new_ns . ' > ' . $target . '/tuleap_namespace"';
         $this->gitCmd($saveNamespace);
         return $clone_result;
     }
     return false;
 }
示例#5
0
 function testAllEmptyElementsAreIgnored()
 {
     $this->assertEqual('toto/0', unixPathJoin(array('', null, 'toto', '0')));
 }
示例#6
0
 public function fork($user, $namespace, $scope, Project $project)
 {
     $clone = clone $this;
     $clone->setProject($project);
     $clone->setCreator($user);
     $clone->setParent($this);
     $clone->setNamespace($namespace);
     $clone->setId(null);
     $path = unixPathJoin(array($project->getUnixName(), $namespace, $this->getName())) . '.git';
     $clone->setPath($path);
     $clone->setScope($scope);
     $this->getBackend()->fork($this, $clone);
 }
 /**
  * Fork a repository
  *
  * @param GitRepository $repository      The repo to fork
  * @param Project       $to_project      The project to create the repo in
  * @param PFUser        $user            The user who does the fork (she will own the clone)
  * @param String        $namespace       The namespace to put the repo in (might be emtpy)
  * @param String        $scope           Either GitRepository::REPO_SCOPE_INDIVIDUAL or GitRepository::REPO_SCOPE_PROJECT
  * @param Array         $forkPermissions Permissions to be applied for the new repository
  */
 public function fork(GitRepository $repository, Project $to_project, PFUser $user, $namespace, $scope, array $forkPermissions)
 {
     $clone = clone $repository;
     $clone->setProject($to_project);
     $clone->setCreator($user);
     $clone->setParent($repository);
     $clone->setNamespace($namespace);
     $clone->setId(null);
     $path = unixPathJoin(array($to_project->getUnixName(), $namespace, $repository->getName())) . '.git';
     $clone->setPath($path);
     $clone->setScope($scope);
     $this->assertRepositoryNameNotAlreadyUsed($clone);
     $this->doForkRepository($repository, $clone, $forkPermissions);
 }
示例#8
0
 public function testForkCrossProjectClonesByChangingTheProjectAndPath()
 {
     $user = $this->_newUser("sandra");
     $backend = new MockGit_Backend_Gitolite();
     $project = new Mockproject();
     $project->setReturnValue('getUnixName', 'tulip');
     $to_project = new Mockproject();
     $to_project->setReturnValue('getUnixName', 'blabla');
     $repo = new GitRepository();
     $repo->setBackend($backend);
     $repo->setProject($project);
     $expectedRepo = $this->_aGitRepoWith($user, $repo, '', $backend, GitRepository::REPO_SCOPE_PROJECT);
     $expectedRepo->setProject($to_project);
     $expectedRepo->setPath(unixPathJoin(array($to_project->getUnixName(), '', $repo->getName())) . '.git');
     $backend->expectOnce('fork', array(new EqualExpectation($repo), new EqualExpectation($expectedRepo)));
     $repo->fork($user, '', GitRepository::REPO_SCOPE_PROJECT, $to_project);
 }
 /**
  * Return relative path from project repository root (without .git)
  * 
  * @return String
  */
 public function getFullName()
 {
     return unixPathJoin(array($this->getNamespace(), $this->getName()));
 }