1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Show a better message for empty repositories and invalid branches

Summary:
Ref T1493.

  - When viewing an invalid branch, show a "there is no such branch" message.
  - When viewing an empty repository, show a "this repository is empty" message.

Test Plan:
  - Viewed empty, bad branch, and nonempty in Git.
  - Viewed empty, bad branch, and nonempty in Mercurial.
  - Viewed empty and nonempty in Subversion.

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T1493

Differential Revision: https://secure.phabricator.com/D9912
This commit is contained in:
epriestley 2014-07-12 07:05:19 -07:00
parent 17badfacac
commit ae263ddde5
6 changed files with 98 additions and 14 deletions

View file

@ -7,6 +7,9 @@ final class DiffusionRepositoryController extends DiffusionController {
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
@ -16,7 +19,74 @@ final class DiffusionRepositoryController extends DiffusionController {
$content[] = $crumbs;
$content[] = $this->buildPropertiesTable($drequest->getRepository());
// Before we do any work, make sure we're looking at a some content: we're
// on a valid branch, and the repository is not empty.
$page_has_content = false;
$empty_title = null;
$empty_message = null;
// If this VCS supports branches, check that the selected branch actually
// exists.
if ($drequest->supportsBranches()) {
$ref_cursor = id(new PhabricatorRepositoryRefCursorQuery())
->setViewer($viewer)
->withRepositoryPHIDs(array($repository->getPHID()))
->withRefTypes(array(PhabricatorRepositoryRefCursor::TYPE_BRANCH))
->withRefNames(array($drequest->getBranch()))
->executeOne();
if ($ref_cursor) {
// This is a valid branch, so we necessarily have some content.
$page_has_content = true;
} else {
$empty_title = pht('No Such Branch');
$empty_message = pht(
'There is no branch named "%s" in this repository.',
$drequest->getBranch());
}
}
// If we didn't find any branches, check if there are any commits at all.
// This can tailor the message for empty repositories.
if (!$page_has_content) {
$any_commit = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepository($repository)
->setLimit(1)
->execute();
if ($any_commit) {
if (!$drequest->supportsBranches()) {
$page_has_content = true;
}
} else {
$empty_title = pht('Empty Repository');
$empty_message = pht(
'This repository does not have any commits yet.');
}
}
if ($page_has_content) {
$content[] = $this->buildNormalContent($drequest);
} else {
$content[] = id(new AphrontErrorView())
->setTitle($empty_title)
->setSeverity(AphrontErrorView::SEVERITY_WARNING)
->setErrors(array($empty_message));
}
return $this->buildApplicationPage(
$content,
array(
'title' => $drequest->getRepository()->getName(),
));
}
private function buildNormalContent(DiffusionRequest $drequest) {
$repository = $drequest->getRepository();
$phids = array();
$content = array();
try {
$history_results = $this->callConduitWithDiffusionRequest(
@ -133,11 +203,7 @@ final class DiffusionRepositoryController extends DiffusionController {
$content[] = $panel;
}
return $this->buildApplicationPage(
$content,
array(
'title' => $drequest->getRepository()->getName(),
));
return $content;
}
private function buildPropertiesTable(PhabricatorRepository $repository) {

View file

@ -2,7 +2,7 @@
final class DiffusionGitRequest extends DiffusionRequest {
protected function getSupportsBranches() {
public function supportsBranches() {
return true;
}

View file

@ -2,7 +2,7 @@
final class DiffusionMercurialRequest extends DiffusionRequest {
protected function getSupportsBranches() {
public function supportsBranches() {
return true;
}

View file

@ -28,7 +28,7 @@ abstract class DiffusionRequest {
private $user;
private $branchObject = false;
abstract protected function getSupportsBranches();
abstract public function supportsBranches();
abstract protected function isStableCommit($symbol);
protected function didInitialize() {
@ -98,7 +98,7 @@ abstract class DiffusionRequest {
$callsign = phutil_unescape_uri_path_component(idx($data, 'callsign'));
$object = self::newFromCallsign($callsign, $request->getUser());
$use_branches = $object->getSupportsBranches();
$use_branches = $object->supportsBranches();
$parsed = self::parseRequestBlob(idx($data, 'dblob'), $use_branches);
$object->setUser($request->getUser());
@ -188,7 +188,7 @@ abstract class DiffusionRequest {
$this->initFromConduit = idx($data, 'initFromConduit', true);
$this->symbolicCommit = idx($data, 'commit');
if ($this->getSupportsBranches()) {
if ($this->supportsBranches()) {
$this->branch = idx($data, 'branch');
}
@ -712,7 +712,7 @@ abstract class DiffusionRequest {
if ($this->symbolicCommit) {
$ref = $this->symbolicCommit;
} else {
if ($this->getSupportsBranches()) {
if ($this->supportsBranches()) {
$ref = $this->getResolvableBranchName($this->getBranch());
} else {
$ref = 'HEAD';

View file

@ -2,7 +2,7 @@
final class DiffusionSvnRequest extends DiffusionRequest {
protected function getSupportsBranches() {
public function supportsBranches() {
return false;
}

View file

@ -5,6 +5,7 @@ final class PhabricatorRepositoryRefCursorQuery
private $repositoryPHIDs;
private $refTypes;
private $refNames;
public function withRepositoryPHIDs(array $phids) {
$this->repositoryPHIDs = $phids;
@ -16,6 +17,11 @@ final class PhabricatorRepositoryRefCursorQuery
return $this;
}
public function withRefNames(array $names) {
$this->refNames = $names;
return $this;
}
protected function loadPage() {
$table = new PhabricatorRepositoryRefCursor();
$conn_r = $table->establishConnection('r');
@ -56,20 +62,32 @@ final class PhabricatorRepositoryRefCursorQuery
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->repositoryPHIDs) {
if ($this->repositoryPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
'repositoryPHID IN (%Ls)',
$this->repositoryPHIDs);
}
if ($this->refTypes) {
if ($this->refTypes !== null) {
$where[] = qsprintf(
$conn_r,
'refType IN (%Ls)',
$this->refTypes);
}
if ($this->refNames !== null) {
$name_hashes = array();
foreach ($this->refNames as $name) {
$name_hashes[] = PhabricatorHash::digestForIndex($name);
}
$where[] = qsprintf(
$conn_r,
'refNameHash IN (%Ls)',
$name_hashes);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);