mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 07:12:41 +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:
parent
a89cef8e39
commit
3a1ee00335
4 changed files with 17 additions and 14 deletions
|
@ -83,7 +83,7 @@ final class DiffusionGitRequest extends DiffusionRequest {
|
|||
return $this->branch;
|
||||
}
|
||||
if ($this->repository) {
|
||||
return $this->repository->getDetail('default-branch', 'master');
|
||||
return $this->repository->getDefaultBranch();
|
||||
}
|
||||
throw new Exception("Unable to determine branch!");
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ final class DiffusionMercurialRequest extends DiffusionRequest {
|
|||
}
|
||||
|
||||
if ($this->repository) {
|
||||
return $this->repository->getDetail('default-branch', 'default');
|
||||
return $this->repository->getDefaultBranch();
|
||||
}
|
||||
|
||||
throw new Exception("Unable to determine branch!");
|
||||
|
|
|
@ -588,23 +588,12 @@ final class PhabricatorRepositoryEditController
|
|||
$inset->setTitle('Application Configuration');
|
||||
|
||||
if ($has_branches) {
|
||||
|
||||
$default_branch_name = null;
|
||||
if ($is_mercurial) {
|
||||
$default_branch_name = 'default';
|
||||
} else if ($is_git) {
|
||||
$default_branch_name = 'master';
|
||||
}
|
||||
|
||||
$inset
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setName('default-branch')
|
||||
->setLabel('Default Branch')
|
||||
->setValue(
|
||||
$repository->getDetail(
|
||||
'default-branch',
|
||||
$default_branch_name))
|
||||
->setValue($repository->getDefaultBranch())
|
||||
->setError($e_branch)
|
||||
->setCaption(
|
||||
'Default branch to show in Diffusion.'));
|
||||
|
|
|
@ -347,6 +347,20 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO {
|
|||
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) {
|
||||
$vcs = $this->getVersionControlSystem();
|
||||
|
||||
|
|
Loading…
Reference in a new issue