Merge changes I615b109f,I261f140c,Ia6ffd80e

* changes:
  Superproject Subscriptions: test more corner cases
  AbstractSubmoduleSubscription: test for pushes to be valid
  Fix "submoduleOp: Move checking for existence to SubmoduleOp"
This commit is contained in:
Dave Borowitz
2016-06-04 21:05:37 +00:00
committed by Gerrit Code Review
3 changed files with 47 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.git;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.Iterables;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.Permission;
@@ -31,7 +32,10 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
import java.util.concurrent.atomic.AtomicInteger;
@@ -57,12 +61,21 @@ public abstract class AbstractSubmoduleSubscription extends AbstractDaemonTest {
.message(message)
.add("a.txt", "a contents: " + contentCounter.incrementAndGet())
.create();
String refspec = "HEAD:" + ref;
String pushedRef = ref;
if (!topic.isEmpty()) {
refspec += "/" + topic;
pushedRef += "/" + topic;
}
repo.git().push().setRemote("origin").setRefSpecs(
new RefSpec(refspec)).call();
String refspec = "HEAD:" + pushedRef;
Iterable<PushResult> res = repo.git().push()
.setRemote("origin").setRefSpecs(new RefSpec(refspec)).call();
RemoteRefUpdate u = Iterables.getOnlyElement(res).getRemoteUpdate(pushedRef);
assertThat(u).isNotNull();
assertThat(u.getStatus()).isEqualTo(Status.OK);
assertThat(u.getNewObjectId()).isEqualTo(ret);
return ret;
}

View File

@@ -107,6 +107,33 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
"subscribed-to-project", subHEAD);
}
@Test
public void testSubscriptionWildcardACLForMissingProject() throws Exception {
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
"not-existing-super-project", "refs/heads/*");
pushChangeTo(subRepo, "master");
}
@Test
public void testSubscriptionWildcardACLForMissingBranch() throws Exception {
createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
"super-project", "refs/heads/*");
pushChangeTo(subRepo, "foo");
}
@Test
public void testSubscriptionWildcardACLForMissingGitmodules() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/*",
"super-project", "refs/heads/*");
pushChangeTo(superRepo, "master");
pushChangeTo(subRepo, "master");
}
@Test
public void testSubscriptionWildcardACLOneOnOneMapping() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");

View File

@@ -152,10 +152,10 @@ public class SubmoduleOp {
Project.NameKey p = targetBranch.getParentKey();
try {
orm.openRepo(p, false);
OpenRepo or = orm.getRepo(project);
ObjectId id = or.repo.resolve(branch.get());
OpenRepo or = orm.getRepo(p);
ObjectId id = or.repo.resolve(targetBranch.get());
if (id == null) {
logDebug("The branch " + branch + " doesn't exist.");
logDebug("The branch " + targetBranch + " doesn't exist.");
continue;
}
} catch (NoSuchProjectException e) {