@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Default "Land Revision" dialog to land into the default branch for the repository

Summary:
Ref T9952. Default the branch target in the dialog to be whatever branch is the default branch for the repository.

This will be correct for repositories like ours (which land everything into `master`) and correct most of the time for repositories which have some other "primary" branch (maybe `development`).

It won't be great if there are multiple open lines of development in a repository (for example, some changes go to `newdesignpro` and some changes go to `legacy-1.2`). I'll do work in T3462 next to improve those cases so we can pick a better default.

Test Plan:
- Saw dialog default to "master".
- Changed repo default branch, saw it default to "notmaster" instead.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9952

Differential Revision: https://secure.phabricator.com/D14734

+43 -9
+43 -9
src/applications/differential/controller/DifferentialRevisionOperationController.php
··· 30 30 $diff = $revision->getActiveDiff(); 31 31 $repository = $revision->getRepository(); 32 32 33 - $ref_types = array( 34 - PhabricatorRepositoryRefCursor::TYPE_BRANCH, 35 - ); 33 + $default_ref = $this->loadDefaultRef($repository); 34 + 35 + if ($default_ref) { 36 + $v_ref = array($default_ref->getPHID()); 37 + } else { 38 + $v_ref = array(); 39 + } 36 40 37 41 $e_ref = true; 38 42 39 43 $errors = array(); 40 44 if ($request->isFormPost()) { 41 45 42 - $ref_phid = head($request->getArr('refPHIDs')); 46 + $v_ref = $request->getArr('refPHIDs'); 47 + $ref_phid = head($v_ref); 43 48 if (!strlen($ref_phid)) { 44 49 $e_ref = pht('Required'); 45 50 $errors[] = pht( 46 51 'You must select a branch to land this revision onto.'); 47 52 } else { 48 - $ref = id(new PhabricatorRepositoryRefCursorQuery()) 49 - ->setViewer($viewer) 53 + $ref = $this->newRefQuery($repository) 50 54 ->withPHIDs(array($ref_phid)) 51 - ->withRepositoryPHIDs(array($repository->getPHID())) 52 - ->withRefTypes($ref_types) 53 55 ->executeOne(); 54 56 if (!$ref) { 55 57 $e_ref = pht('Invalid'); ··· 85 87 ->setParameters( 86 88 array( 87 89 'repositoryPHIDs' => array($repository->getPHID()), 88 - 'refTypes' => $ref_types, 90 + 'refTypes' => $this->getTargetableRefTypes(), 89 91 )); 90 92 91 93 $form = id(new AphrontFormView()) ··· 100 102 ->setName('refPHIDs') 101 103 ->setLimit(1) 102 104 ->setError($e_ref) 105 + ->setValue($v_ref) 103 106 ->setDatasource($ref_datasource)) 104 107 ->appendRemarkupInstructions( 105 108 pht( ··· 113 116 ->appendForm($form) 114 117 ->addCancelButton($detail_uri) 115 118 ->addSubmitButton(pht('Mutate Repository Unpredictably')); 119 + } 120 + 121 + private function newRefQuery(PhabricatorRepository $repository) { 122 + $viewer = $this->getViewer(); 123 + 124 + return id(new PhabricatorRepositoryRefCursorQuery()) 125 + ->setViewer($viewer) 126 + ->withRepositoryPHIDs(array($repository->getPHID())) 127 + ->withRefTypes($this->getTargetableRefTypes()); 128 + } 129 + 130 + private function getTargetableRefTypes() { 131 + return array( 132 + PhabricatorRepositoryRefCursor::TYPE_BRANCH, 133 + ); 134 + } 135 + 136 + private function loadDefaultRef(PhabricatorRepository $repository) { 137 + $default_name = $this->getDefaultRefName($repository); 138 + 139 + if (!strlen($default_name)) { 140 + return null; 141 + } 142 + 143 + return $this->newRefQuery($repository) 144 + ->withRefNames(array($default_name)) 145 + ->executeOne(); 146 + } 147 + 148 + private function getDefaultRefName(PhabricatorRepository $repository) { 149 + return $repository->getDefaultBranch(); 116 150 } 117 151 118 152 }