2013-10-25 22:57:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionRepositoryEditBranchesController
|
2013-10-26 00:58:58 +02:00
|
|
|
extends DiffusionRepositoryEditController {
|
2013-10-25 22:57:14 +02:00
|
|
|
|
2016-01-05 17:49:10 +01:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$response = $this->loadDiffusionContextForEdit();
|
|
|
|
if ($response) {
|
|
|
|
return $response;
|
2013-10-25 22:57:14 +02:00
|
|
|
}
|
|
|
|
|
2016-01-05 17:49:10 +01:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
|
2013-11-12 01:26:58 +01:00
|
|
|
$is_git = false;
|
|
|
|
$is_hg = false;
|
|
|
|
|
2013-10-25 22:57:14 +02:00
|
|
|
switch ($repository->getVersionControlSystem()) {
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
2013-11-12 01:26:58 +01:00
|
|
|
$is_git = true;
|
|
|
|
break;
|
2013-10-25 22:57:14 +02:00
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
2013-11-12 01:26:58 +01:00
|
|
|
$is_hg = true;
|
2013-10-25 22:57:14 +02:00
|
|
|
break;
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
|
|
|
throw new Exception(
|
|
|
|
pht('Subversion does not support branches!'));
|
|
|
|
default:
|
|
|
|
throw new Exception(
|
|
|
|
pht('Repository has unknown version control system!'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
|
|
|
|
|
|
|
|
$v_default = $repository->getHumanReadableDetail('default-branch');
|
2014-08-26 22:28:55 +02:00
|
|
|
$v_track = $repository->getDetail(
|
2013-10-27 05:08:24 +01:00
|
|
|
'branch-filter',
|
|
|
|
array());
|
2014-08-26 22:28:55 +02:00
|
|
|
$v_track = array_keys($v_track);
|
|
|
|
$v_autoclose = $repository->getDetail(
|
2013-10-27 05:08:24 +01:00
|
|
|
'close-commits-filter',
|
|
|
|
array());
|
2014-08-26 22:28:55 +02:00
|
|
|
$v_autoclose = array_keys($v_autoclose);
|
2013-10-25 22:57:14 +02:00
|
|
|
|
2014-08-26 22:28:55 +02:00
|
|
|
$e_track = null;
|
|
|
|
$e_autoclose = null;
|
|
|
|
|
|
|
|
$validation_exception = null;
|
2013-10-25 22:57:14 +02:00
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$v_default = $request->getStr('default');
|
2014-08-26 22:28:55 +02:00
|
|
|
|
|
|
|
$v_track = $this->processBranches($request->getStr('track'));
|
|
|
|
if (!$is_hg) {
|
|
|
|
$v_autoclose = $this->processBranches($request->getStr('autoclose'));
|
|
|
|
}
|
2013-10-25 22:57:14 +02:00
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
$template = id(new PhabricatorRepositoryTransaction());
|
|
|
|
|
|
|
|
$type_default = PhabricatorRepositoryTransaction::TYPE_DEFAULT_BRANCH;
|
|
|
|
$type_track = PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY;
|
|
|
|
$type_autoclose = PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY;
|
|
|
|
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_default)
|
|
|
|
->setNewValue($v_default);
|
|
|
|
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_track)
|
|
|
|
->setNewValue($v_track);
|
|
|
|
|
2013-11-12 01:26:58 +01:00
|
|
|
if (!$is_hg) {
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_autoclose)
|
|
|
|
->setNewValue($v_autoclose);
|
|
|
|
}
|
2013-10-25 22:57:14 +02:00
|
|
|
|
2014-08-26 22:28:55 +02:00
|
|
|
$editor = id(new PhabricatorRepositoryEditor())
|
2013-10-25 22:57:14 +02:00
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
2014-08-26 22:28:55 +02:00
|
|
|
->setActor($viewer);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$editor->applyTransactions($repository, $xactions);
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($edit_uri);
|
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
2013-10-25 22:57:14 +02:00
|
|
|
|
2014-08-26 22:28:55 +02:00
|
|
|
$e_track = $validation_exception->getShortMessage($type_track);
|
|
|
|
$e_autoclose = $validation_exception->getShortMessage($type_autoclose);
|
|
|
|
}
|
2013-10-25 22:57:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$content = array();
|
|
|
|
|
2013-10-26 00:58:58 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Edit Branches'));
|
2013-10-25 22:57:14 +02:00
|
|
|
|
|
|
|
$title = pht('Edit Branches (%s)', $repository->getName());
|
2016-03-17 20:01:22 +01:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($title)
|
|
|
|
->setHeaderIcon('fa-pencil');
|
2013-10-25 22:57:14 +02:00
|
|
|
|
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setObject($repository)
|
|
|
|
->execute();
|
|
|
|
|
2014-08-26 22:28:55 +02:00
|
|
|
$rows = array();
|
|
|
|
$rows[] = array(
|
|
|
|
array(
|
|
|
|
'master',
|
|
|
|
),
|
|
|
|
pht('Select only master.'),
|
|
|
|
);
|
|
|
|
$rows[] = array(
|
|
|
|
array(
|
|
|
|
'master',
|
|
|
|
'develop',
|
|
|
|
'release',
|
|
|
|
),
|
2015-05-22 09:27:56 +02:00
|
|
|
pht('Select %s, %s, and %s.', 'master', 'develop', 'release'),
|
2014-08-26 22:28:55 +02:00
|
|
|
);
|
|
|
|
$rows[] = array(
|
|
|
|
array(
|
|
|
|
'master',
|
|
|
|
'regexp(/^release-/)',
|
|
|
|
),
|
2015-05-22 09:27:56 +02:00
|
|
|
pht('Select master, and all branches which start with "%s".', 'release-'),
|
2014-08-26 22:28:55 +02:00
|
|
|
);
|
|
|
|
$rows[] = array(
|
|
|
|
array(
|
|
|
|
'regexp(/^(?!temp-)/)',
|
|
|
|
),
|
2015-05-22 09:27:56 +02:00
|
|
|
pht('Select all branches which do not start with "%s".', 'temp-'),
|
2014-08-26 22:28:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($rows as $k => $row) {
|
|
|
|
$rows[$k][0] = phutil_tag(
|
|
|
|
'pre',
|
|
|
|
array(),
|
|
|
|
implode("\n", $row[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
$example_table = id(new AphrontTableView($rows))
|
|
|
|
->setHeaders(
|
|
|
|
array(
|
|
|
|
pht('Example'),
|
|
|
|
pht('Effect'),
|
|
|
|
))
|
|
|
|
->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'',
|
|
|
|
'wide',
|
|
|
|
));
|
|
|
|
|
|
|
|
$v_track = implode("\n", $v_track);
|
|
|
|
$v_autoclose = implode("\n", $v_autoclose);
|
|
|
|
|
2013-10-25 22:57:14 +02:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->appendRemarkupInstructions(
|
2015-05-22 09:27:56 +02:00
|
|
|
pht('You can choose a **Default Branch** for viewing this repository.'))
|
2013-10-25 22:57:14 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('default')
|
|
|
|
->setLabel(pht('Default Branch'))
|
2014-08-26 22:28:55 +02:00
|
|
|
->setValue($v_default))
|
|
|
|
->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'If you want to import only some branches into Diffusion, you can '.
|
|
|
|
'list them in **Track Only**. Other branches will be ignored. If '.
|
|
|
|
'you do not specify any branches, all branches are tracked.'));
|
|
|
|
|
|
|
|
if (!$is_hg) {
|
|
|
|
$form->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'If you have **Autoclose** enabled for this repository, Phabricator '.
|
|
|
|
'can close tasks and revisions when corresponding commits are '.
|
|
|
|
'pushed to the repository. If you want to autoclose objects only '.
|
|
|
|
'when commits appear on specific branches, you can list those '.
|
|
|
|
'branches in **Autoclose Only**. By default, all tracked branches '.
|
|
|
|
'will autoclose objects.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'When specifying branches, you should enter one branch name per '.
|
|
|
|
'line. You can use regular expressions to match branches by '.
|
2015-05-22 09:27:56 +02:00
|
|
|
'wrapping an expression in `%s`. For example:',
|
|
|
|
'regexp(...)'))
|
2013-10-25 22:57:14 +02:00
|
|
|
->appendChild(
|
2014-08-26 22:28:55 +02:00
|
|
|
id(new AphrontFormMarkupControl())
|
|
|
|
->setValue($example_table))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
2013-10-25 22:57:14 +02:00
|
|
|
->setName('track')
|
|
|
|
->setLabel(pht('Track Only'))
|
2014-08-26 22:28:55 +02:00
|
|
|
->setError($e_track)
|
|
|
|
->setValue($v_track));
|
2013-11-12 01:26:58 +01:00
|
|
|
|
|
|
|
if (!$is_hg) {
|
|
|
|
$form->appendChild(
|
2014-08-26 22:28:55 +02:00
|
|
|
id(new AphrontFormTextAreaControl())
|
2013-10-25 22:57:14 +02:00
|
|
|
->setName('autoclose')
|
|
|
|
->setLabel(pht('Autoclose Only'))
|
2014-08-26 22:28:55 +02:00
|
|
|
->setError($e_autoclose)
|
|
|
|
->setValue($v_autoclose));
|
2013-11-12 01:26:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Save Branches'))
|
|
|
|
->addCancelButton($edit_uri));
|
2013-10-25 22:57:14 +02:00
|
|
|
|
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2016-03-17 20:01:22 +01:00
|
|
|
->setHeaderText(pht('Branches'))
|
2014-08-26 22:28:55 +02:00
|
|
|
->setValidationException($validation_exception)
|
2016-03-17 20:01:22 +01:00
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
2013-10-25 22:57:14 +02:00
|
|
|
->setForm($form);
|
|
|
|
|
2016-03-17 20:01:22 +01:00
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setFooter(array(
|
|
|
|
$form_box,
|
|
|
|
));
|
|
|
|
|
2016-01-05 17:49:10 +01:00
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
2016-03-17 20:01:22 +01:00
|
|
|
->appendChild($view);
|
2013-10-25 22:57:14 +02:00
|
|
|
}
|
|
|
|
|
2014-08-26 22:28:55 +02:00
|
|
|
private function processBranches($string) {
|
|
|
|
$lines = phutil_split_lines($string, $retain_endings = false);
|
|
|
|
foreach ($lines as $key => $line) {
|
|
|
|
$lines[$key] = trim($line);
|
|
|
|
if (!strlen($lines[$key])) {
|
|
|
|
unset($lines[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_values($lines);
|
|
|
|
}
|
|
|
|
|
2013-10-25 22:57:14 +02:00
|
|
|
}
|