/** * Execute a git command on the repository being manipulated * * This method will start a new process on the current machine and * run git commands. Once the command has been run, the method will * return the command line output. * * @param Repository $repository Repository where the command will be run * @param string $command Git command to be run * @return string Returns the command output */ public function run(Repository $repository, $command) { $descriptors = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $process = proc_open($this->getPath() . ' ' . $command, $descriptors, $pipes, $repository->getPath()); if (!is_resource($process)) { throw new \RuntimeException('Unable to execute command: ' . $command); } $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); if (!empty($stderr)) { throw new \RuntimeException($stderr); } $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); proc_close($process); return $stdout; }