示例#1
0
 public function perform()
 {
     set_time_limit(0);
     $log = new DeploynautLogFile($this->args['logfile']);
     $projects = DNProject::get()->filter('Name', Convert::raw2sql($this->args['projectName']));
     $project = $projects->first();
     $path = $project->getLocalCVSPath();
     $env = $this->args['env'];
     $log->write('Starting git fetch for project "' . $project->Name . '"');
     // if an alternate user has been configured for clone, run the command as that user
     // @todo Gitonomy doesn't seem to have any way to prefix the command properly, if you
     // set 'sudo -u composer git' as the "command" parameter, it tries to run the whole
     // thing as a single command and fails
     $user = DNData::inst()->getGitUser();
     if (!empty($user)) {
         $command = sprintf('cd %s && sudo -u %s git fetch -p origin +refs/heads/*:refs/heads/* --tags', $path, $user);
         $process = new \Symfony\Component\Process\Process($command);
         $process->setEnv($env);
         $process->setTimeout(3600);
         $process->run();
         if (!$process->isSuccessful()) {
             throw new RuntimeException($process->getErrorOutput());
         }
     } else {
         $repository = new Gitonomy\Git\Repository($path, array('environment_variables' => $env));
         $repository->run('fetch', array('-p', 'origin', '+refs/heads/*:refs/heads/*', '--tags'));
     }
     $log->write('Git fetch is finished');
 }
示例#2
0
 /**
  *
  * @param int $limit - defaults to the ten lates
  * @return array()
  */
 protected function getReferences()
 {
     $repository = new Gitonomy\Git\Repository($this->project->LocalCVSPath);
     if ($this->getTags) {
         if ($this->reference) {
             throw new LogicException("Can't have \$reference and \$getTags both set");
         }
         $log = $repository->getReferences()->getTags();
     } else {
         if ($this->reference) {
             $log = $this->reference->getLog();
         } else {
             $log = $repository->getLog();
         }
     }
     if ($this->limit) {
         if (is_array($log)) {
             $limitedLog = array_slice($log, 0, $this->limit);
         } else {
             $limitedLog = $log->setLimit($this->limit);
         }
     } else {
         $limitedLog = $log;
     }
     // cache them for look up in byName
     $builds = array();
     foreach ($limitedLog as $reference) {
         if ($this->blockBranch) {
             $branchesIncluding = GitonomyCache::getIncludingBranches($reference);
             foreach ($branchesIncluding as $candidate) {
                 if ($candidate->getName() == $this->blockBranch) {
                     // Break out of the function
                     return $builds;
                 }
             }
         }
         if ($this->getTags) {
             $builds[$reference->getCommitHash()] = DNTag::create($reference, $this->project, $this->data);
         } else {
             $name = $this->reference ? $this->reference->getName() : '';
             $builds[$reference->getHash()] = DNCommit::create($reference, $this->project, $this->data, $name);
         }
     }
     return $builds;
 }
示例#3
0
 /**
  * @return array()
  */
 protected function getReferences()
 {
     $branches = array();
     // Placeholder to put master branch first
     $firstBranch = null;
     // return an empty array if the version control isn't checked out yet
     if (!file_exists($this->project->LocalCVSPath)) {
         return array();
     }
     $repository = new Gitonomy\Git\Repository($this->project->LocalCVSPath);
     foreach ($repository->getReferences()->getBranches() as $branch) {
         $obj = new DNBranch($branch, $this->project, $this->data);
         if ($branch->getName() == 'master') {
             $firstBranch = array($branch->getName() => $obj);
         } else {
             $branches[$branch->getName()] = $obj;
         }
     }
     if ($firstBranch) {
         $branches = $firstBranch + $branches;
     }
     return $branches;
 }
示例#4
0
 /**
  * @return array
  */
 protected function getReferences()
 {
     $branches = array();
     // Placeholder to put master branch first
     $firstBranch = null;
     try {
         $repository = new Gitonomy\Git\Repository($this->project->getLocalCVSPath());
     } catch (Exception $e) {
         return $branches;
     }
     foreach ($repository->getReferences()->getBranches() as $branch) {
         /** @var DNBranch $obj */
         $obj = DNBranch::create($branch, $this->project, $this->data);
         if ($branch->getName() == 'master') {
             $firstBranch = array($branch->getName() => $obj);
         } else {
             $branches[$branch->getName()] = $obj;
         }
     }
     if ($firstBranch) {
         $branches = $firstBranch + $branches;
     }
     return $branches;
 }
 protected function initialize()
 {
     if (true === $this->initialized) {
         return;
     }
     $this->initialized = true;
     try {
         $parser = new Parser\ReferenceParser();
         $output = $this->repository->run('show-ref');
     } catch (RuntimeException $e) {
         $output = $e->getOutput();
         $error = $e->getErrorOutput();
         if ($error) {
             throw new RuntimeException('Error while getting list of references: ' . $error);
         }
     }
     $parser->parse($output);
     foreach ($parser->references as $row) {
         list($commitHash, $fullname) = $row;
         if (preg_match('#^refs/(heads|remotes)/(.*)$#', $fullname)) {
             if (preg_match('#.*HEAD$#', $fullname)) {
                 continue;
             }
             $reference = new Branch($this->repository, $fullname, $commitHash);
             $this->references[$fullname] = $reference;
             $this->branches[] = $reference;
         } elseif (preg_match('#^refs/tags/(.*)$#', $fullname)) {
             $reference = new Tag($this->repository, $fullname, $commitHash);
             $this->references[$fullname] = $reference;
             $this->tags[] = $reference;
         } elseif ($fullname === 'refs/stash') {
             $reference = new Stash($this->repository, $fullname, $commitHash);
             $this->references[$fullname] = $reference;
         } elseif (preg_match('#^refs/pull/(.*)$#', $fullname)) {
             // Do nothing here
         } else {
             throw new RuntimeException(sprintf('Unable to parse "%s"', $fullname));
         }
     }
 }
示例#6
0
文件: Hooks.php 项目: beubi/gitlib
 protected function getPath($name)
 {
     return $this->repository->getGitDir() . '/hooks/' . $name;
 }