Exemple #1
0
 /**
  * Clone a repository (clone is a reserved keyword).
  *
  * @param string $path
  * @param string $remote_url
  * @param null $repo
  * @param \Shell\Output\ProcessOutputInterface $output
  * @param bool $background
  * @return GitRepository|Process
  * @throws GitException
  */
 public static function copy($path, $remote_url, &$repo = null, $output = null, $background = false)
 {
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($path)) {
         throw new InvalidArgumentException('Path must be absolute.');
     }
     $fs->mkdir($path);
     $git = new Git($path);
     $repo = new GitRepository($git, $output);
     $args = [$remote_url, $path];
     if ($background) {
         $onSuccess = function () use(&$repo) {
             $repo->processGitConfig();
             $repo->setUpstream();
             $repo->initialized = true;
         };
         return $git->execNonBlocking('clone', $args, [], [], $onSuccess);
     } else {
         $git->exec('clone', $args, ['--verbose' => true]);
         $repo->processGitConfig();
         $repo->setUpstream();
         $repo->initialized = true;
         return $repo;
     }
 }
Exemple #2
0
 /**
  * Clone a repository (clone is a reserved keyword).
  *
  * @param string $project_dir
  * @param string $remote_url
  * @param null $repo
  * @param bool $background
  * @return GitRepository|Process
  * @throws GitException
  */
 public static function copy($project_dir, $remote_url, &$repo = null, $background = false)
 {
     $fs = new Filesystem();
     $fs->mkdir($project_dir);
     $git = new Git($project_dir);
     $repo = new GitRepository($git);
     $args = [$remote_url, $project_dir];
     if ($background) {
         $onSuccess = function () use(&$repo) {
             $repo->processGitConfig();
             $repo->setUpstream();
             $repo->initialized = true;
         };
         return $git->execNonBlocking('clone', $args, [], [], $onSuccess);
     } else {
         $git->exec('clone', $args);
         $repo->processGitConfig();
         $repo->setUpstream();
         $repo->initialized = true;
         return $repo;
     }
 }