Support to configure default submit type for newly created projects

Bug: issue 2257
Change-Id: If65a15c1f2928d26ffb2ab6fb12acbdc9b2cdda8
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2013-11-19 11:24:37 +01:00
parent 23e1a2e824
commit a79ea550cc
6 changed files with 29 additions and 10 deletions

View File

@ -115,8 +115,11 @@ Description values containing spaces should be quoted in single quotes
* CHERRY_PICK: always cherry-pick the commit.
+
Defaults to MERGE_IF_NECESSARY. For more details see
link:project-setup.html#submit_type[Change Submit Actions].
Defaults to MERGE_IF_NECESSARY unless
link:config-gerrit.html#repository.name.defaultSubmitType[
repository.<name>.defaultSubmitType] is set to a different value.
For more details see link:project-setup.html#submit_type[
Change Submit Actions].
--use-content-merge::
If enabled, Gerrit will try to perform a 3-way merge of text

View File

@ -2323,6 +2323,14 @@ to be the default owner of new projects.
Currently only the repository name `*` is supported.
This is a wildcard designating all repositories.
[[repository.name.defaultSubmitType]]repository.<name>.defaultSubmitType::
+
The default submit type for newly created projects. Supported values
are `MERGE_IF_NECESSARY`, `FAST_FORWARD_ONLY`, `REBASE_IF_NECESSARY`,
`MERGE_ALWAYS` and `CHERRY_PICK`.
+
By default, `MERGE_IF_NECESSARY`.
[[repository.name.ownerGroup]]repository.<name>.ownerGroup::
+
A name of a group which exists in the database. Zero, one or many

View File

@ -1478,7 +1478,9 @@ Whether an empty initial commit should be created.
The submit type that should be set for the project
(`MERGE_IF_NECESSARY`, `REBASE_IF_NECESSARY`, `FAST_FORWARD_ONLY`,
`MERGE_ALWAYS`, `CHERRY_PICK`). +
If not set, `MERGE_IF_NECESSARY` is set as submit type.
If not set, `MERGE_IF_NECESSARY` is set as submit type unless
link:config-gerrit.html#repository.name.defaultSubmitType[
repository.<name>.defaultSubmitType] is set to a different value.
|`branches` |optional|
A list of branches that should be initially created. +
For the branch names the `refs/heads/` prefix can be omitted.

View File

@ -101,8 +101,7 @@ public class CreateProject implements RestModifyView<TopLevelResource, Input> {
args.createEmptyCommit = input.createEmptyCommit;
args.permissionsOnly = input.permissionsOnly;
args.projectDescription = Strings.emptyToNull(input.description);
args.submitType =
Objects.firstNonNull(input.submitType, SubmitType.MERGE_IF_NECESSARY);
args.submitType = input.submitType;
args.branch = input.branches;
if (input.owners != null) {
List<AccountGroup.UUID> ownerIds =

View File

@ -14,6 +14,7 @@
package com.google.gerrit.server.project;
import com.google.common.base.Objects;
import com.google.gerrit.common.ProjectUtil;
import com.google.gerrit.common.data.AccessSection;
import com.google.gerrit.common.data.GroupDescription;
@ -25,9 +26,11 @@ import com.google.gerrit.extensions.events.NewProjectCreatedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.Project.SubmitType;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.GroupBackend;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.ProjectOwnerGroups;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitRepositoryManager;
@ -40,6 +43,7 @@ import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
@ -66,6 +70,7 @@ public class PerformCreateProject {
PerformCreateProject create(CreateProjectArgs createProjectArgs);
}
private final Config cfg;
private final Set<AccountGroup.UUID> projectOwnerGroups;
private final IdentifiedUser currentUser;
private final GitRepositoryManager repoManager;
@ -78,13 +83,15 @@ public class PerformCreateProject {
private final MetaDataUpdate.User metaDataUpdateFactory;
@Inject
PerformCreateProject(@ProjectOwnerGroups Set<AccountGroup.UUID> pOwnerGroups,
PerformCreateProject(@GerritServerConfig Config cfg,
@ProjectOwnerGroups Set<AccountGroup.UUID> pOwnerGroups,
IdentifiedUser identifiedUser, GitRepositoryManager gitRepoManager,
GitReferenceUpdated referenceUpdated,
DynamicSet<NewProjectCreatedListener> createdListener,
@GerritPersonIdent PersonIdent personIdent, GroupBackend groupBackend,
MetaDataUpdate.User metaDataUpdateFactory,
@Assisted CreateProjectArgs createPArgs, ProjectCache pCache) {
this.cfg = cfg;
this.projectOwnerGroups = pOwnerGroups;
this.currentUser = identifiedUser;
this.repoManager = gitRepoManager;
@ -179,7 +186,8 @@ public class PerformCreateProject {
Project newProject = config.getProject();
newProject.setDescription(createProjectArgs.projectDescription);
newProject.setSubmitType(createProjectArgs.submitType);
newProject.setSubmitType(Objects.firstNonNull(createProjectArgs.submitType,
cfg.getEnum("repository", "*", "defaultSubmitType", SubmitType.MERGE_IF_NECESSARY)));
newProject
.setUseContributorAgreements(createProjectArgs.contributorAgreements);
newProject.setUseSignedOffBy(createProjectArgs.signedOffBy);

View File

@ -63,9 +63,8 @@ final class CreateProjectCommand extends SshCommand {
@Option(name = "--description", aliases = {"-d"}, metaVar = "DESCRIPTION", usage = "description of project")
private String projectDescription = "";
@Option(name = "--submit-type", aliases = {"-t"}, usage = "project submit type\n"
+ "(default: MERGE_IF_NECESSARY)")
private SubmitType submitType = SubmitType.MERGE_IF_NECESSARY;
@Option(name = "--submit-type", aliases = {"-t"}, usage = "project submit type")
private SubmitType submitType;
@Option(name = "--contributor-agreements", usage = "if contributor agreement is required")
private InheritableBoolean contributorAgreements = InheritableBoolean.INHERIT;