Merge changes from topic 'superproject_fixes'
* changes: Submodule subscriptions: accept allowed but unsubscribed subscriptions Correct inheriting superproject subscription test submodule subscriptions: ensure nested relative projects work
This commit is contained in:
@@ -71,13 +71,6 @@ public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
|
|||||||
return pushChangeTo(repo, "refs/heads/" + branch, "some change", "");
|
return pushChangeTo(repo, "refs/heads/" + branch, "some change", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createSubmoduleSubscription(TestRepository<?> repo, String branch,
|
|
||||||
String subscribeToRepo, String subscribeToBranch) throws Exception {
|
|
||||||
Config config = new Config();
|
|
||||||
prepareSubmoduleConfigEntry(config, subscribeToRepo, subscribeToBranch);
|
|
||||||
pushSubmoduleConfig(repo, branch, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void allowSubmoduleSubscription(String submodule, String subBranch,
|
protected void allowSubmoduleSubscription(String submodule, String subBranch,
|
||||||
String superproject, String superBranch) throws Exception {
|
String superproject, String superBranch) throws Exception {
|
||||||
Project.NameKey sub = new Project.NameKey(name(submodule));
|
Project.NameKey sub = new Project.NameKey(name(submodule));
|
||||||
@@ -99,6 +92,34 @@ public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createSubmoduleSubscription(TestRepository<?> repo, String branch,
|
||||||
|
String subscribeToRepo, String subscribeToBranch) throws Exception {
|
||||||
|
Config config = new Config();
|
||||||
|
prepareSubmoduleConfigEntry(config, subscribeToRepo, subscribeToBranch);
|
||||||
|
pushSubmoduleConfig(repo, branch, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createRelativeSubmoduleSubscription(TestRepository<?> repo,
|
||||||
|
String branch, String subscribeToRepoPrefix, String subscribeToRepo,
|
||||||
|
String subscribeToBranch) throws Exception {
|
||||||
|
Config config = new Config();
|
||||||
|
prepareRelativeSubmoduleConfigEntry(config, subscribeToRepoPrefix,
|
||||||
|
subscribeToRepo, subscribeToBranch);
|
||||||
|
pushSubmoduleConfig(repo, branch, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void prepareRelativeSubmoduleConfigEntry(Config config,
|
||||||
|
String subscribeToRepoPrefix, String subscribeToRepo,
|
||||||
|
String subscribeToBranch) {
|
||||||
|
subscribeToRepo = name(subscribeToRepo);
|
||||||
|
String url = subscribeToRepoPrefix + subscribeToRepo;
|
||||||
|
config.setString("submodule", subscribeToRepo, "path", subscribeToRepo);
|
||||||
|
config.setString("submodule", subscribeToRepo, "url", url);
|
||||||
|
if (subscribeToBranch != null) {
|
||||||
|
config.setString("submodule", subscribeToRepo, "branch", subscribeToBranch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void prepareSubmoduleConfigEntry(Config config,
|
protected void prepareSubmoduleConfigEntry(Config config,
|
||||||
String subscribeToRepo, String subscribeToBranch) {
|
String subscribeToRepo, String subscribeToBranch) {
|
||||||
subscribeToRepo = name(subscribeToRepo);
|
subscribeToRepo = name(subscribeToRepo);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.git;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.acceptance.GerritConfig;
|
import com.google.gerrit.acceptance.GerritConfig;
|
||||||
import com.google.gerrit.acceptance.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
@@ -27,7 +28,9 @@ import org.eclipse.jgit.lib.ObjectId;
|
|||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.revwalk.RevTree;
|
import org.eclipse.jgit.revwalk.RevTree;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
|
import org.eclipse.jgit.transport.PushResult;
|
||||||
import org.eclipse.jgit.transport.RefSpec;
|
import org.eclipse.jgit.transport.RefSpec;
|
||||||
|
import org.eclipse.jgit.transport.RemoteRefUpdate;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@NoHttpd
|
@NoHttpd
|
||||||
@@ -339,20 +342,66 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
|
|||||||
@Test
|
@Test
|
||||||
public void testSubscriptionInheritACL() throws Exception {
|
public void testSubscriptionInheritACL() throws Exception {
|
||||||
createProjectWithPush("config-repo");
|
createProjectWithPush("config-repo");
|
||||||
TestRepository<?> superRepo = createProjectWithPush("super-project",
|
createProjectWithPush("config-repo2",
|
||||||
new Project.NameKey(name("config-repo")));
|
new Project.NameKey(name("config-repo")));
|
||||||
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
|
TestRepository<?> superRepo = createProjectWithPush("super-project");
|
||||||
allowSubmoduleSubscription("config-repo", "refs/heads/master",
|
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project",
|
||||||
"super-project", "refs/heads/wrong-branch");
|
new Project.NameKey(name("config-repo2")));
|
||||||
|
allowSubmoduleSubscription("config-repo", "refs/heads/*",
|
||||||
|
"super-project", "refs/heads/*");
|
||||||
|
|
||||||
pushChangeTo(subRepo, "master");
|
pushChangeTo(subRepo, "master");
|
||||||
createSubmoduleSubscription(superRepo, "master",
|
createSubmoduleSubscription(superRepo, "master",
|
||||||
"subscribed-to-project", "master");
|
"subscribed-to-project", "master");
|
||||||
|
ObjectId subHEAD = pushChangeTo(subRepo, "master");
|
||||||
|
expectToHaveSubmoduleState(superRepo, "master",
|
||||||
|
"subscribed-to-project", subHEAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAllowedButNotSubscribed() throws Exception {
|
||||||
|
TestRepository<?> superRepo = createProjectWithPush("super-project");
|
||||||
|
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
|
||||||
|
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
|
||||||
|
"super-project", "refs/heads/master");
|
||||||
|
|
||||||
pushChangeTo(subRepo, "master");
|
pushChangeTo(subRepo, "master");
|
||||||
|
subRepo.branch("HEAD").commit().insertChangeId()
|
||||||
|
.message("some change")
|
||||||
|
.add("b.txt", "b contents for testing")
|
||||||
|
.create();
|
||||||
|
String refspec = "HEAD:refs/heads/master";
|
||||||
|
PushResult r = Iterables.getOnlyElement(subRepo.git().push()
|
||||||
|
.setRemote("origin")
|
||||||
|
.setRefSpecs(new RefSpec(refspec))
|
||||||
|
.call());
|
||||||
|
assertThat(r.getMessages()).doesNotContain("error");
|
||||||
|
assertThat(r.getRemoteUpdate("refs/heads/master").getStatus())
|
||||||
|
.isEqualTo(RemoteRefUpdate.Status.OK);
|
||||||
|
|
||||||
assertThat(hasSubmodule(superRepo, "master",
|
assertThat(hasSubmodule(superRepo, "master",
|
||||||
"subscribed-to-project")).isFalse();
|
"subscribed-to-project")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSubscriptionDeepRelative() throws Exception {
|
||||||
|
TestRepository<?> superRepo = createProjectWithPush("super-project");
|
||||||
|
TestRepository<?> subRepo = createProjectWithPush(
|
||||||
|
"nested/subscribed-to-project");
|
||||||
|
// master is allowed to be subscribed to any superprojects branch:
|
||||||
|
allowSubmoduleSubscription("nested/subscribed-to-project",
|
||||||
|
"refs/heads/master", "super-project", null);
|
||||||
|
|
||||||
|
pushChangeTo(subRepo, "master");
|
||||||
|
createRelativeSubmoduleSubscription(superRepo, "master",
|
||||||
|
"../", "nested/subscribed-to-project", "master");
|
||||||
|
|
||||||
|
ObjectId subHEAD = pushChangeTo(subRepo, "master");
|
||||||
|
|
||||||
|
expectToHaveSubmoduleState(superRepo, "master",
|
||||||
|
"nested/subscribed-to-project", subHEAD);
|
||||||
|
}
|
||||||
|
|
||||||
private void deleteAllSubscriptions(TestRepository<?> repo, String branch)
|
private void deleteAllSubscriptions(TestRepository<?> repo, String branch)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
repo.git().fetch().setRemote("origin").call();
|
repo.git().fetch().setRemote("origin").call();
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,11 +54,7 @@ public class GitModules {
|
|||||||
|
|
||||||
private static final String GIT_MODULES = ".gitmodules";
|
private static final String GIT_MODULES = ".gitmodules";
|
||||||
|
|
||||||
private final String canonicalWebUrl;
|
|
||||||
private final Branch.NameKey branch;
|
|
||||||
private final String submissionId;
|
private final String submissionId;
|
||||||
private final MergeOpRepoManager orm;
|
|
||||||
|
|
||||||
Set<SubmoduleSubscription> subscriptions;
|
Set<SubmoduleSubscription> subscriptions;
|
||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
@@ -65,14 +62,9 @@ public class GitModules {
|
|||||||
@CanonicalWebUrl @Nullable String canonicalWebUrl,
|
@CanonicalWebUrl @Nullable String canonicalWebUrl,
|
||||||
@Assisted Branch.NameKey branch,
|
@Assisted Branch.NameKey branch,
|
||||||
@Assisted String submissionId,
|
@Assisted String submissionId,
|
||||||
@Assisted MergeOpRepoManager orm) {
|
@Assisted MergeOpRepoManager orm) throws IOException {
|
||||||
this.orm = orm;
|
|
||||||
this.branch = branch;
|
|
||||||
this.submissionId = submissionId;
|
this.submissionId = submissionId;
|
||||||
this.canonicalWebUrl = canonicalWebUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void load() throws IOException {
|
|
||||||
Project.NameKey project = branch.getParentKey();
|
Project.NameKey project = branch.getParentKey();
|
||||||
logDebug("Loading .gitmodules of {} for project {}", branch, project);
|
logDebug("Loading .gitmodules of {} for project {}", branch, project);
|
||||||
try {
|
try {
|
||||||
@@ -91,18 +83,18 @@ public class GitModules {
|
|||||||
TreeWalk tw = TreeWalk.forPath(or.repo, GIT_MODULES, commit.getTree());
|
TreeWalk tw = TreeWalk.forPath(or.repo, GIT_MODULES, commit.getTree());
|
||||||
if (tw == null
|
if (tw == null
|
||||||
|| (tw.getRawMode(0) & FileMode.TYPE_MASK) != FileMode.TYPE_FILE) {
|
|| (tw.getRawMode(0) & FileMode.TYPE_MASK) != FileMode.TYPE_FILE) {
|
||||||
|
subscriptions = Collections.emptySet();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BlobBasedConfig bbc;
|
||||||
try {
|
try {
|
||||||
BlobBasedConfig bbc =
|
bbc = new BlobBasedConfig(null, or.repo, commit, GIT_MODULES);
|
||||||
new BlobBasedConfig(null, or.repo, commit, GIT_MODULES);
|
|
||||||
subscriptions = new SubmoduleSectionParser(bbc, canonicalWebUrl,
|
|
||||||
branch).parseAllSections();
|
|
||||||
} catch (ConfigInvalidException e) {
|
} catch (ConfigInvalidException e) {
|
||||||
throw new IOException(
|
throw new IOException("Could not read .gitmodules of super project: " +
|
||||||
"Could not read .gitmodule file of super project: " +
|
|
||||||
branch.getParentKey(), e);
|
branch.getParentKey(), e);
|
||||||
}
|
}
|
||||||
|
subscriptions = new SubmoduleSectionParser(bbc, canonicalWebUrl,
|
||||||
|
branch).parseAllSections();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<SubmoduleSubscription> subscribedTo(Branch.NameKey src) {
|
public Collection<SubmoduleSubscription> subscribedTo(Branch.NameKey src) {
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ public class SubmoduleOp {
|
|||||||
getDestinationBranches(branch, s, orm);
|
getDestinationBranches(branch, s, orm);
|
||||||
for (Branch.NameKey targetBranch : branches) {
|
for (Branch.NameKey targetBranch : branches) {
|
||||||
GitModules m = gitmodulesFactory.create(targetBranch, updateId, orm);
|
GitModules m = gitmodulesFactory.create(targetBranch, updateId, orm);
|
||||||
m.load();
|
|
||||||
for (SubmoduleSubscription ss : m.subscribedTo(branch)) {
|
for (SubmoduleSubscription ss : m.subscribedTo(branch)) {
|
||||||
logDebug("Checking SubmoduleSubscription " + ss);
|
logDebug("Checking SubmoduleSubscription " + ss);
|
||||||
if (projectCache.get(ss.getSubmodule().getParentKey()) != null) {
|
if (projectCache.get(ss.getSubmodule().getParentKey()) != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user