Search in sources :

Example 26 with ObjectId

use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertExtIdBehindGerritsBack.

private void insertExtIdBehindGerritsBack(ExternalId extId) throws Exception {
    try (Repository repo = repoManager.openRepository(allUsers);
        RevWalk rw = new RevWalk(repo);
        ObjectInserter ins = repo.newObjectInserter()) {
        ObjectId rev = ExternalIdReader.readRevision(repo);
        NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
        ExternalIdsUpdate.insert(rw, ins, noteMap, extId);
        ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, "insert new ID", serverIdent.get(), serverIdent.get());
    }
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectId(org.eclipse.jgit.lib.ObjectId) NoteMap(org.eclipse.jgit.notes.NoteMap) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 27 with ObjectId

use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.

the class AbstractPushForReview method testPushAFewChanges.

private void testPushAFewChanges() throws Exception {
    int n = 10;
    String r = "refs/for/master";
    ObjectId initialHead = testRepo.getRepository().resolve("HEAD");
    List<RevCommit> commits = createChanges(n, r);
    // Check that a change was created for each.
    for (RevCommit c : commits) {
        assertThat(byCommit(c).change().getSubject()).named("change for " + c.name()).isEqualTo(c.getShortMessage());
    }
    List<RevCommit> commits2 = amendChanges(initialHead, commits, r);
    // Check that there are correct patch sets.
    for (int i = 0; i < n; i++) {
        RevCommit c = commits.get(i);
        RevCommit c2 = commits2.get(i);
        String name = "change for " + c2.name();
        ChangeData cd = byCommit(c);
        assertThat(cd.change().getSubject()).named(name).isEqualTo(c2.getShortMessage());
        assertThat(getPatchSetRevisions(cd)).named(name).containsExactlyEntriesIn(ImmutableMap.of(1, c.name(), 2, c2.name()));
    }
    // Pushing again results in "no new changes".
    assertPushRejected(pushHead(testRepo, r, false), r, "no new changes");
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 28 with ObjectId

use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.

the class AbstractPushForReview method mergedOptionWithExistingChangeInsertsPatchSet.

@Test
public void mergedOptionWithExistingChangeInsertsPatchSet() throws Exception {
    String master = "refs/heads/master";
    grant(project, master, Permission.PUSH, true);
    PushOneCommit.Result r = pushTo("refs/for/master");
    r.assertOkStatus();
    ObjectId c1 = r.getCommit().copy();
    // Create a PS2 commit directly on master in the server's repo. This
    // simulates the client amending locally and pushing directly to the branch,
    // expecting the change to be auto-closed, but the change metadata update
    // fails.
    ObjectId c2;
    try (Repository repo = repoManager.openRepository(project)) {
        TestRepository<?> tr = new TestRepository<>(repo);
        RevCommit commit2 = tr.amend(c1).message("New subject").insertChangeId(r.getChangeId().substring(1)).create();
        c2 = commit2.copy();
        tr.update(master, c2);
    }
    testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master")).call();
    testRepo.reset(c2);
    String ref = "refs/for/master%merged";
    assertPushOk(pushHead(testRepo, ref, false), ref);
    EnumSet<ListChangesOption> opts = EnumSet.of(ListChangesOption.ALL_REVISIONS);
    ChangeInfo info = gApi.changes().id(r.getChangeId()).get(opts);
    assertThat(info.currentRevision).isEqualTo(c2.name());
    assertThat(info.revisions.keySet()).containsExactly(c1.name(), c2.name());
    // TODO(dborowitz): Fix ReceiveCommits to also auto-close the change.
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) TestRepository(org.eclipse.jgit.junit.TestRepository) RefSpec(org.eclipse.jgit.transport.RefSpec) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 29 with ObjectId

use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushWithReviewerInFooter.

private void pushWithReviewerInFooter(String nameEmail, TestAccount expectedReviewer) throws Exception {
    int n = 5;
    String r = "refs/for/master";
    ObjectId initialHead = testRepo.getRepository().resolve("HEAD");
    List<RevCommit> commits = createChanges(n, r, ImmutableList.of("Acked-By: " + nameEmail));
    for (int i = 0; i < n; i++) {
        RevCommit c = commits.get(i);
        ChangeData cd = byCommit(c);
        String name = "reviewers for " + (i + 1);
        if (expectedReviewer != null) {
            assertThat(cd.reviewers().all()).named(name).containsExactly(expectedReviewer.getId());
            gApi.changes().id(cd.getId().get()).reviewer(expectedReviewer.getId().toString()).remove();
        }
        assertThat(byCommit(c).reviewers().all()).named(name).isEmpty();
    }
    List<RevCommit> commits2 = amendChanges(initialHead, commits, r);
    for (int i = 0; i < n; i++) {
        RevCommit c = commits2.get(i);
        ChangeData cd = byCommit(c);
        String name = "reviewers for " + (i + 1);
        if (expectedReviewer != null) {
            assertThat(cd.reviewers().all()).named(name).containsExactly(expectedReviewer.getId());
        } else {
            assertThat(byCommit(c).reviewers().all()).named(name).isEmpty();
        }
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 30 with ObjectId

use of org.eclipse.jgit.lib.ObjectId in project gerrit by GerritCodeReview.

the class SubmoduleSubscriptionsWholeTopicMergeIT method recursiveSubmodules.

@Test
public void recursiveSubmodules() throws Exception {
    TestRepository<?> topRepo = createProjectWithPush("top-project");
    TestRepository<?> midRepo = createProjectWithPush("mid-project");
    TestRepository<?> bottomRepo = createProjectWithPush("bottom-project");
    allowMatchingSubmoduleSubscription("mid-project", "refs/heads/master", "top-project", "refs/heads/master");
    allowMatchingSubmoduleSubscription("bottom-project", "refs/heads/master", "mid-project", "refs/heads/master");
    createSubmoduleSubscription(topRepo, "master", "mid-project", "master");
    createSubmoduleSubscription(midRepo, "master", "bottom-project", "master");
    ObjectId bottomHead = pushChangeTo(bottomRepo, "refs/for/master", "some message", "same-topic");
    ObjectId topHead = pushChangeTo(topRepo, "refs/for/master", "some message", "same-topic");
    String id1 = getChangeId(bottomRepo, bottomHead).get();
    String id2 = getChangeId(topRepo, topHead).get();
    gApi.changes().id(id1).current().review(ReviewInput.approve());
    gApi.changes().id(id2).current().review(ReviewInput.approve());
    gApi.changes().id(id1).current().submit();
    expectToHaveSubmoduleState(midRepo, "master", "bottom-project", bottomRepo, "master");
    expectToHaveSubmoduleState(topRepo, "master", "mid-project", midRepo, "master");
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) Test(org.junit.Test)

Aggregations

ObjectId (org.eclipse.jgit.lib.ObjectId)355 Test (org.junit.Test)128 RevCommit (org.eclipse.jgit.revwalk.RevCommit)123 RevWalk (org.eclipse.jgit.revwalk.RevWalk)84 Repository (org.eclipse.jgit.lib.Repository)63 IOException (java.io.IOException)61 Change (com.google.gerrit.reviewdb.client.Change)41 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)39 ArrayList (java.util.ArrayList)36 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)34 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)34 Ref (org.eclipse.jgit.lib.Ref)34 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)33 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)25 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)24 RefUpdate (org.eclipse.jgit.lib.RefUpdate)22 NoteMap (org.eclipse.jgit.notes.NoteMap)22 Map (java.util.Map)21 OrmException (com.google.gwtorm.server.OrmException)20 ObjectReader (org.eclipse.jgit.lib.ObjectReader)19