diff --git a/Documentation/cmd-create-project.txt b/Documentation/cmd-create-project.txt index 4d1ea05450..e8c3857b60 100644 --- a/Documentation/cmd-create-project.txt +++ b/Documentation/cmd-create-project.txt @@ -60,7 +60,14 @@ This command is intended to be used in scripts. --owner:: -o:: - Name of the group(s) which will initially own this repository. + Identifier of the group(s) which will initially own this repository. + + This can be: + + * the UUID of the group + * the legacy numeric ID of the group + * the name of the group if it is unique + The specified group(s) must already be defined within Gerrit. Several groups can be specified on the command line. + diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/args4j/AccountGroupUUIDHandler.java b/gerrit-server/src/main/java/com/google/gerrit/server/args4j/AccountGroupUUIDHandler.java index 79ab8c8726..56446688bc 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/args4j/AccountGroupUUIDHandler.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/args4j/AccountGroupUUIDHandler.java @@ -14,10 +14,13 @@ package com.google.gerrit.server.args4j; +import com.google.gerrit.common.data.GroupDescription; import com.google.gerrit.common.data.GroupReference; +import com.google.gerrit.common.errors.NoSuchGroupException; import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.server.account.GroupBackend; import com.google.gerrit.server.account.GroupBackends; +import com.google.gerrit.server.account.GroupControl; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import org.kohsuke.args4j.CmdLineException; @@ -29,20 +32,44 @@ import org.kohsuke.args4j.spi.Setter; public class AccountGroupUUIDHandler extends OptionHandler { private final GroupBackend groupBackend; + private final GroupControl.Factory groupControlFactory; @Inject public AccountGroupUUIDHandler( final GroupBackend groupBackend, + final GroupControl.Factory groupControlFactory, @Assisted final CmdLineParser parser, @Assisted final OptionDef option, @Assisted final Setter setter) { super(parser, option, setter); this.groupBackend = groupBackend; + this.groupControlFactory = groupControlFactory; } @Override public final int parseArguments(final Parameters params) throws CmdLineException { final String n = params.getParameter(0); + AccountGroup.UUID uuid = new AccountGroup.UUID(n); + if (groupBackend.handles(uuid)) { + GroupDescription.Basic d = groupBackend.get(uuid); + if (d != null) { + setter.addValue(uuid); + return 1; + } + } + + // Might be a legacy AccountGroup.Id. + if (n.matches("^[1-9][0-9]*$")) { + try { + AccountGroup.Id legacyId = AccountGroup.Id.parse(n); + uuid = groupControlFactory.controlFor(legacyId).getGroup().getGroupUUID(); + setter.addValue(uuid); + return 1; + } catch (IllegalArgumentException | NoSuchGroupException e) { + // Ignored + } + } + GroupReference group = GroupBackends.findExactSuggestion(groupBackend, n); if (group == null) { throw new CmdLineException(owner, "Group \"" + n + "\" does not exist");