diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index a38f9fcbee..2740becee5 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -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 diff --git a/Documentation/user-submodules.txt b/Documentation/user-submodules.txt index 151ac71528..8ba31e7597 100644 --- a/Documentation/user-submodules.txt +++ b/Documentation/user-submodules.txt @@ -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 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 2f3baae8ed..ae378212b1 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 @@ -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"); 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 5a91206fce..f7b447969c 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 @@ 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 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 updatedBranches) throws SubmoduleException { + if (!enableSuperProjectSubscriptions) { + return; + } try { // These (repo/branch) will be updated later with all the given // individual submodule subscriptions