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
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
$drequest = $this->diffusionRequest;
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
|
|
|
|
$repository = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->withIDs(array($repository->getID()))
|
|
|
|
->executeOne();
|
|
|
|
if (!$repository) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
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');
|
2013-10-27 05:08:24 +01:00
|
|
|
$v_track = $repository->getHumanReadableDetail(
|
|
|
|
'branch-filter',
|
|
|
|
array());
|
|
|
|
$v_autoclose = $repository->getHumanReadableDetail(
|
|
|
|
'close-commits-filter',
|
|
|
|
array());
|
2013-10-25 22:57:14 +02:00
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$v_default = $request->getStr('default');
|
|
|
|
$v_track = $request->getStrList('track');
|
|
|
|
$v_autoclose = $request->getStrList('autoclose');
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
id(new PhabricatorRepositoryEditor())
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setActor($viewer)
|
|
|
|
->applyTransactions($repository, $xactions);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($edit_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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());
|
|
|
|
|
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setObject($repository)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'You can choose a **Default Branch** for viewing this repository.'.
|
|
|
|
"\n\n".
|
|
|
|
'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.'.
|
|
|
|
"\n\n".
|
|
|
|
'If you have **Autoclose** enabled, 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 branches autoclose objects.'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('default')
|
|
|
|
->setLabel(pht('Default Branch'))
|
|
|
|
->setValue($v_default)
|
|
|
|
->setCaption(
|
|
|
|
pht('Example: %s', phutil_tag('tt', array(), 'develop'))))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('track')
|
|
|
|
->setLabel(pht('Track Only'))
|
|
|
|
->setValue($v_track)
|
|
|
|
->setCaption(
|
2013-11-12 01:26:58 +01:00
|
|
|
pht('Example: %s', phutil_tag('tt', array(), 'master, develop'))));
|
|
|
|
|
|
|
|
if (!$is_hg) {
|
|
|
|
$form->appendChild(
|
2013-10-25 22:57:14 +02:00
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('autoclose')
|
|
|
|
->setLabel(pht('Autoclose Only'))
|
|
|
|
->setValue($v_autoclose)
|
|
|
|
->setCaption(
|
2013-11-12 01:26:58 +01:00
|
|
|
pht('Example: %s', phutil_tag('tt', array(), 'master, release'))));
|
|
|
|
}
|
|
|
|
|
|
|
|
$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())
|
|
|
|
->setHeaderText($title)
|
|
|
|
->setForm($form);
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$form_box,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|