Merge branch 'stable-2.11' into stable-2.12

* stable-2.11:
  SetParent: Explicitly set to All-Projects when not specified
  CreateProject: Explicitly set parent to All-Projects when not specified

Change-Id: If833c4489945ed3f25e8aa3f5a1f812ab2fa12f7
This commit is contained in:
David Pursehouse
2016-02-18 17:44:36 +09:00
3 changed files with 31 additions and 10 deletions

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.project;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
@@ -70,20 +72,20 @@ public class SetParent implements RestModifyView<ProjectResource, Input> {
throws AuthException, ResourceConflictException,
ResourceNotFoundException, UnprocessableEntityException, IOException {
ProjectControl ctl = rsrc.getControl();
validateParentUpdate(ctl, input.parent, checkIfAdmin);
String parentName = MoreObjects.firstNonNull(
Strings.emptyToNull(input.parent), allProjects.get());
validateParentUpdate(ctl, parentName, checkIfAdmin);
try {
MetaDataUpdate md = updateFactory.create(rsrc.getNameKey());
try {
ProjectConfig config = ProjectConfig.read(md);
Project project = config.getProject();
project.setParentName(Strings.emptyToNull(input.parent));
project.setParentName(parentName);
String msg = Strings.emptyToNull(input.commitMessage);
if (msg == null) {
msg = String.format(
"Changed parent to %s.\n",
MoreObjects.firstNonNull(project.getParentName(),
allProjects.get()));
"Changed parent to %s.\n", parentName);
} else if (!msg.endsWith("\n")) {
msg += "\n";
}
@@ -92,8 +94,9 @@ public class SetParent implements RestModifyView<ProjectResource, Input> {
config.commit(md);
cache.evict(ctl.getProject());
Project.NameKey parentName = project.getParent(allProjects);
return parentName != null ? parentName.get() : "";
Project.NameKey parent = project.getParent(allProjects);
checkNotNull(parent);
return parent.get();
} finally {
md.close();
}