Merge "SubmoduleOp: Allow all branches to be subscribed"

This commit is contained in:
Dave Borowitz
2016-08-10 15:23:36 +00:00
committed by Gerrit Code Review
8 changed files with 226 additions and 104 deletions

View File

@@ -130,18 +130,25 @@ public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
return pushChangeTo(repo, "refs/heads/" + branch, "some change", "");
}
protected void allowSubmoduleSubscription(String submodule, String subBranch,
String superproject, String superBranch) throws Exception {
protected void allowSubmoduleSubscription(String submodule,
String subBranch, String superproject, String superBranch, boolean match)
throws Exception {
Project.NameKey sub = new Project.NameKey(name(submodule));
Project.NameKey superName = new Project.NameKey(name(superproject));
try (MetaDataUpdate md = metaDataUpdateFactory.create(sub)) {
md.setMessage("Added superproject subscription");
ProjectConfig pc = ProjectConfig.read(md);
SubscribeSection s = new SubscribeSection(superName);
String refspec;
if (superBranch == null) {
s.addRefSpec(subBranch);
refspec = subBranch;
} else {
s.addRefSpec(subBranch + ":" + superBranch);
refspec = subBranch + ":" + superBranch;
}
if (match) {
s.addMatchingRefSpec(refspec);
} else {
s.addMultiMatchRefSpec(refspec);
}
pc.addSubscribeSection(s);
ObjectId oldId = pc.getRevision();
@@ -151,6 +158,13 @@ public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
}
}
protected void allowMatchingSubmoduleSubscription(String submodule,
String subBranch, String superproject, String superBranch)
throws Exception {
allowSubmoduleSubscription(submodule, subBranch, superproject,
superBranch, true);
}
protected void createSubmoduleSubscription(TestRepository<?> repo, String branch,
String subscribeToRepo, String subscribeToBranch) throws Exception {
Config config = new Config();

View File

@@ -44,7 +44,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionWithoutGlobalServerSetting() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
createSubmoduleSubscription(superRepo, "master",
@@ -70,7 +70,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionToEmptyRepo() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
createSubmoduleSubscription(superRepo, "master",
@@ -87,7 +87,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionToExistingRepo() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -104,8 +104,8 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionWildcardACLForSingleBranch() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
// master is allowed to be subscribed to any superprojects branch:
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
// master is allowed to be subscribed to master branch only:
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", null);
// create 'branch':
pushChangeTo(superRepo, "branch");
@@ -120,14 +120,14 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
expectToHaveSubmoduleState(superRepo, "master",
"subscribed-to-project", subHEAD);
expectToHaveSubmoduleState(superRepo, "branch",
"subscribed-to-project", subHEAD);
assertThat(hasSubmodule(superRepo, "branch",
"subscribed-to-project")).isFalse();
}
@Test
public void testSubscriptionWildcardACLForMissingProject() throws Exception {
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
"not-existing-super-project", "refs/heads/*");
pushChangeTo(subRepo, "master");
}
@@ -136,7 +136,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionWildcardACLForMissingBranch() throws Exception {
createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
"super-project", "refs/heads/*");
pushChangeTo(subRepo, "foo");
}
@@ -145,7 +145,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionWildcardACLForMissingGitmodules() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
"super-project", "refs/heads/*");
pushChangeTo(superRepo, "master");
pushChangeTo(subRepo, "master");
@@ -156,7 +156,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
// any branch is allowed to be subscribed to the same superprojects branch:
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
"super-project", "refs/heads/*");
// create 'branch' in both repos:
@@ -188,12 +188,53 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
"subscribed-to-project", subHEAD3);
}
@Test
public void testSubscriptionWildcardACLForManyBranches() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
// Any branch is allowed to be subscribed to any superproject branch:
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
"super-project", null, false);
pushChangeTo(superRepo, "branch");
pushChangeTo(subRepo, "another-branch");
createSubmoduleSubscription(superRepo, "branch",
"subscribed-to-project", "another-branch");
ObjectId subHEAD = pushChangeTo(subRepo, "another-branch");
expectToHaveSubmoduleState(superRepo, "branch",
"subscribed-to-project", subHEAD);
}
@Test
public void testSubscriptionWildcardACLOneToManyBranches() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
// Any branch is allowed to be subscribed to any superproject branch:
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/*", false);
pushChangeTo(superRepo, "branch");
createSubmoduleSubscription(superRepo, "branch",
"subscribed-to-project", "master");
ObjectId subHEAD = pushChangeTo(subRepo, "master");
expectToHaveSubmoduleState(superRepo, "branch",
"subscribed-to-project", subHEAD);
createSubmoduleSubscription(superRepo, "branch",
"subscribed-to-project", "branch");
pushChangeTo(subRepo, "branch");
// no change expected, as only master is subscribed:
expectToHaveSubmoduleState(superRepo, "branch",
"subscribed-to-project", subHEAD);
}
@Test
@GerritConfig(name = "submodule.verboseSuperprojectUpdate", value = "false")
public void testSubmoduleShortCommitMessage() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -220,7 +261,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubmoduleSubjectCommitMessage() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -248,7 +289,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubmoduleCommitMessage() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -276,7 +317,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionUnsubscribe() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -303,7 +344,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -329,7 +370,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionToDifferentBranches() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/foo",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/foo",
"super-project", "refs/heads/master");
createSubmoduleSubscription(superRepo, "master",
@@ -345,9 +386,9 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testBranchCircularSubscription() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
allowSubmoduleSubscription("super-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("super-project", "refs/heads/master",
"subscribed-to-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -370,9 +411,9 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
allowSubmoduleSubscription("super-project", "refs/heads/dev",
allowMatchingSubmoduleSubscription("super-project", "refs/heads/dev",
"subscribed-to-project", "refs/heads/dev");
pushChangeTo(subRepo, "master");
@@ -414,7 +455,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionFailOnWrongProjectACL() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"wrong-super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -429,7 +470,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testSubscriptionFailOnWrongBranchACL() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/wrong-branch");
pushChangeTo(subRepo, "master");
@@ -448,7 +489,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project",
new Project.NameKey(name("config-repo2")));
allowSubmoduleSubscription("config-repo", "refs/heads/*",
allowMatchingSubmoduleSubscription("config-repo", "refs/heads/*",
"super-project", "refs/heads/*");
pushChangeTo(subRepo, "master");
@@ -463,7 +504,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
public void testAllowedButNotSubscribed() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
@@ -490,7 +531,7 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
TestRepository<?> subRepo = createProjectWithPush(
"nested/subscribed-to-project");
// master is allowed to be subscribed to any superprojects branch:
allowSubmoduleSubscription("nested/subscribed-to-project",
allowMatchingSubmoduleSubscription("nested/subscribed-to-project",
"refs/heads/master", "super-project", null);
pushChangeTo(subRepo, "master");

View File

@@ -58,7 +58,7 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
public void testSubscriptionUpdateOfManyChanges() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
createSubmoduleSubscription(superRepo, "master", "subscribed-to-project", "master");
@@ -113,7 +113,7 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
public void testSubscriptionUpdateIncludingChangeInSuperproject() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
createSubmoduleSubscription(superRepo, "master", "subscribed-to-project", "master");
@@ -181,11 +181,11 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
TestRepository<?> sub2 = createProjectWithPush("sub2");
TestRepository<?> sub3 = createProjectWithPush("sub3");
allowSubmoduleSubscription("sub1", "refs/heads/master",
allowMatchingSubmoduleSubscription("sub1", "refs/heads/master",
"super-project", "refs/heads/master");
allowSubmoduleSubscription("sub2", "refs/heads/master",
allowMatchingSubmoduleSubscription("sub2", "refs/heads/master",
"super-project", "refs/heads/master");
allowSubmoduleSubscription("sub3", "refs/heads/master",
allowMatchingSubmoduleSubscription("sub3", "refs/heads/master",
"super-project", "refs/heads/master");
Config config = new Config();
@@ -227,7 +227,7 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> sub = createProjectWithPush("sub");
allowSubmoduleSubscription("sub", "refs/heads/master",
allowMatchingSubmoduleSubscription("sub", "refs/heads/master",
"super-project", "refs/heads/master");
Config config = new Config();
@@ -261,7 +261,7 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
TestRepository<?> sub = createProjectWithPush("sub");
TestRepository<?> standAlone = createProjectWithPush("standalone");
allowSubmoduleSubscription("sub", "refs/heads/master",
allowMatchingSubmoduleSubscription("sub", "refs/heads/master",
"super-project", "refs/heads/master");
createSubmoduleSubscription(superRepo, "master", "sub", "master");
@@ -301,9 +301,9 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
TestRepository<?> midRepo = createProjectWithPush("mid-project");
TestRepository<?> bottomRepo = createProjectWithPush("bottom-project");
allowSubmoduleSubscription("mid-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("mid-project", "refs/heads/master",
"top-project", "refs/heads/master");
allowSubmoduleSubscription("bottom-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("bottom-project", "refs/heads/master",
"mid-project", "refs/heads/master");
createSubmoduleSubscription(topRepo, "master", "mid-project", "master");
@@ -332,11 +332,11 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
TestRepository<?> midRepo = createProjectWithPush("mid-project");
TestRepository<?> bottomRepo = createProjectWithPush("bottom-project");
allowSubmoduleSubscription("mid-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("mid-project", "refs/heads/master",
"top-project", "refs/heads/master");
allowSubmoduleSubscription("bottom-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("bottom-project", "refs/heads/master",
"mid-project", "refs/heads/master");
allowSubmoduleSubscription("bottom-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("bottom-project", "refs/heads/master",
"top-project", "refs/heads/master");
createSubmoduleSubscription(midRepo, "master", "bottom-project", "master");
@@ -373,11 +373,11 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
createSubmoduleSubscription(topRepo, "master", "mid-project", "master");
createSubmoduleSubscription(bottomRepo, "master", "top-project", "master");
allowSubmoduleSubscription("bottom-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("bottom-project", "refs/heads/master",
"mid-project", "refs/heads/master");
allowSubmoduleSubscription("mid-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("mid-project", "refs/heads/master",
"top-project", "refs/heads/master");
allowSubmoduleSubscription("top-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("top-project", "refs/heads/master",
"bottom-project", "refs/heads/master");
ObjectId bottomMasterHead =
@@ -401,9 +401,9 @@ public class SubmoduleSubscriptionsWholeTopicMergeIT
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
allowSubmoduleSubscription("super-project", "refs/heads/dev",
allowMatchingSubmoduleSubscription("super-project", "refs/heads/dev",
"subscribed-to-project", "refs/heads/dev");
pushChangeTo(subRepo, "dev");