예제 #1
0
 /**
  * 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
  * @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
  */
 public static function open($repositoryPath, $git = null, $createIfNotExists = false, $initArguments = null)
 {
     $git = Binary::ensure($git);
     if (!is_string($repositoryPath)) {
         throw new \InvalidArgumentException(sprintf('"%s" is not a valid path', $repositoryPath));
     }
     $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);
 }
 /**
  * Registers the stream wrapper with the given protocol
  *
  * @param   string                                   $protocol    The protocol (such as "git")
  * @param   Binary|string|null|PathFactoryInterface  $binary      The Git binary or a path factory
  * @throws  \RuntimeException                                     If $protocol is already registered
  */
 public static function register($protocol, $binary = null)
 {
     $bufferFactory = Factory::getDefault();
     if ($binary instanceof PathFactoryInterface) {
         $pathFactory = $binary;
     } else {
         $binary = Binary::ensure($binary);
         $pathFactory = new PathFactory($protocol, $binary, null);
     }
     parent::doRegister($protocol, $pathFactory, $bufferFactory);
 }
 /**
  * Creates a path factory
  *
  * @param   string              $protocol    The protocol (such as "git")
  * @param   Binary|string|null  $git         The Git binary
  * @param   RepositoryRegistry  $map         The repository registry
  */
 public function __construct($protocol, $git = null, RepositoryRegistry $map = null)
 {
     parent::__construct($protocol, $map);
     $this->git = Binary::ensure($git);
 }