Run any git command, like "status" or "checkout -b mybranch origin/mybranch"

@throws  RuntimeException
@param   string  $commandString
@return  string  $output
164
public function git($commandString)
    {
        // clean commands that begin with "git "
        $commandString = preg_replace('/^git\s/', '', $commandString);

        $commandString = $this->options['git_executable'].' '.$commandString;

        $command = new $this->options['command_class']($this->dir, $commandString, $this->debug);

        return $command->run();
    }
1303187
public function git_run($command)
    {
        $git = escapeshellarg(pake_which('git'));

        if (self::$needs_work_tree_workaround === true) {
            $cmd = '(cd '.escapeshellarg($this->repository_path).' && '.$git.' '.$command.')';
        } else {
            $cmd = $git;
            $cmd .= ' --git-dir='.escapeshellarg($this->repository_path.'/.git');
            $cmd .= ' --work-tree='.escapeshellarg($this->repository_path);
            $cmd .= ' '.$command;
        }

        try {
            return pake_sh($cmd);
        } catch (pakeException $e) {
            if (strpos($e->getMessage(), 'cannot be used without a working tree') !== false ||
                // workaround for windows (using win7 and git 1.7.10)
                strpos($e->getMessage(), 'fatal: Could not switch to ') !== false) {
                pake_echo_error('Your version of git is buggy. Using workaround');
                self::$needs_work_tree_workaround = true;
                return $this->git_run($command);
            }

            throw $e;
        }
    }
918493
private function runCommand($cmd, $package = null, $args, $noAddtlArguments = false)
    {
        $translator = $this->getServiceLocator()->get('translator');
        $docPath = str_replace(['\\', 'public/../'], '', $this->getDocumentRoot());
        $docPath = trim(substr($docPath, 0, strlen($docPath) - 1)); // remove last "/" trail


        set_time_limit(0);
        ini_set('memory_limit', -1);
        putenv('COMPOSER_HOME=' . self::COMPOSER);


        if (in_array($cmd, $this->availableCommands())) {

            $dryRunArgs = null;

            if ($this->getDryRun()) {
                $dryRunArgs = self::DRY_RUN_ARGS;
            }

            $noProgress = self::NO_PROGRESS;
            $ignoreReqs = self::IGNORE_REQ;
            $preferDist = self::PREFER_DIST;
            $noScript = self::NO_SCRIPTS;
            $commandString = "$cmd $package $dryRunArgs $args $ignoreReqs $noProgress $noScript $preferDist --working-dir=\"$docPath\"";

            // override commandstring if noAddtlArguments is set to "true"
            if ($noAddtlArguments) {
                $commandString = "$cmd --working-dir=\"$docPath\"";
            }

            $input = new StringInput($commandString);
            $output = new StreamOutput(fopen('php://output', 'w'));
            $composer = new Application();
            $formatter = $output->getFormatter();

            $formatter->setDecorated(true);
            $formatter->setStyle('error', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
            $formatter->setStyle('info', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::INFO));
            $formatter->setStyle('comment', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::COMMENT));
            $formatter->setStyle('warning', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
            $output->setFormatter($formatter);

            chdir($docPath);

            if (PHP_OS !== 'AIX' && DIRECTORY_SEPARATOR == '/') {
                /** proc_open(): fork failed - Cannot allocate memory [fix] | linux only */
                shell_exec('sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024');
                shell_exec('sudo /sbin/mkswap /var/swap.1');
                shell_exec('sudo /sbin/swapon /var/swap.1');
            }

            $composer->run($input, $output);

            return $output;
        }

        return sprintf($translator->translate('tr_market_place_unknown_command'), $cmd);
    }
1358607
public function getCommand()
    {
        if (is_null($this->commandName)) {
            throw new \RuntimeException("You should pass a commandName to execute a command");
        }

        $command = '';
        $command .= $this->getCLIConfigs();
        $command .= $this->getCLIGlobalOptions();
        $command .= $this->getCLICommandName();
        $command .= $this->getCLICommandArguments();
        $command .= $this->getCLISubjects();
        $command .= $this->getCLIPath();

        $command = preg_replace('/\\s{2,}/', ' ', $command);

        return trim($command);
    }
16960
private function runGitCommand($command)
    {
        $path = dirname($this->file);
        $process = new Process($command, $path);

        if (0 === $process->run()) {
            return trim($process->getOutput());
        }

        throw new RuntimeException(
            sprintf(
                'The tag or commit hash could not be retrieved from "%s": %s',
                $path,
                $process->getErrorOutput()
            )
        );
    }
240834
public function run(
        ?string $command,
        $input = [],
        OutputInterface $output = null
    ): CommandOutput {
        if (is_array($input)) {
            $input = new ArrayInput($input + compact('command'));
        }
        $output = $output ?? new BufferedOutput();

        $command = $this->getApplication()->find($command);
        $code = ContainerScope::runScope($this->container, function () use (
            $command,
            $input,
            $output
        ) {
            return $command->run($input, $output);
        });

        return new CommandOutput($code ?? self::CODE_NONE, $output);
    }
1009032
protected function cloneRepo($url, $dest, $branch)
    {
        $command = "git clone --branch=$branch $url $dest";
        $this->info("Run \"$command\".");

        File::makeDirectory($dest, 0755, true);

        $output = [];
        exec($command, $output, $returnStatusCode);

        if ($returnStatusCode !== 0) {
            throw RuntimeException::commandExecutionFailed(
                $command, $returnStatusCode
            );
        }

        $this->info("\"$command\" was successfully ran.");
    }
760578
public function
	Run($cmd=null) {
	/*//
	@argv string HandlerName
	@argv array CommandArgumentList

	if given a string it will execute the handler defined under as that name.
	if given an array then it will process that array as though it was the
	_SERVER['argv'] data and execute as if that was the original command line
	given to the object creation.
	//*/

		$restore = false;
		$return = 0;

		////////
		////////

		if(is_array($cmd)) {
			// rewrite our input and option data with this subcommand
			// that was given to us. execute as though this array defined
			// the original command input.

			$restore = [ 'Inputs'=>$this->Inputs, 'Options'=>$this->Options ];

			$data = static::ParseCommandArgs($cmd,false);
			$this->Inputs = $data['Inputs'];
			$this->Options = $data['Options'];

			$cmd = $this->GetInputs();
		}

		////////
		////////

		if(!$cmd && !($cmd = $this->GetInput(1))) {
			if(!$this->DefaultHandlerName) {
				echo "No input provided.", PHP_EOL;
				return static::ErrorNoInput;

			}

			$cmd = [$this->DefaultHandlerName];
		}

		else {
			$cmd = $this->GetInputs();
		}

		////////
		////////

		$Commanded = FALSE;

		foreach($cmd as $cur) {
			$method = static::GetMethodFromCommand($cur);
			try {
				$return = $this->Run_ByMethod($method);
				$Commanded = TRUE;
			}
			catch(ClientHandlerException $e) {
				try {
					$return = $this->Run_ByCallable($cur);
					$Commanded = TRUE;
				}
				catch(ClientHandlerException $e) { }
			}

			if($Commanded && !$this->ChainCommands)
			break;
		}

		if(!$Commanded) {
			echo "no handler or method found for {$cur}", PHP_EOL;
			return static::ErrorNoHandler;
		}

		////////
		////////

		if($restore) {
			// restore the original input data before continuing on so that
			// we could continue processing the cli input data if needed.
			$this->Inputs = $restore['Inputs'];
			$this->Options = $restore['Options'];
		}

		return $return;
	}
297469
protected function executeCommand($sCommand)
    {
        if (is_iterable($sCommand)) {
            foreach ($sCommand as $sCommand) {
                $this->executeCommand($sCommand);
            }
        } elseif (is_string($sCommand)) {

            $this->oOutput->writeln('> <info>' . $sCommand . '</info>');
            exec($sCommand, $aOutput, $iReturnVal);

            if ($iReturnVal) {
                throw new \RuntimeException('Failed to execute command: ' . $sCommand, $iReturnVal);
            }
        }
    }
313010
public function run()
    {
        $result = $this->getCommand()->run();

        if ($result->getExitCode() != 0) {
            throw new \RuntimeException(sprintf(
                'Command failed. Exit code %d, output %s',
                $result->getExitCode(),
                $result->getStdErr()));
        }

        return $this->parse($result->getStdOut());
    }
914509
public function rawRun($commandString)
    {
        $this->validateCommand($commandString);

        /** @var $process \Symfony\Component\Process\Process */
        $process = new $this->processClass($commandString);
        $process->setTimeout($this->timeout);
        $process->run();

        if (!$process->isSuccessful()) {
            throw new RuntimeException($process->getErrorOutput());
        }

        return $process->getOutput();
    }
624776
public function remoteBranchExists($remote, $branch)
    {
        $result = $this->processHelper->runCommand(['git', 'ls-remote', $remote], true);
        if (1 >= ($exists = preg_match_all('#(?<=\s)'.preg_quote('refs/heads/'.$branch, '#').'(?!\w)$#m', $result))) {
            return 1 === $exists;
        }

        throw new \RuntimeException(sprintf('Invalid refs found while searching for remote branch at "refs/heads/%s"', $branch));
    }
249213
public function run($command, $repository = null, $force = false)
    {
        list($stdout, $status, $stderr) = parent::run($command, $repository);
        if (!empty($stderr)) {
            throw new GitRuntimeException($stderr);
        }
        return $stdout;
    }
848259
protected function run($cmd/*, $options = NULL*/){
		$args = func_get_args ();
		$cmd = $this->_processCommand ( $args );
		exec ( $cmd . ' 2>&1', $output, $ret );

		if ($ret !== 0) {
			throw new GitException ( implode("<br>",$output), $ret );
		}

		return $this;
	}
1082289
public function executeCommand($cmd, $timeout = 300)
    {
        $php = escapeshellarg($this->getPhp());
        $process = new Process($php.' '.$this->root_dir.'console '.$cmd, $this->root_dir.'/../', null, null, $timeout);
        $process->run(function ($type, $buffer) {
            echo $buffer;
        });

        if (!$process->isSuccessful()) {
            throw new \RuntimeException(sprintf('An error occurred when executing the "%s" command.', $cmd));
        }
    }
1310201
public function complete()
    {
        $folder  = SetupHelper::getRootFolder();
        $command = sprintf(
            'cd %1$s && git init',
            escapeshellarg($folder)
        );

        exec($command, $output, $return);

        if (0 !== $return) {
            throw new RuntimeException(
                sprintf(
                    'Could not initialize the VCS in folder "%1$s". [Exit Status: %2$d]',
                    $folder,
                    $return
                )
            );
        }
    }
716149
public function runCommand($command, OutputInterface $output = null)
    {
        $input = new StringInput($command);

        $command = $this->find($this->getCommandName($input));

        return $command->run($input, $output ?: new NullOutput());
    }