コード例 #1
0
ファイル: Controller.php プロジェクト: gitaminhq/gitamin
 /**
  * Returns an Array where the first value is the tree-ish and the second is the path.
  *
  * @param \GitList\Git\Repository $repository
  * @param string                  $branch
  * @param string                  $tree
  *
  * @return array
  */
 protected function parseBranchTreeParam($repository, $branch = '', $tree = '')
 {
     $branch = trim($branch, '/');
     $tree = trim($tree, '/');
     $input = $branch . '/' . $tree;
     // If the ref appears to be a SHA, just split the string
     if (preg_match('/^([[:alnum:]]{40})(.+)/', $input, $matches)) {
         $branch = $matches[1];
     } else {
         // Otherwise, attempt to detect the ref using a list of the project's branches and tags
         $validRefs = array_merge((array) $repository->getBranches(), (array) $repository->getTags());
         foreach ($validRefs as $key => $ref) {
             if (!preg_match(sprintf('#^%s/#', preg_quote($ref, '#')), $input)) {
                 unset($validRefs[$key]);
             }
         }
         // No exact ref match, so just try our best
         if (count($validRefs) > 1) {
             preg_match('/([^\\/]+)(.*)/', $input, $matches);
             $branch = preg_replace('/^\\/|\\/$/', '', $matches[1]);
         } else {
             // Extract branch name
             $branch = array_shift($validRefs);
         }
     }
     return [$branch, $tree];
 }
コード例 #2
0
ファイル: Client.php プロジェクト: npotier/gitlist
 /**
  * Creates a new repository on the specified path
  *
  * @param  string     $path Path where the new repository will be created
  * @return Repository Instance of Repository
  */
 public function createRepository($path, $bare = null)
 {
     if (file_exists($path . '/.git/HEAD') && !file_exists($path . '/HEAD')) {
         throw new \RuntimeException('A GIT repository already exists at ' . $path);
     }
     $repository = new Repository($path, $this);
     return $repository->create($bare);
 }
コード例 #3
0
ファイル: Repository.php プロジェクト: npotier/gitlist
 /**
  * Returns an Array where the first value is the tree-ish and the second is the path
  *
  * @param  \GitList\Git\Repository $repository
  * @param  string                  $branch
  * @param  string                  $tree
  * @return array
  */
 public function extractRef($repository, $branch = '', $tree = '')
 {
     $branch = trim($branch, '/');
     $tree = trim($tree, '/');
     $input = $branch . '/' . $tree;
     // If the ref appears to be a SHA, just split the string
     if (preg_match("/^([[:alnum:]]{40})(.+)/", $input, $matches)) {
         $branch = $matches[1];
     } else {
         // Otherwise, attempt to detect the ref using a list of the project's branches and tags
         $valid_refs = array_merge((array) $repository->getBranches(), (array) $repository->getTags());
         foreach ($valid_refs as $k => $v) {
             if (!preg_match("#{$v}/#", $input)) {
                 unset($valid_refs[$k]);
             }
         }
         // No exact ref match, so just try our best
         if (count($valid_refs) > 1) {
             preg_match('/([^\\/]+)(.*)/', $input, $matches);
             $branch = preg_replace('/^\\/|\\/$/', '', $matches[0]);
         } else {
             // Extract branch name
             $branch = array_shift($valid_refs);
         }
     }
     $tree = trim(str_replace($branch, "", $input), "/");
     return array($branch, $tree);
 }