/** * Execute the command. * * @return mixed Depend on the command. * * @throws GitException When the command is executed the second time or could not be executed. */ protected function run() { $process = $this->processBuilder->getProcess(); if ($this->output !== null) { throw new GitException('Command cannot be executed twice', $process->getWorkingDirectory(), $process->getCommandLine(), $this->output, ''); } $this->repository->getConfig()->getLogger()->debug(sprintf('[ccabs-repository-git] exec [%s] %s', $process->getWorkingDirectory(), $process->getCommandLine())); if ($this->dryRun) { return $process->getCommandLine(); } $process->run(); $this->output = $process->getOutput(); $this->output = rtrim($this->output, "\r\n"); if (!$process->isSuccessful()) { throw GitException::createFromProcess('Could not execute git command', $process); } return $this->output; }
/** * 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 ''; }