상속: extends TQ\Vcs\Cli\Binary
예제 #1
0
 public function testFailedCall()
 {
     $binary = new Binary(GIT_BINARY);
     $call = $binary->createGitCall('/', 'unknowncommand', array());
     $result = $call->execute();
     $this->assertFalse($result->hasStdOut());
     $this->assertTrue($result->hasStdErr());
     $this->assertEmpty($result->getStdOut());
     $this->assertNotEmpty($result->getStdErr());
     $this->assertGreaterThan(0, $result->getReturnCode());
 }
예제 #2
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);
 }
예제 #4
0
 public function testFileModeSwitchWithFileArgument()
 {
     $binary = new Binary('/usr/bin/git');
     $call = $binary->createGitCall('/', 'command', array('option', '/path/to/file', '--', 'path/to/file'));
     $this->assertCliCommandEquals("/usr/bin/git 'command' 'option' '/path/to/file' -- 'path/to/file'", $call->getCmd());
 }
예제 #5
0
 /**
  * Inits a path to be used as a Git repository
  *
  * @param   Binary   $binary        The Git binary
  * @param   string   $path          The repository path
  */
 protected static function initRepository(Binary $binary, $path)
 {
     $result = $binary->init($path);
     self::throwIfError($result, sprintf('Cannot initialize a Git repository in "%s"', $path));
 }
 /**
  * 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);
 }