From 3a1ee003359e8d4d9e31e263afa5aac750751756 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 20 May 2012 14:50:43 -0700 Subject: [PATCH] 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 --- .../diffusion/request/git/DiffusionGitRequest.php | 2 +- .../mercurial/DiffusionMercurialRequest.php | 2 +- .../edit/PhabricatorRepositoryEditController.php | 13 +------------ .../storage/repository/PhabricatorRepository.php | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/applications/diffusion/request/git/DiffusionGitRequest.php b/src/applications/diffusion/request/git/DiffusionGitRequest.php index d59b77b4c8..d27a972c66 100644 --- a/src/applications/diffusion/request/git/DiffusionGitRequest.php +++ b/src/applications/diffusion/request/git/DiffusionGitRequest.php @@ -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!"); } diff --git a/src/applications/diffusion/request/mercurial/DiffusionMercurialRequest.php b/src/applications/diffusion/request/mercurial/DiffusionMercurialRequest.php index 53b54088f7..99d6baf720 100644 --- a/src/applications/diffusion/request/mercurial/DiffusionMercurialRequest.php +++ b/src/applications/diffusion/request/mercurial/DiffusionMercurialRequest.php @@ -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!"); diff --git a/src/applications/repository/controller/edit/PhabricatorRepositoryEditController.php b/src/applications/repository/controller/edit/PhabricatorRepositoryEditController.php index a498eca592..94e48e83b8 100644 --- a/src/applications/repository/controller/edit/PhabricatorRepositoryEditController.php +++ b/src/applications/repository/controller/edit/PhabricatorRepositoryEditController.php @@ -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.')); diff --git a/src/applications/repository/storage/repository/PhabricatorRepository.php b/src/applications/repository/storage/repository/PhabricatorRepository.php index 0776c819f4..d52ce559b9 100644 --- a/src/applications/repository/storage/repository/PhabricatorRepository.php +++ b/src/applications/repository/storage/repository/PhabricatorRepository.php @@ -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();