public static function open($repositoryPath, $git = null, $createIfNotExists = false, $initArguments = null, $findRepositoryRoot = true)
    {
        $git = Binary::ensure($git);
        $repositoryRoot = null;

        if (!is_string($repositoryPath)) {
            throw new \InvalidArgumentException(sprintf(
                '"%s" is not a valid path', $repositoryPath
            ));
        }

        if ($findRepositoryRoot) {
            $repositoryRoot = self::findRepositoryRoot($repositoryPath);
        }

        if ($repositoryRoot === null) {
            if (!$createIfNotExists) {
                throw new \InvalidArgumentException(sprintf(
                    '"%s" is not a valid path', $repositoryPath
                ));
            } else {
                if (!file_exists($repositoryPath) && !mkdir($repositoryPath, $createIfNotExists, true)) {
                    throw new \RuntimeException(sprintf(
                        '"%s" cannot be created', $repositoryPath
                    ));
                } else if (!is_dir($repositoryPath)) {
                    throw new \InvalidArgumentException(sprintf(
                        '"%s" is not a valid path', $repositoryPath
                    ));
                }
                self::initRepository($git, $repositoryPath, $initArguments);
                $repositoryRoot = $repositoryPath;
            }
        }

        if ($repositoryRoot === null) {
            throw new \InvalidArgumentException(sprintf(
                '"%s" is not a valid Git repository', $repositoryPath
            ));
        }

        return new static($repositoryRoot, $git);
    }
public static function open($repositoryPath, $git = null, $createIfNotExists = false, $initArguments = null, $findRepositoryRoot = true)
    {
        $git = Binary::ensure($git);
        $repositoryRoot = null;

        if (!is_string($repositoryPath)) {
            throw new \InvalidArgumentException(sprintf(
                '"%s" is not a valid path', $repositoryPath
            ));
        }

        if ($findRepositoryRoot) {
            $repositoryRoot = self::findRepositoryRoot($repositoryPath);
        }

        if ($repositoryRoot === null) {
            if (!$createIfNotExists) {
                throw new \InvalidArgumentException(sprintf(
                    '"%s" is not a valid path', $repositoryPath
                ));
            } else {
                if (!file_exists($repositoryPath) && !mkdir($repositoryPath, $createIfNotExists, true)) {
                    throw new \RuntimeException(sprintf(
                        '"%s" cannot be created', $repositoryPath
                    ));
                } else if (!is_dir($repositoryPath)) {
                    throw new \InvalidArgumentException(sprintf(
                        '"%s" is not a valid path', $repositoryPath
                    ));
                }
                self::initRepository($git, $repositoryPath, $initArguments);
                $repositoryRoot = $repositoryPath;
            }
        }

        if ($repositoryRoot === null) {
            throw new \InvalidArgumentException(sprintf(
                '"%s" is not a valid Git repository', $repositoryPath
            ));
        }

        return new static($repositoryRoot, $git);
    }
public static function open ( $ repositoryPath , $ git = null , $ createIfNotExists = false , $ initArguments = null , $ findRepositoryRoot = true ) { $ git = Binary :: ensure ( $ git ) ; $ repositoryRoot = null ; if ( ! is_string ( $ repositoryPath ) ) { throw new \ InvalidArgumentException ( sprintf ( '"%s" is not a valid path' , $ repositoryPath ) ) ; } if ( $ findRepositoryRoot ) { $ repositoryRoot = self :: findRepositoryRoot ( $ repositoryPath ) ; } if ( $ repositoryRoot === null ) { if ( ! $ createIfNotExists ) { throw new \ InvalidArgumentException ( sprintf ( '"%s" is not a valid path' , $ repositoryPath ) ) ; } else { if ( ! file_exists ( $ repositoryPath ) && ! mkdir ( $ repositoryPath , $ createIfNotExists , true ) ) { throw new \ RuntimeException ( sprintf ( '"%s" cannot be created' , $ repositoryPath ) ) ; } else if ( ! is_dir ( $ repositoryPath ) ) { throw new \ InvalidArgumentException ( sprintf ( '"%s" is not a valid path' , $ repositoryPath ) ) ; } self :: initRepository ( $ git , $ repositoryPath , $ initArguments ) ; $ repositoryRoot = $ repositoryPath ; } } if ( $ repositoryRoot === null ) { throw new \ InvalidArgumentException ( sprintf ( '"%s" is not a valid Git repository' , $ repositoryPath ) ) ; } return new static ( $ repositoryRoot , $ git ) ; }
Opens a Git repository on the file system, optionally creates and initializes a new repository

@param   string               $repositoryPath        The full path to the repository
@param   Binary|string|null   $git                   The Git binary
@param   boolean|integer      $createIfNotExists     False to fail on non-existing repositories, directory
creation mode, such as 0755  if the command
should create the directory and init the repository instead
@param   array|null           $initArguments         Arguments to be passed to git-init if initializing a
repository
@param   boolean              $findRepositoryRoot    False to use the repository path as the root directory.

@return  Repository
@throws  \RuntimeException                       If the path cannot be created
@throws  \InvalidArgumentException               If the path is not valid or if it's not a valid Git repository
Opens a Git repository on the file system optionally creates and initializes a new repository