Search in sources :

Example 36 with RefSpec

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;
}
Also used : Path(java.nio.file.Path) URIish(org.eclipse.jgit.transport.URIish) FetchResult(org.eclipse.jgit.transport.FetchResult) HashMap(java.util.HashMap) ObjectId(org.eclipse.jgit.lib.ObjectId) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IdString(com.google.gerrit.extensions.restapi.IdString) Project(com.google.gerrit.reviewdb.client.Project) Ref(org.eclipse.jgit.lib.Ref) RefSpec(org.eclipse.jgit.transport.RefSpec) Branch(com.google.gerrit.reviewdb.client.Branch) FileSystem(java.nio.file.FileSystem) TransportBundleStream(org.eclipse.jgit.transport.TransportBundleStream) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 37 with RefSpec

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);
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) RefSpec(org.eclipse.jgit.transport.RefSpec) ObjectId(org.eclipse.jgit.lib.ObjectId) Branch(com.google.gerrit.reviewdb.client.Branch) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 38 with RefSpec

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());
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 39 with RefSpec

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);
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) ObjectId(org.eclipse.jgit.lib.ObjectId)

Example 40 with RefSpec

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();
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) PushResult(org.eclipse.jgit.transport.PushResult) Test(org.junit.Test)

Aggregations

RefSpec (org.eclipse.jgit.transport.RefSpec)49 Test (org.junit.Test)17 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 PushCommand (org.eclipse.jgit.api.PushCommand)10 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)9 PushResult (org.eclipse.jgit.transport.PushResult)9 Git (org.eclipse.jgit.api.Git)8 File (java.io.File)7 FetchCommand (org.eclipse.jgit.api.FetchCommand)6 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)6 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)6 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)5 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)5 ArrayList (java.util.ArrayList)5 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)4 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)4