1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Select default branches more effectively in Diffusion

Summary: If you have an empty value saved in the "default branch" field, we default to empty string (or null, or whatever) instead of the correct default.

Test Plan:
  - Looked at a Git repo with an empty default branch, got a default to "master" instead of an error.
  - Looked at a Mercurial repo with an empty default branch, got a default to "default" instead of an error.

Reviewers: btrahan, csilvers

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1237

Differential Revision: https://secure.phabricator.com/D2512
This commit is contained in:
epriestley 2012-05-20 14:50:43 -07:00
parent a89cef8e39
commit 3a1ee00335
4 changed files with 17 additions and 14 deletions

View file

@ -83,7 +83,7 @@ final class DiffusionGitRequest extends DiffusionRequest {
return $this->branch; return $this->branch;
} }
if ($this->repository) { if ($this->repository) {
return $this->repository->getDetail('default-branch', 'master'); return $this->repository->getDefaultBranch();
} }
throw new Exception("Unable to determine branch!"); throw new Exception("Unable to determine branch!");
} }

View file

@ -41,7 +41,7 @@ final class DiffusionMercurialRequest extends DiffusionRequest {
} }
if ($this->repository) { if ($this->repository) {
return $this->repository->getDetail('default-branch', 'default'); return $this->repository->getDefaultBranch();
} }
throw new Exception("Unable to determine branch!"); throw new Exception("Unable to determine branch!");

View file

@ -588,23 +588,12 @@ final class PhabricatorRepositoryEditController
$inset->setTitle('Application Configuration'); $inset->setTitle('Application Configuration');
if ($has_branches) { if ($has_branches) {
$default_branch_name = null;
if ($is_mercurial) {
$default_branch_name = 'default';
} else if ($is_git) {
$default_branch_name = 'master';
}
$inset $inset
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('default-branch') ->setName('default-branch')
->setLabel('Default Branch') ->setLabel('Default Branch')
->setValue( ->setValue($repository->getDefaultBranch())
$repository->getDetail(
'default-branch',
$default_branch_name))
->setError($e_branch) ->setError($e_branch)
->setCaption( ->setCaption(
'Default branch to show in Diffusion.')); 'Default branch to show in Diffusion.'));

View file

@ -347,6 +347,20 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO {
return $this->getDetail('tracking-enabled', false); return $this->getDetail('tracking-enabled', false);
} }
public function getDefaultBranch() {
$default = $this->getDetail('default-branch');
if (strlen($default)) {
return $default;
}
$default_branches = array(
PhabricatorRepositoryType::REPOSITORY_TYPE_GIT => 'master',
PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL => 'default',
);
return idx($default_branches, $this->getVersionControlSystem());
}
public function shouldTrackBranch($branch) { public function shouldTrackBranch($branch) {
$vcs = $this->getVersionControlSystem(); $vcs = $this->getVersionControlSystem();