Gitonomy\Git\Repository::run PHP Method

run() public method

This command is a facility command. You can run any command directly on git repository.
public run ( string $command, array $args = [] ) : string
$command string Git command to run (checkout, branch, tag)
$args array Arguments of git command
return string Output of a successful process or null if execution failed and debug-mode is disabled.
    public function run($command, $args = array())
    {
        $process = $this->getProcess($command, $args);
        if ($this->logger) {
            $this->logger->info(sprintf('run command: %s "%s" ', $command, implode(' ', $args)));
            $before = microtime(true);
        }
        $process->run();
        $output = $process->getOutput();
        if ($this->logger && $this->debug) {
            $duration = microtime(true) - $before;
            $this->logger->debug(sprintf('last command (%s) duration: %sms', $command, sprintf('%.2f', $duration * 1000)));
            $this->logger->debug(sprintf('last command (%s) return code: %s', $command, $process->getExitCode()));
            $this->logger->debug(sprintf('last command (%s) output: %s', $command, $output));
        }
        if (!$process->isSuccessful()) {
            $error = sprintf("error while running %s\n output: \"%s\"", $command, $process->getErrorOutput());
            if ($this->logger) {
                $this->logger->error($error);
            }
            if ($this->debug) {
                throw new ProcessException($process);
            }
            return;
        }
        return $output;
    }

Usage Example

Beispiel #1
0
 /**
  * @return FilesCollection
  */
 public function locate()
 {
     $allFiles = trim($this->repository->run('ls-files'));
     $filePaths = preg_split("/\r\n|\n|\r/", $allFiles);
     $files = array();
     foreach ($filePaths as $file) {
         $files[] = new SplFileInfo($file, dirname($file), $file);
     }
     return new FilesCollection($files);
 }
All Usage Examples Of Gitonomy\Git\Repository::run