Exemplo n.º 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');
 }
 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));
         }
     }
 }