Search in sources :

Example 31 with RevWalk

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

the class ChangeIT method noteDbCommitsOnPatchSetCreation.

@Test
public void noteDbCommitsOnPatchSetCreation() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    PushOneCommit.Result r = createChange();
    pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "4711", r.getChangeId()).to("refs/for/master").assertOkStatus();
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    try (Repository repo = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(repo)) {
        RevCommit commitPatchSetCreation = rw.parseCommit(repo.exactRef(changeMetaRef(new Change.Id(c._number))).getObjectId());
        assertThat(commitPatchSetCreation.getShortMessage()).isEqualTo("Create patch set 2");
        PersonIdent expectedAuthor = changeNoteUtil.newIdent(accountCache.get(admin.id).getAccount(), c.updated, serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
        assertThat(commitPatchSetCreation.getAuthorIdent()).isEqualTo(expectedAuthor);
        assertThat(commitPatchSetCreation.getCommitterIdent()).isEqualTo(new PersonIdent(serverIdent.get(), c.updated));
        assertThat(commitPatchSetCreation.getParentCount()).isEqualTo(1);
        RevCommit commitChangeCreation = rw.parseCommit(commitPatchSetCreation.getParent(0));
        assertThat(commitChangeCreation.getShortMessage()).isEqualTo("Create change");
        expectedAuthor = changeNoteUtil.newIdent(accountCache.get(admin.id).getAccount(), c.created, serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
        assertThat(commitChangeCreation.getAuthorIdent()).isEqualTo(expectedAuthor);
        assertThat(commitChangeCreation.getCommitterIdent()).isEqualTo(new PersonIdent(serverIdent.get(), c.created));
        assertThat(commitChangeCreation.getParentCount()).isEqualTo(0);
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LabelId(com.google.gerrit.reviewdb.client.LabelId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 32 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, ObjectId expectedId) throws Exception {
    submodule = name(submodule);
    ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).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(expectedId);
}
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 33 with RevWalk

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

the class SubmitOnPushIT method assertCommit.

private void assertCommit(Project.NameKey project, String branch) throws Exception {
    try (Repository r = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(r)) {
        RevCommit c = rw.parseCommit(r.exactRef(branch).getObjectId());
        assertThat(c.getShortMessage()).isEqualTo(PushOneCommit.SUBJECT);
        assertThat(c.getAuthorIdent().getEmailAddress()).isEqualTo(admin.email);
        assertThat(c.getCommitterIdent().getEmailAddress()).isEqualTo(admin.email);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 34 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 35 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)

Aggregations

RevWalk (org.eclipse.jgit.revwalk.RevWalk)487 RevCommit (org.eclipse.jgit.revwalk.RevCommit)292 Repository (org.eclipse.jgit.lib.Repository)205 ObjectId (org.eclipse.jgit.lib.ObjectId)199 IOException (java.io.IOException)160 Ref (org.eclipse.jgit.lib.Ref)124 Test (org.junit.Test)76 ObjectReader (org.eclipse.jgit.lib.ObjectReader)69 ArrayList (java.util.ArrayList)61 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)55 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)47 File (java.io.File)39 RevTree (org.eclipse.jgit.revwalk.RevTree)39 TestRepository (org.eclipse.jgit.junit.TestRepository)35 Git (org.eclipse.jgit.api.Git)32 PersonIdent (org.eclipse.jgit.lib.PersonIdent)32 RevObject (org.eclipse.jgit.revwalk.RevObject)32 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)31 HashMap (java.util.HashMap)30 Map (java.util.Map)27