Search in sources :

Example 11 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 12 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 13 with TestRepository

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

the class AbstractDaemonTest method amendBuilder.

protected TestRepository<?>.CommitBuilder<?> amendBuilder() throws Exception {
    ObjectId head = repo().exactRef("HEAD").getObjectId();
    TestRepository<?>.CommitBuilder<?> b = testRepo.amendRef("HEAD");
    Optional<String> id = GitUtil.getChangeId(testRepo, head);
    // preserve an existing Change-Id. Tests probably want this.
    if (id.isPresent()) {
        b.insertChangeId(id.get().substring(1));
    } else {
        b.insertChangeId();
    }
    return b;
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) ObjectId(org.eclipse.jgit.lib.ObjectId) IdString(com.google.gerrit.extensions.restapi.IdString)

Example 14 with TestRepository

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

the class AccountIT method deleteUserBranchWithAccessDatabaseCapability.

@Test
@Sandboxed
public void deleteUserBranchWithAccessDatabaseCapability() throws Exception {
    allowGlobalCapabilities(REGISTERED_USERS, GlobalCapability.ACCESS_DATABASE);
    grant(allUsers, RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", Permission.DELETE, true, REGISTERED_USERS);
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    String userRef = RefNames.refsUsers(admin.id);
    PushResult r = deleteRef(allUsersRepo, userRef);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(userRef);
    assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.OK);
    try (Repository repo = repoManager.openRepository(allUsers)) {
        assertThat(repo.exactRef(userRef)).isNull();
    }
// TODO(ekempin): assert that account was deleted from cache and index
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

Example 15 with TestRepository

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

the class AccountIT method cannotDeleteUserBranch.

@Test
@Sandboxed
public void cannotDeleteUserBranch() throws Exception {
    grant(allUsers, RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", Permission.DELETE, true, REGISTERED_USERS);
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    String userRef = RefNames.refsUsers(admin.id);
    PushResult r = deleteRef(allUsersRepo, userRef);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(userRef);
    assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
    assertThat(refUpdate.getMessage()).contains("Not allowed to delete user branch.");
    try (Repository repo = repoManager.openRepository(allUsers)) {
        assertThat(repo.exactRef(userRef)).isNotNull();
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

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