Display empty branch list when project has no repository
If a project exists only to provide permissions inherited by other projects, it probably has no Git repository, and thus cannot have any branches. Instead of crashing with an exception when clicking on the branches tab in the admin web UI, display a message. Bug: issue 612 Change-Id: I140ea74e640d732863df2b95eabb6e73787eae11 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -19,35 +19,33 @@ import com.google.gerrit.reviewdb.Branch;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* It holds list of branches and boolean to indicate
|
||||
* if it is allowed to add new branches.
|
||||
* It holds list of branches and boolean to indicate if it is allowed to add new
|
||||
* branches.
|
||||
*/
|
||||
public final class ListBranchesResult {
|
||||
protected boolean noRepository;
|
||||
protected boolean canAdd;
|
||||
|
||||
protected List<Branch> branches;
|
||||
|
||||
protected ListBranchesResult() {
|
||||
}
|
||||
|
||||
public ListBranchesResult(final List<Branch> branches, boolean canAdd) {
|
||||
public ListBranchesResult(List<Branch> branches, boolean canAdd,
|
||||
boolean noRepository) {
|
||||
this.branches = branches;
|
||||
this.canAdd = canAdd;
|
||||
this.noRepository = noRepository;
|
||||
}
|
||||
|
||||
public boolean getNoRepository() {
|
||||
return noRepository;
|
||||
}
|
||||
|
||||
public boolean getCanAdd() {
|
||||
return canAdd;
|
||||
}
|
||||
|
||||
public void setCanAdd(boolean canAdd) {
|
||||
this.canAdd = canAdd;
|
||||
}
|
||||
|
||||
public List<Branch> getBranches() {
|
||||
return branches;
|
||||
}
|
||||
|
||||
public void setBranches(List<Branch> branches) {
|
||||
this.branches = branches;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,4 +88,5 @@ public interface AdminConstants extends Constants {
|
||||
|
||||
String noGroupSelected();
|
||||
String errorNoMatchingGroups();
|
||||
String errorNoGitRepository();
|
||||
}
|
||||
|
||||
@@ -69,3 +69,4 @@ projectAdminTabAccess = Access
|
||||
|
||||
noGroupSelected = (No group selected)
|
||||
errorNoMatchingGroups = No Matching Groups
|
||||
errorNoGitRepository = No Git Repository
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.google.gwt.user.client.ui.CheckBox;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||
import com.google.gwtjsonrpc.client.RemoteJsonException;
|
||||
|
||||
@@ -64,10 +65,22 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
||||
super.onLoad();
|
||||
Util.PROJECT_SVC.listBranches(getProjectKey(),
|
||||
new ScreenLoadCallback<ListBranchesResult>(this) {
|
||||
@Override
|
||||
public void preDisplay(final ListBranchesResult result) {
|
||||
enableForm(true);
|
||||
display(result.getBranches());
|
||||
addPanel.setVisible(result.getCanAdd());
|
||||
if (result.getNoRepository()) {
|
||||
branches.setVisible(false);
|
||||
addPanel.setVisible(false);
|
||||
delBranch.setVisible(false);
|
||||
|
||||
Label no = new Label(Util.C.errorNoGitRepository());
|
||||
no.setStyleName(Gerrit.RESOURCES.css().smallHeading());
|
||||
add(no);
|
||||
|
||||
} else {
|
||||
enableForm(true);
|
||||
display(result.getBranches());
|
||||
addPanel.setVisible(result.getCanAdd());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,15 +60,20 @@ class ListBranches extends Handler<ListBranchesResult> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListBranchesResult call() throws NoSuchProjectException,
|
||||
RepositoryNotFoundException {
|
||||
public ListBranchesResult call() throws NoSuchProjectException {
|
||||
final ProjectControl pctl = projectControlFactory.validateFor( //
|
||||
projectName, //
|
||||
ProjectControl.OWNER | ProjectControl.VISIBLE);
|
||||
|
||||
final List<Branch> branches = new ArrayList<Branch>();
|
||||
Branch headBranch = null;
|
||||
final Repository db = repoManager.openRepository(projectName.get());
|
||||
|
||||
final Repository db;
|
||||
try {
|
||||
db = repoManager.openRepository(projectName.get());
|
||||
} catch (RepositoryNotFoundException noGitRepository) {
|
||||
return new ListBranchesResult(branches, false, true);
|
||||
}
|
||||
try {
|
||||
final Map<String, Ref> all = db.getAllRefs();
|
||||
|
||||
@@ -139,7 +144,7 @@ class ListBranches extends Handler<ListBranchesResult> {
|
||||
if (headBranch != null) {
|
||||
branches.add(0, headBranch);
|
||||
}
|
||||
return new ListBranchesResult(branches, pctl.canAddRefs());
|
||||
return new ListBranchesResult(branches, pctl.canAddRefs(), false);
|
||||
}
|
||||
|
||||
private Branch createBranch(final String name) {
|
||||
|
||||
Reference in New Issue
Block a user