Example #1
0
File: GitRepo.php Project: coyl/git
 /**
  * Create a new git repository
  *
  * Accepts a creation path, and, optionally, a source path
  *
  * @access public
  * @param string $repoPath repository path
  * @param string $source directory to source
  * @param bool $remoteSource reference path
  * @param string|null $reference
  * @throws \Exception
  * @return GitRepo
  */
 public static function create($repoPath, $source = null, $remoteSource = false, $reference = null, $commandString = "")
 {
     if (is_dir($repoPath) && file_exists($repoPath . "/.git") && is_dir($repoPath . "/.git")) {
         throw new GitException(sprintf('"%s" is already a git repository', $repoPath));
     } else {
         $repo = new self($repoPath, true, false);
         if (is_string($source)) {
             if ($remoteSource) {
                 if (!is_dir($reference) || !is_dir($reference . '/.git')) {
                     throw new GitException('"' . $reference . '" is not a git repository. Cannot use as reference.');
                 } else {
                     if (strlen($reference)) {
                         $reference = realpath($reference);
                         $reference = "--reference {$reference}";
                     }
                 }
                 $repo->cloneRemote($source, $reference);
             } else {
                 $repo->cloneFrom($source, $commandString);
             }
         } else {
             $repo->run('create');
         }
         return $repo;
     }
 }