Search in sources :

Example 76 with RevWalk

use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.

the class SubmitOnPushIT method assertMergeCommit.

private void assertMergeCommit(String branch, String subject) throws Exception {
    try (Repository r = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(r)) {
        RevCommit c = rw.parseCommit(r.exactRef(branch).getObjectId());
        assertThat(c.getParentCount()).isEqualTo(2);
        assertThat(c.getShortMessage()).isEqualTo("Merge \"" + subject + "\"");
        assertThat(c.getAuthorIdent().getEmailAddress()).isEqualTo(admin.email);
        assertThat(c.getCommitterIdent().getEmailAddress()).isEqualTo(serverIdent.get().getEmailAddress());
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 77 with RevWalk

use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.

the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.

protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, TestRepository<?> subRepo, String subBranch) throws Exception {
    submodule = name(submodule);
    ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
    ObjectId subHead = subRepo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + subBranch).getObjectId();
    RevWalk rw = repo.getRevWalk();
    RevCommit c = rw.parseCommit(commitId);
    rw.parseBody(c.getTree());
    RevTree tree = c.getTree();
    RevObject actualId = repo.get(tree, submodule);
    assertThat(actualId).isEqualTo(subHead);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevObject(org.eclipse.jgit.revwalk.RevObject) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 78 with RevWalk

use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.

the class SubmoduleSubscriptionsIT method submoduleCommitMessage.

@Test
public void submoduleCommitMessage() 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");
    createSubmoduleSubscription(superRepo, "master", "subscribed-to-project", "master");
    ObjectId subHEAD = pushChangeTo(subRepo, "master");
    // The first update doesn't include the rev log
    RevWalk rw = subRepo.getRevWalk();
    expectToHaveCommitMessage(superRepo, "master", "Update git submodules\n\n" + "* Update " + name("subscribed-to-project") + " from branch 'master'");
    // The next commit should generate only its commit message,
    // omitting previous commit logs
    subHEAD = pushChangeTo(subRepo, "master");
    RevCommit subCommitMsg = rw.parseCommit(subHEAD);
    expectToHaveCommitMessage(superRepo, "master", "Update git submodules\n\n" + "* Update " + name("subscribed-to-project") + " from branch 'master'" + "\n  - " + subCommitMsg.getFullMessage().replace("\n", "\n    "));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 79 with RevWalk

use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.

the class SubmoduleSubscriptionsIT method testSubmoduleSubjectCommitMessage.

@Test
@GerritConfig(name = "submodule.verboseSuperprojectUpdate", value = "SUBJECT_ONLY")
public void testSubmoduleSubjectCommitMessage() 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");
    createSubmoduleSubscription(superRepo, "master", "subscribed-to-project", "master");
    ObjectId subHEAD = pushChangeTo(subRepo, "master");
    // The first update doesn't include the rev log
    RevWalk rw = subRepo.getRevWalk();
    expectToHaveCommitMessage(superRepo, "master", "Update git submodules\n\n" + "* Update " + name("subscribed-to-project") + " from branch 'master'");
    // The next commit should generate only its commit message,
    // omitting previous commit logs
    subHEAD = pushChangeTo(subRepo, "master");
    RevCommit subCommitMsg = rw.parseCommit(subHEAD);
    expectToHaveCommitMessage(superRepo, "master", "Update git submodules\n\n" + "* Update " + name("subscribed-to-project") + " from branch 'master'" + "\n  - " + subCommitMsg.getShortMessage());
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Test(org.junit.Test)

Example 80 with RevWalk

use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.

the class CreateChangeIT method createNewCommitWithoutChangeId.

private RevCommit createNewCommitWithoutChangeId() throws Exception {
    try (Repository repo = repoManager.openRepository(project);
        RevWalk walk = new RevWalk(repo)) {
        Ref ref = repo.exactRef("refs/heads/master");
        RevCommit tip = null;
        if (ref != null) {
            tip = walk.parseCommit(ref.getObjectId());
        }
        TestRepository<?> testSrcRepo = new TestRepository<>(repo);
        TestRepository<?>.BranchBuilder<?> builder = testSrcRepo.branch("refs/heads/master");
        RevCommit revCommit = tip == null ? builder.commit().message("commit 1").add("a.txt", "content").create() : builder.commit().parent(tip).message("commit 1").add("a.txt", "content").create();
        assertThat(GitUtil.getChangeId(testSrcRepo, revCommit)).isEmpty();
        return revCommit;
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) RefNames.changeMetaRef(com.google.gerrit.reviewdb.client.RefNames.changeMetaRef) Ref(org.eclipse.jgit.lib.Ref) TestRepository(org.eclipse.jgit.junit.TestRepository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RevWalk (org.eclipse.jgit.revwalk.RevWalk)217 RevCommit (org.eclipse.jgit.revwalk.RevCommit)114 Repository (org.eclipse.jgit.lib.Repository)100 ObjectId (org.eclipse.jgit.lib.ObjectId)92 IOException (java.io.IOException)67 Ref (org.eclipse.jgit.lib.Ref)35 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)33 Test (org.junit.Test)33 Change (com.google.gerrit.reviewdb.client.Change)31 ObjectReader (org.eclipse.jgit.lib.ObjectReader)30 ArrayList (java.util.ArrayList)25 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)24 OrmException (com.google.gwtorm.server.OrmException)24 RevTree (org.eclipse.jgit.revwalk.RevTree)24 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)21 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)16 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)15 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)15 PersonIdent (org.eclipse.jgit.lib.PersonIdent)15 Project (com.google.gerrit.reviewdb.client.Project)14