diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index 8fa6b30095..324d03a9cc 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -167,6 +167,7 @@ class gitlab $params['per_page'] = '100'; $branches = array(); + $default = array(); for($page = 1; true; $page ++) { $params['page'] = $page; @@ -176,15 +177,24 @@ class gitlab foreach($branchList as $branch) { if(!isset($branch->name)) continue; - $branches[$branch->name] = $branch->name; + if($branch->default) + { + $default[$branch->name] = $branch->name; + } + else + { + $branches[$branch->name] = $branch->name; + } } /* Last page. */ if(count($branchList) < $params['per_page']) break; } - if(empty($branches)) $branches['master'] = 'master'; + if(empty($branches) and empty($default)) $branches['master'] = 'master'; asort($branches); + + $branches = $default + $branches; return $branches; } diff --git a/lib/scm/gitrepo.class.php b/lib/scm/gitrepo.class.php index 50e48a60cc..93261cdcac 100644 --- a/lib/scm/gitrepo.class.php +++ b/lib/scm/gitrepo.class.php @@ -125,6 +125,9 @@ class GitRepo $list = execCmd($cmd . ' 2>&1', 'array', $result); if($result) return array(); + /* Get default branch. */ + $defaultBranch = execCmd("$this->client symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'"); + $branches = array(); foreach($list as $localBranch) { @@ -132,9 +135,12 @@ class GitRepo $localBranch = trim($localBranch); if(empty($localBranch))continue; - $branches[$localBranch] = $localBranch; + if($localBranch != $defaultBranch) $branches[$localBranch] = $localBranch; } + asort($branches); + $branches = array($defaultBranch => $defaultBranch) + $branches; + return $branches; } @@ -552,8 +558,10 @@ class GitRepo else { $file = explode(' ', $commit); - $file = end($file); - list($action, $path) = explode("\t", $file); + $file = explode("\t", end($file)); + if(!isset($file[1])) $file[1] = ''; + list($action, $path) = $file; + $parsedFile = new stdclass(); $parsedFile->revision = $hash; $parsedFile->path = '/' . trim($path);