Пример #1
0
 /**
  * Constructor.
  *
  * @param GitRepository $repository The git repository to work on.
  */
 public function __construct(GitRepository $repository)
 {
     $this->repository = $repository;
     $this->processBuilder = new ProcessBuilder();
     $this->processBuilder->setWorkingDirectory($repository->getRepositoryPath());
     $this->processBuilder->add($this->repository->getConfig()->getGitExecutablePath());
     $this->initializeProcessBuilder();
 }
Пример #2
0
 /**
  * @covers \Bit3\GitPhp\GitRepository::getRepositoryPath
  */
 public function testGetRepositoryPath()
 {
     $this->assertEquals($this->initializedRepositoryPath, $this->initializedGitRepository->getRepositoryPath());
     $this->assertEquals($this->uninitializedRepositoryPath, $this->uninitializedGitRepository->getRepositoryPath());
 }
 /**
  * Retrieve the data of the current user on the system.
  *
  * @param GitRepository $git The repository to extract all files from.
  *
  * @return string
  *
  * @throws GitException When the git execution failed.
  */
 private function getCurrentUserInfo($git)
 {
     // Sadly no command in our git library for this.
     $processBuilder = new ProcessBuilder();
     $processBuilder->setWorkingDirectory($git->getRepositoryPath());
     $processBuilder->add($git->getConfig()->getGitExecutablePath())->add('config')->add('--get-regexp')->add('user.[name|email]');
     $process = $processBuilder->getProcess();
     $git->getConfig()->getLogger()->debug(sprintf('[git-php] exec [%s] %s', $process->getWorkingDirectory(), $process->getCommandLine()));
     $process->run();
     $output = rtrim($process->getOutput(), "\r\n");
     if (!$process->isSuccessful()) {
         throw GitException::createFromProcess('Could not execute git command', $process);
     }
     $config = array();
     foreach (explode(PHP_EOL, $output) as $line) {
         list($name, $value) = explode(' ', $line, 2);
         $config[trim($name)] = trim($value);
     }
     if (isset($config['user.name']) && $config['user.email']) {
         return sprintf('%s <%s>', $config['user.name'], $config['user.email']);
     }
     return '';
 }