Search in sources :

Example 6 with TestRepository

use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method noCodeChange.

private void noCodeChange(String changeId) throws Exception {
    TestRepository<?>.CommitBuilder<?> commitBuilder = testRepo.amendRef("HEAD").insertChangeId(changeId.substring(1));
    commitBuilder.message("New subject " + System.nanoTime()).author(admin.getIdent()).committer(new PersonIdent(admin.getIdent(), testRepo.getDate()));
    commitBuilder.create();
    GitUtil.pushHead(testRepo, "refs/for/master", false);
    assertThat(getChangeKind(changeId)).isEqualTo(NO_CODE_CHANGE);
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 7 with TestRepository

use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.

the class AbstractSubmit method assertRebase.

protected void assertRebase(TestRepository<?> testRepo, boolean contentMerge) throws Exception {
    Repository repo = testRepo.getRepository();
    RevCommit localHead = getHead(repo);
    RevCommit remoteHead = getRemoteHead();
    assert_().withFailureMessage(String.format("%s not equal %s", localHead.name(), remoteHead.name())).that(localHead.getId()).isNotEqualTo(remoteHead.getId());
    assertThat(remoteHead.getParentCount()).isEqualTo(1);
    if (!contentMerge) {
        assertThat(getLatestRemoteDiff()).isEqualTo(getLatestDiff(repo));
    }
    assertThat(remoteHead.getShortMessage()).isEqualTo(localHead.getShortMessage());
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 8 with TestRepository

use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.

the class AbstractPushForReview method accidentallyPushNewPatchSetDirectlyToBranch.

private Change.Id accidentallyPushNewPatchSetDirectlyToBranch() throws Exception {
    PushOneCommit.Result r = createChange();
    RevCommit ps1Commit = r.getCommit();
    Change c = r.getChange().change();
    RevCommit ps2Commit;
    try (Repository repo = repoManager.openRepository(project)) {
        // Create a new patch set of the change directly in Gerrit's repository,
        // without pushing it. In reality it's more likely that the client would
        // create and push this behind Gerrit's back (e.g. an admin accidentally
        // using direct ssh access to the repo), but that's harder to do in tests.
        TestRepository<?> tr = new TestRepository<>(repo);
        ps2Commit = tr.branch("refs/heads/master").commit().message(ps1Commit.getShortMessage() + " v2").insertChangeId(r.getChangeId().substring(1)).create();
    }
    testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master")).call();
    testRepo.reset(ps2Commit);
    ChangeData cd = byCommit(ps1Commit);
    assertThat(cd.change().getStatus()).isEqualTo(Change.Status.NEW);
    assertThat(getPatchSetRevisions(cd)).containsExactlyEntriesIn(ImmutableMap.of(1, ps1Commit.name()));
    return c.getId();
}
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) Change(com.google.gerrit.reviewdb.client.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 9 with TestRepository

use of org.eclipse.jgit.junit.TestRepository 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 10 with TestRepository

use of org.eclipse.jgit.junit.TestRepository 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

TestRepository (org.eclipse.jgit.junit.TestRepository)22 Repository (org.eclipse.jgit.lib.Repository)14 Test (org.junit.Test)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)7 Change (com.google.gerrit.reviewdb.client.Change)6 ObjectId (org.eclipse.jgit.lib.ObjectId)6 PersonIdent (org.eclipse.jgit.lib.PersonIdent)6 ArrayList (java.util.ArrayList)4 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)4 Ref (org.eclipse.jgit.lib.Ref)4 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)3 Sandboxed (com.google.gerrit.acceptance.Sandboxed)2 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)2 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)2 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 CurrentUser (com.google.gerrit.server.CurrentUser)2 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)2