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>
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index a38f9fc..2740bec 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -3976,6 +3976,11 @@
+
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
diff --git a/Documentation/user-submodules.txt b/Documentation/user-submodules.txt
index 151ac71..8ba31e7 100644
--- a/Documentation/user-submodules.txt
+++ b/Documentation/user-submodules.txt
@@ -20,6 +20,10 @@
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
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
index 2f3baae..ae37821 100644
--- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
@@ -29,6 +29,17 @@
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");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
@@ -76,7 +87,6 @@
}
@Test
-
public void testSubmoduleCommitMessage() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/SubmoduleOp.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/SubmoduleOp.java
index 5a91206..f7b4479 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/SubmoduleOp.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/SubmoduleOp.java
@@ -79,6 +79,7 @@
private final ChangeHooks changeHooks;
private final SubmoduleSectionParser.Factory subSecParserFactory;
private final boolean verboseSuperProject;
+ private final boolean enableSuperProjectSubscriptions;
@Inject
public SubmoduleOp(
@@ -99,12 +100,17 @@
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 @@
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 @@
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