SubmoduleOp: Introduce a setting to disable all superproject subscriptions

Not every host needs superproject subscriptions. Have an option to turn it
off completely. In fact a quick search reveals people are mostly confused
by this feature in the wild.

Change-Id: I20f699c06f6bf832d5686cd19db31238e1842851
Signed-off-by: Stefan Beller <sbeller@google.com>
This commit is contained in:
Stefan Beller
2016-03-10 10:06:53 -08:00
parent 38e33103d3
commit 8cc252ef0c
4 changed files with 33 additions and 2 deletions

View File

@@ -3976,6 +3976,11 @@ the commit message of the superproject update.
+
By default this is true.
[[submodule.enableSuperProjectSubscriptions]]submodule.enableSuperProjectSubscriptions
+
This allows to enable the superproject subscription mechanism.
+
By default this is true.
[[user]]
=== Section user

View File

@@ -20,6 +20,10 @@ When a new commit of a registered submodule is merged, Gerrit
automatically updates the subscribers to the submodule with a new
commit having the updated gitlinks.
This feature is enabled by default and can be disabled
via link:config-gerrit.html#submodule.enableSuperProjectSubscriptions[submodule.enableSuperProjectSubscriptions]
in the server configuration.
== Git Submodules Overview
Submodules are a git feature that allows an external repository to be

View File

@@ -28,6 +28,17 @@ import org.junit.Test;
public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
@Test
@GerritConfig(name = "submodule.enableSuperProjectSubscriptions", value = "false")
public void testSubscriptionWithoutServerSetting() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
createSubmoduleSubscription(superRepo, "master", "subscribed-to-project", "master");
pushChangeTo(subRepo, "master");
assertThat(hasSubmodule(superRepo, "master", "subscribed-to-project")).isFalse();
}
@Test
public void testSubscriptionToEmptyRepo() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
@@ -76,7 +87,6 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
}
@Test
public void testSubmoduleCommitMessage() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");

View File

@@ -79,6 +79,7 @@ public class SubmoduleOp {
private final ChangeHooks changeHooks;
private final SubmoduleSectionParser.Factory subSecParserFactory;
private final boolean verboseSuperProject;
private final boolean enableSuperProjectSubscriptions;
@Inject
public SubmoduleOp(
@@ -99,12 +100,17 @@ public class SubmoduleOp {
this.subSecParserFactory = subSecParserFactory;
this.verboseSuperProject = cfg.getBoolean("submodule",
"verboseSuperprojectUpdate", true);
this.enableSuperProjectSubscriptions = cfg.getBoolean("submodule",
"enableSuperProjectSubscriptions", true);
updatedSubscribers = new HashSet<>();
}
void updateSubmoduleSubscriptions(ReviewDb db, Set<Branch.NameKey> branches)
throws SubmoduleException {
if (!enableSuperProjectSubscriptions) {
return;
}
for (Branch.NameKey branch : branches) {
updateSubmoduleSubscriptions(db, branch);
}
@@ -112,6 +118,9 @@ public class SubmoduleOp {
void updateSubmoduleSubscriptions(ReviewDb db, Branch.NameKey destBranch)
throws SubmoduleException {
if (!enableSuperProjectSubscriptions) {
return;
}
if (urlProvider.get() == null) {
logAndThrowSubmoduleException("Cannot establish canonical web url used "
+ "to access gerrit. It should be provided in gerrit.config file.");
@@ -185,6 +194,9 @@ public class SubmoduleOp {
protected void updateSuperProjects(ReviewDb db,
Collection<Branch.NameKey> updatedBranches) throws SubmoduleException {
if (!enableSuperProjectSubscriptions) {
return;
}
try {
// These (repo/branch) will be updated later with all the given
// individual submodule subscriptions