use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method fetchFromBundles.
/**
* Fetches each bundle into a newly cloned repository, then it applies the bundle, and returns the
* resulting tree id.
*
* <p>Omits NoteDb meta refs.
*/
protected Map<Branch.NameKey, ObjectId> fetchFromBundles(BinaryResult bundles) throws Exception {
assertThat(bundles.getContentType()).isEqualTo("application/x-zip");
FileSystem fs = Jimfs.newFileSystem();
Path previewPath = fs.getPath("preview.zip");
try (OutputStream out = Files.newOutputStream(previewPath)) {
bundles.writeTo(out);
}
Map<Branch.NameKey, ObjectId> ret = new HashMap<>();
try (FileSystem zipFs = FileSystems.newFileSystem(previewPath, null);
DirectoryStream<Path> dirStream = Files.newDirectoryStream(Iterables.getOnlyElement(zipFs.getRootDirectories()))) {
for (Path p : dirStream) {
if (!Files.isRegularFile(p)) {
continue;
}
String bundleName = p.getFileName().toString();
int len = bundleName.length();
assertThat(bundleName).endsWith(".git");
String repoName = bundleName.substring(0, len - 4);
Project.NameKey proj = new Project.NameKey(repoName);
TestRepository<?> localRepo = cloneProject(proj);
try (InputStream bundleStream = Files.newInputStream(p);
TransportBundleStream tbs = new TransportBundleStream(localRepo.getRepository(), new URIish(bundleName), bundleStream)) {
FetchResult fr = tbs.fetch(NullProgressMonitor.INSTANCE, Arrays.asList(new RefSpec("refs/*:refs/preview/*")));
for (Ref r : fr.getAdvertisedRefs()) {
String refName = r.getName();
if (RefNames.isNoteDbMetaRef(refName)) {
continue;
}
RevCommit c = localRepo.getRevWalk().parseCommit(r.getObjectId());
ret.put(new Branch.NameKey(proj, refName), c.getTree().copy());
}
}
}
}
assertThat(ret).isNotEmpty();
return ret;
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class SubmoduleSubscriptionsWholeTopicMergeIT method subscriptionUpdateOfManyChanges.
@Test
public void subscriptionUpdateOfManyChanges() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master", "super-project", "refs/heads/master");
createSubmoduleSubscription(superRepo, "master", "subscribed-to-project", "master");
ObjectId subHEAD = subRepo.branch("HEAD").commit().insertChangeId().message("some change").add("a.txt", "a contents ").create();
subRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
RevCommit c = subRepo.getRevWalk().parseCommit(subHEAD);
RevCommit c1 = subRepo.branch("HEAD").commit().insertChangeId().message("first change").add("asdf", "asdf\n").create();
subRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/for/master/" + name("topic-foo"))).call();
subRepo.reset(c.getId());
RevCommit c2 = subRepo.branch("HEAD").commit().insertChangeId().message("qwerty").add("qwerty", "qwerty").create();
RevCommit c3 = subRepo.branch("HEAD").commit().insertChangeId().message("qwerty followup").add("qwerty", "qwerty\nqwerty\n").create();
subRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/for/master/" + name("topic-foo"))).call();
String id1 = getChangeId(subRepo, c1).get();
String id2 = getChangeId(subRepo, c2).get();
String id3 = getChangeId(subRepo, c3).get();
gApi.changes().id(id1).current().review(ReviewInput.approve());
gApi.changes().id(id2).current().review(ReviewInput.approve());
gApi.changes().id(id3).current().review(ReviewInput.approve());
Map<Branch.NameKey, ObjectId> preview = fetchFromSubmitPreview(id1);
gApi.changes().id(id1).current().submit();
ObjectId subRepoId = subRepo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/master").getObjectId();
expectToHaveSubmoduleState(superRepo, "master", "subscribed-to-project", subRepoId);
// As the submodules have changed commits, the superproject tree will be
// different, so we cannot directly compare the trees here, so make
// assumptions only about the changed branches:
Project.NameKey p1 = new Project.NameKey(name("super-project"));
Project.NameKey p2 = new Project.NameKey(name("subscribed-to-project"));
assertThat(preview).containsKey(new Branch.NameKey(p1, "refs/heads/master"));
assertThat(preview).containsKey(new Branch.NameKey(p2, "refs/heads/master"));
if ((getSubmitType() == SubmitType.CHERRY_PICK) || (getSubmitType() == SubmitType.REBASE_ALWAYS)) {
// each change is updated and the respective target branch is updated:
assertThat(preview).hasSize(5);
} else if ((getSubmitType() == SubmitType.REBASE_IF_NECESSARY)) {
// Either the first is used first as is, then the second and third need
// rebasing, or those two stay as is and the first is rebased.
// add in 2 master branches, expect 3 or 4:
assertThat(preview.size()).isAnyOf(3, 4);
} else {
assertThat(preview).hasSize(2);
}
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class SubmitOnPushIT method mergeOnPushToBranch.
@Test
public void mergeOnPushToBranch() throws Exception {
grant(project, "refs/heads/master", Permission.PUSH);
PushOneCommit.Result r = push("refs/for/master", PushOneCommit.SUBJECT, "a.txt", "some content");
r.assertOkStatus();
git().push().setRefSpecs(new RefSpec(r.getCommit().name() + ":refs/heads/master")).call();
assertCommit(project, "refs/heads/master");
ChangeData cd = Iterables.getOnlyElement(queryProvider.get().byKey(new Change.Key(r.getChangeId())));
RevCommit c = r.getCommit();
PatchSet.Id psId = cd.currentPatchSet().getId();
assertThat(psId.get()).isEqualTo(1);
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.MERGED);
assertSubmitApproval(psId);
assertThat(cd.patchSets()).hasSize(1);
assertThat(cd.patchSet(psId).getRevision().get()).isEqualTo(c.name());
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class AbstractSubmoduleSubscription method deleteAllSubscriptions.
protected void deleteAllSubscriptions(TestRepository<?> repo, String branch) throws Exception {
repo.git().fetch().setRemote("origin").call();
repo.reset("refs/remotes/origin/" + branch);
ObjectId expectedId = repo.branch("HEAD").commit().insertChangeId().message("delete contents in .gitmodules").add(".gitmodules", // Just remove the contents of the file!
"").create();
repo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/" + branch)).call();
ObjectId actualId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/master").getObjectId();
assertThat(actualId).isEqualTo(expectedId);
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class SubmoduleSubscriptionsIT method allowedButNotSubscribed.
@Test
public void allowedButNotSubscribed() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowMatchingSubmoduleSubscription("subscribed-to-project", "refs/heads/master", "super-project", "refs/heads/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", "subscribed-to-project")).isFalse();
}
Aggregations