public function cloneUrl(string $url, string $to = null, string $repoReference = null, int $depth = null, bool $recursive = false)
    {
        // get binary version before reset
        $v = $this->getBinaryVersion();

        $this->clearAll();
        $this->addCommandName(static::GIT_CLONE_COMMAND);
        $this->addCommandSubject($url);
        if (null !== $to) {
            $this->addCommandSubject2($to);
        }

        if (null !== $repoReference) {
            // git documentation says the --branch was added in 2.0.0, but it exists undocumented at least back to 1.8.3.1
            if (version_compare($v, '1.8.3.1', '<')) {
                throw new \RuntimeException(
                    'Please upgrade to git v1.8.3.1 or newer to support cloning a specific branch. You have ' . $v . '.'
                );
            }
            $this->addCommandArgument('--branch=' . $repoReference);
        }

        if (null !== $depth) {
            $this->addCommandArgument('--depth=' . $depth);
            // shallow-submodules is a nice to have feature. Just ignoring if git version not high enough
            // It would be nice if this had a logger injected for us to log notices
            if (version_compare($v, '2.9.0', '>=') && $recursive && 1 == $depth) {
                $this->addCommandArgument('--shallow-submodules');
            }
        }

        if ($recursive) {
            $this->addCommandArgument('--recursive');
        }

        return $this->getCommand();
    }
public function cloneUrl(string $url, string $to = null, string $repoReference = null, int $depth = null, bool $recursive = false)
    {
        // get binary version before reset
        $v = $this->getBinaryVersion();

        $this->clearAll();
        $this->addCommandName(static::GIT_CLONE_COMMAND);
        $this->addCommandSubject($url);
        if (null !== $to) {
            $this->addCommandSubject2($to);
        }

        if (null !== $repoReference) {
            // git documentation says the --branch was added in 2.0.0, but it exists undocumented at least back to 1.8.3.1
            if (version_compare($v, '1.8.3.1', '<')) {
                throw new \RuntimeException(
                    'Please upgrade to git v1.8.3.1 or newer to support cloning a specific branch. You have ' . $v . '.'
                );
            }
            $this->addCommandArgument('--branch=' . $repoReference);
        }

        if (null !== $depth) {
            $this->addCommandArgument('--depth=' . $depth);
            // shallow-submodules is a nice to have feature. Just ignoring if git version not high enough
            // It would be nice if this had a logger injected for us to log notices
            if (version_compare($v, '2.9.0', '>=') && $recursive && 1 == $depth) {
                $this->addCommandArgument('--shallow-submodules');
            }
        }

        if ($recursive) {
            $this->addCommandArgument('--recursive');
        }

        return $this->getCommand();
    }
public function cloneUrl ( string $ url , string $ to = null , string $ repoReference = null , int $ depth = null , bool $ recursive = false ) { // get binary version before reset $ v = $ this -> getBinaryVersion ( ) ; $ this -> clearAll ( ) ; $ this -> addCommandName ( static :: GIT_CLONE_COMMAND ) ; $ this -> addCommandSubject ( $ url ) ; if ( null !== $ to ) { $ this -> addCommandSubject2 ( $ to ) ; } if ( null !== $ repoReference ) { // git documentation says the --branch was added in 2.0.0, but it exists undocumented at least back to 1.8.3.1 if ( version_compare ( $ v , '1.8.3.1' , '<' ) ) { throw new \ RuntimeException ( 'Please upgrade to git v1.8.3.1 or newer to support cloning a specific branch. You have ' . $ v . '.' ) ; } $ this -> addCommandArgument ( '--branch=' . $ repoReference ) ; } if ( null !== $ depth ) { $ this -> addCommandArgument ( '--depth=' . $ depth ) ; // shallow-submodules is a nice to have feature. Just ignoring if git version not high enough // It would be nice if this had a logger injected for us to log notices if ( version_compare ( $ v , '2.9.0' , '>=' ) && $ recursive && 1 == $ depth ) { $ this -> addCommandArgument ( '--shallow-submodules' ) ; } } if ( $ recursive ) { $ this -> addCommandArgument ( '--recursive' ) ; } return $ this -> getCommand ( ) ; }
Command to clone a repository

@param string      $url           repository url
@param string      $to            where to clone the repo
@param string|null $repoReference Repo reference to clone. Required if performing a shallow clone.
@param int|null    $depth         Depth of commits to clone
@param bool        $recursive     Whether to recursively clone submodules.

@throws \RuntimeException
@return string command
Command to clone a repository